remove web3-utils-legacy. fix lib tests

pull/3951/head
Oleksii Kosynskyi 2 years ago
parent fc2878827e
commit 29aab75915
No known key found for this signature in database
GPG Key ID: B4A8D3CCE22EA65E
  1. 6
      apps/remix-ide/src/app/tabs/debugger-tab.js
  2. 28
      apps/remix-ide/src/blockchain/blockchain.tsx
  3. 9
      apps/remix-ide/src/blockchain/providers/vm.ts
  4. 2
      libs/remix-simulator/package.json
  5. 12
      libs/remix-simulator/src/VmProxy.ts
  6. 6
      libs/remix-simulator/src/methods/accounts.ts
  7. 7
      libs/remix-simulator/src/methods/transactions.ts
  8. 5
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx
  9. 7
      libs/remix-ui/run-tab/src/lib/components/mainnet.tsx
  10. 1
      package.json

@ -86,9 +86,9 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
'timestamp': block.timestamp,
}
if (block.baseFeePerGas) {
blockContext['basefee'] = Web3.utils.toBN(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
blockContext['basefee'] = Web3.utils.toBigInt(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
}
const msg = {
const msg = {
'sender': tx.from,
'sig': tx.input.substring(0, 10),
'value': tx.value + ' Wei'
@ -97,7 +97,7 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
const txOrigin = {
'origin': tx.from
}
return {
block: blockContext,
msg,

@ -1,7 +1,5 @@
import React from 'react' // eslint-disable-line
import Web3 from 'web3'
import { fromWei, toBN, toWei } from 'web3-utils-legacy'
import { fromWei, toBigInt, toWei } from 'web3-utils'
import { Plugin } from '@remixproject/engine'
import { toBuffer, addHexPrefix } from '@ethereumjs/util'
import { EventEmitter } from 'events'
@ -57,7 +55,7 @@ export class Blockchain extends Plugin {
networkStatus: {
network: {
name: string,
id: string
id: string
}
error?: string
}
@ -223,7 +221,7 @@ export class Blockchain extends Plugin {
const proxyModal = {
id: 'confirmProxyDeployment',
title: 'Confirm Deploy Proxy (ERC1967)',
message: `Confirm you want to deploy an ERC1967 proxy contract that is connected to your implementation.
message: `Confirm you want to deploy an ERC1967 proxy contract that is connected to your implementation.
For more info on ERC1967, see: https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Proxy`,
modalType: 'modal',
okLabel: 'OK',
@ -254,7 +252,7 @@ export class Blockchain extends Plugin {
const finalCb = async (error, txResult, address, returnValue) => {
if (error) {
const log = logBuilder(error)
_paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment failed: ' + error])
return this.call('terminal', 'logHtml', log)
}
@ -433,7 +431,7 @@ export class Blockchain extends Plugin {
}
calculateFee (gas, gasPrice, unit?) {
return toBN(gas).mul(toBN(toWei(gasPrice.toString(10) as string, unit || 'gwei')))
return toBigInt(gas) * toBigInt(toWei(gasPrice.toString(10) as string, unit || 'gwei'))
}
determineGasFees (tx) {
@ -593,7 +591,7 @@ export class Blockchain extends Plugin {
return this.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false
}
}, _ => this.executionContext.web3(), _ => this.executionContext.currentblockGasLimit())
web3Runner.event.register('transactionBroadcasted', (txhash) => {
this.executionContext.detectNetwork((error, network) => {
if (error || !network) return
@ -604,7 +602,7 @@ export class Blockchain extends Plugin {
this.call('terminal', 'logHtml',
(<a href={etherScanLink(network.name, txhash)} target="_blank">
view on etherscan
</a>))
</a>))
}
})
})
@ -669,7 +667,7 @@ export class Blockchain extends Plugin {
const execResult = await this.web3().testPlugin.getExecutionResultFromSimulator(result.transactionHash)
resolve(resultToRemixTx(result, execResult))
} else
resolve(resultToRemixTx(result))
resolve(resultToRemixTx(result))
} catch (e) {
reject(e)
}
@ -763,7 +761,7 @@ export class Blockchain extends Plugin {
}
return reject(error)
}
const isVM = this.executionContext.isVM()
if (isVM && tx.useCall) {
try {
@ -823,7 +821,7 @@ export class Blockchain extends Plugin {
}
return <div>{formattedLog}</div>
})}
</div>
</div>
_paq.push(['trackEvent', 'udapp', 'hardhat', 'console.log'])
this.call('terminal', 'logHtml', finalLogs)
}
@ -838,16 +836,16 @@ export class Blockchain extends Plugin {
}
}
}
if (!isVM && tx && tx.useCall) {
returnValue = toBuffer(addHexPrefix(txResult.result))
}
let address = null
if (txResult && txResult.receipt) {
address = txResult.receipt.contractAddress
}
cb(null, txResult, address, returnValue)
} catch (error) {
cb(error)

@ -1,7 +1,6 @@
import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3'
import { fromWei } from 'web3-utils-legacy'
import { fromWei } from 'web3-utils'
import { privateToAddress, hashPersonalMessage } from '@ethereumjs/util'
import BN from 'bn.js'
import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator'
import { ExecutionContext } from '../execution-context'
@ -34,8 +33,8 @@ export class VMProvider {
let incr = 0
const stamps = {}
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
this.worker.addEventListener('message', (msg) => {
if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) {
stamps[msg.data.stamp](msg.data.error, msg.data.result)
@ -84,7 +83,7 @@ export class VMProvider {
async getBalanceInEther (address) {
const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX })
return fromWei(new BN(balance).toString(10), 'ether')
return fromWei(BigInt(balance).toString(10), 'ether')
}
getGasPrice (cb) {

@ -69,4 +69,4 @@
"typings": "src/index.d.ts",
"gitHead": "8edf05261b079599b71f0fe2f890b005e2d8a6c3",
"types": "./src/index.d.ts"
}
}

@ -3,10 +3,8 @@ const { toHexPaddedString, formatMemory } = util
import { helpers } from '@remix-project/remix-lib'
const { normalizeHexAddress } = helpers.ui
import { ConsoleLogs, hash } from '@remix-project/remix-lib'
import BN from 'bn.js'
import { toChecksumAddress, bufferToHex, Address, toBuffer } from '@ethereumjs/util'
import utils from 'web3-utils'
import { toBN } from 'web3-utils-legacy'
import utils, {toBigInt} from 'web3-utils'
import { ethers } from 'ethers'
import { VMContext } from './vm-context'
import type { StateManager } from '@ethereumjs/statemanager'
@ -84,7 +82,7 @@ export class VmProxy {
this.fromDecimal = (...args) => utils.fromDecimal.apply(this, args)
this.fromWei = (...args) => utils.fromWei.apply(this, args)
this.toWei = (...args) => utils.toWei.apply(this, args)
this.toBigNumber = (...args) => toBN.apply(this, args)
this.toBigNumber = (...args) => utils.toBigInt.apply(this, args)
this.isAddress = (...args) => utils.isAddress.apply(this, args)
this.utils = utils
this.txsMapBlock = {}
@ -427,10 +425,10 @@ export class VmProxy {
getSha3Input (stack, memory) {
const memoryStart = toHexPaddedString(stack[stack.length - 1])
const memoryLength = toHexPaddedString(stack[stack.length - 2])
const memStartDec = (new BN(memoryStart.replace('0x', ''), 16)).toString(10)
const memStartDec = toBigInt(memoryStart).toString(10)
const memoryStartInt = parseInt(memStartDec) * 2
const memLengthDec = (new BN(memoryLength.replace('0x', ''), 16).toString(10))
const memoryLengthInt = parseInt(memLengthDec) * 2
const memLengthDec = toBigInt(memoryLength).toString(10)
const memoryLengthInt = parseInt(memLengthDec.toString()) * 2
let i = Math.floor(memoryStartInt / 32)
const maxIndex = Math.floor(memoryLengthInt / 32) + i

@ -1,6 +1,6 @@
import { privateToAddress, toChecksumAddress, isValidPrivate, Address } from '@ethereumjs/util'
import BN from 'bn.js'
import { privateKeyToAccount } from 'web3-eth-accounts'
import { toBigInt } from 'web3-utils'
import * as crypto from 'crypto'
export class Web3Accounts {
@ -46,7 +46,7 @@ export class Web3Accounts {
const stateManager = this.vmContext.vm().stateManager
stateManager.getAccount(Address.fromString(addressStr)).then((account) => {
account.balance = new BN(balance.replace('0x', '') || 'f00000000000000001', 16)
account.balance = toBigInt(balance || '0xf00000000000000001')
stateManager.putAccount(Address.fromString(addressStr), account).catch((error) => {
reject(error)
}).then(() => {
@ -83,7 +83,7 @@ export class Web3Accounts {
const address = payload.params[0]
this.vmContext.vm().stateManager.getAccount(Address.fromString(address)).then((account) => {
cb(null, new BN(account.balance).toString(10))
cb(null, toBigInt(account.balance).toString(10))
}).catch((error) => {
cb(error)
})

@ -1,5 +1,4 @@
import { toHex, toNumber } from 'web3-utils'
import BN from 'bn.js'
import { toHex, toNumber, toBigInt } from 'web3-utils'
import { toChecksumAddress, Address, bigIntToHex } from '@ethereumjs/util'
import { processTx } from './txProcess'
import { execution } from '@remix-project/remix-lib'
@ -156,7 +155,7 @@ export class Transactions {
payload.params[0].gas = 10000000 * 10
this.vmContext.web3().flagNextAsDoNotRecordEvmSteps()
processTx(this.txRunnerInstance, payload, true, (error, value: VMexecutionResult) => {
processTx(this.txRunnerInstance, payload, true, (error, value: VMexecutionResult) => {
if (error) return cb(error)
const result: RunTxResult = value.result
if ((result as any).receipt?.status === '0x0' || (result as any).receipt?.status === 0) {
@ -234,7 +233,7 @@ export class Transactions {
const address = payload.params[0]
this.vmContext.vm().stateManager.getAccount(Address.fromString(address)).then((account) => {
const nonce = new BN(account.nonce).toString(10)
const nonce = toBigInt(account.nonce).toString(10)
cb(null, nonce)
}).catch((error) => {
cb(error)

@ -1,7 +1,6 @@
import React from 'react' // eslint-disable-line
import DropdownPanel from './dropdown-panel' // eslint-disable-line
import { BN } from 'bn.js'
import { toBN } from 'web3-utils-legacy'
import {toBigInt} from 'web3-utils' // eslint-disable-line
export const GlobalVariables = ({ block, receipt, tx, className }) => {
// see https://docs.soliditylang.org/en/latest/units-and-global-variables.html#block-and-transaction-properties
@ -18,7 +17,7 @@ export const GlobalVariables = ({ block, receipt, tx, className }) => {
'tx.origin': tx && tx.from
}
if (block && block.baseFeePerGas) {
globals['block.basefee'] = toBN(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
globals['block.basefee'] = toBigInt(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
}
return (

@ -1,8 +1,7 @@
// eslint-disable-next-line no-use-before-define
import React, { useEffect, useState } from 'react'
import { CopyToClipboard } from '@remix-ui/clipboard'
import Web3 from 'web3'
import { fromWei, toBN, toWei } from 'web3-utils-legacy'
import { fromWei, toBigInt, toWei } from 'web3-utils'
import { MainnetProps } from '../types'
export function MainnetPrompt (props: MainnetProps) {
@ -14,7 +13,7 @@ export function MainnetPrompt (props: MainnetProps) {
if (txFeeText) setTransactionFee(txFeeText)
if (gasPriceValue) onGasPriceChange(gasPriceValue)
if (props.network && props.network.lastBlock && props.network.lastBlock.baseFeePerGas) {
const baseFee = fromWei(toBN(props.network.lastBlock.baseFeePerGas), 'Gwei')
const baseFee = fromWei(toBigInt(props.network.lastBlock.baseFeePerGas), 'Gwei')
setBaseFee(baseFee)
onMaxFeeChange(baseFee)
@ -107,7 +106,7 @@ export function MainnetPrompt (props: MainnetProps) {
</div>
<div className="align-items-center my-1" title="Represents the maximum amount of fee that you will pay for this transaction. The minimun needs to be set to base fee.">
<div className='d-flex'>
<span className="text-dark mr-2 text-nowrap">Max fee (Not less than base fee {fromWei(toBN(props.network.lastBlock.baseFeePerGas), 'Gwei')} Gwei):</span>
<span className="text-dark mr-2 text-nowrap">Max fee (Not less than base fee {fromWei(toBigInt(props.network.lastBlock.baseFeePerGas), 'Gwei')} Gwei):</span>
<input className="form-control mr-1 text-right" style={{ height: '1.2rem', width: '6rem' }} id='maxfee' onInput={(e: any) => onMaxFeeChange(e.target.value)} defaultValue={baseFee} />
<span>Gwei</span>
<span className="text-dark ml-2"></span>

@ -208,7 +208,6 @@
"viem": "^1.2.12",
"wagmi": "^1.3.8",
"web3": "^4.0.3",
"web3-utils-legacy": "npm:web3-utils@1.10.0",
"winston": "^3.3.3",
"ws": "^7.3.0"
},

Loading…
Cancel
Save