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. 2
      apps/remix-ide/src/app/tabs/debugger-tab.js
  2. 6
      apps/remix-ide/src/blockchain/blockchain.tsx
  3. 5
      apps/remix-ide/src/blockchain/providers/vm.ts
  4. 12
      libs/remix-simulator/src/VmProxy.ts
  5. 6
      libs/remix-simulator/src/methods/accounts.ts
  6. 5
      libs/remix-simulator/src/methods/transactions.ts
  7. 5
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx
  8. 7
      libs/remix-ui/run-tab/src/lib/components/mainnet.tsx
  9. 1
      package.json

@ -86,7 +86,7 @@ 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 = {
'sender': tx.from,

@ -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'
@ -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) {

@ -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'
@ -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) {

@ -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'
@ -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