From debcd570e691241908927a62775fef077290627e Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Mon, 24 Jul 2023 14:51:41 -1000 Subject: [PATCH] Fix yarn run build:libs --- libs/remix-lib/src/execution/txRunnerWeb3.ts | 76 +++++++++---------- libs/remix-simulator/src/VmProxy.ts | 7 +- .../src/methods/transactions.ts | 6 +- libs/remix-tests/src/runTestFiles.ts | 10 ++- 4 files changed, 51 insertions(+), 48 deletions(-) diff --git a/libs/remix-lib/src/execution/txRunnerWeb3.ts b/libs/remix-lib/src/execution/txRunnerWeb3.ts index d5fce39b92..4a4e4eba63 100644 --- a/libs/remix-lib/src/execution/txRunnerWeb3.ts +++ b/libs/remix-lib/src/execution/txRunnerWeb3.ts @@ -95,12 +95,11 @@ export class TxRunnerWeb3 { if (useCall) { tx['gas'] = gasLimit if (this._api && this._api.isVM()) tx['timestamp'] = timestamp - return this.getWeb3().eth.call(tx, function (error, result: any) { - if (error) return callback(error) - callback(null, { + this.getWeb3().eth.call(tx) + .then((result: any) => callback(null, { result: result - }) - }) + })) + .catch(error => callback(error)) } this._api.detectNetwork((errNetWork, network) => { if (errNetWork) { @@ -118,43 +117,44 @@ export class TxRunnerWeb3 { txCopy.type = '0x1' txCopy.gasPrice = network.lastBlock.baseFeePerGas } - } - this.getWeb3().eth.estimateGas(txCopy, (err, gasEstimation) => { - if (err && err.message.indexOf('Invalid JSON RPC response') !== -1) { - // // @todo(#378) this should be removed when https://github.com/WalletConnect/walletconnect-monorepo/issues/334 is fixed - callback(new Error('Gas estimation failed because of an unknown internal error. This may indicated that the transaction will fail.')) - } - err = network.name === 'VM' ? null : err // just send the tx if "VM" - gasEstimationForceSend(err, () => { - // callback is called whenever no error - tx['gas'] = !gasEstimation ? gasLimit : gasEstimation + } + this.getWeb3().eth.estimateGas(txCopy) + .then(gasEstimation => { + gasEstimationForceSend(null, () => { + // callback is called whenever no error + tx['gas'] = !gasEstimation ? gasLimit : gasEstimation + + if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { + return this._executeTx(tx, network, null, this._api, promptCb, callback) + } - if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { - return this._executeTx(tx, network, null, this._api, promptCb, callback) - } - - confirmCb(network, tx, tx['gas'], (txFee) => { - return this._executeTx(tx, network, txFee, this._api, promptCb, callback) - }, (error) => { - callback(error) + confirmCb(network, tx, tx['gas'], (txFee) => { + return this._executeTx(tx, network, txFee, this._api, promptCb, callback) + }, (error) => { + callback(error) + }) }) - }, () => { - const blockGasLimit = this.currentblockGasLimit() - // NOTE: estimateGas very likely will return a large limit if execution of the code failed - // we want to be able to run the code in order to debug and find the cause for the failure - if (err) return callback(err) - - let warnEstimation = ' An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that\'s also the reason of strong gas estimation). ' - warnEstimation += ' ' + err - - if (gasEstimation > gasLimit) { - return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation) - } - if (gasEstimation > blockGasLimit) { - return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation) + }) + .catch(err => { + if (err && err.message.indexOf('Invalid JSON RPC response') !== -1) { + // // @todo(#378) this should be removed when https://github.com/WalletConnect/walletconnect-monorepo/issues/334 is fixed + callback(new Error('Gas estimation failed because of an unknown internal error. This may indicated that the transaction will fail.')) } + err = network.name === 'VM' ? null : err // just send the tx if "VM" + gasEstimationForceSend(err, () => { + tx['gas'] = gasLimit + + if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { + return this._executeTx(tx, network, null, this._api, promptCb, callback) + } + + confirmCb(network, tx, tx['gas'], (txFee) => { + return this._executeTx(tx, network, txFee, this._api, promptCb, callback) + }, (error) => { + callback(error) + }) + }) }) - }) }) } } diff --git a/libs/remix-simulator/src/VmProxy.ts b/libs/remix-simulator/src/VmProxy.ts index a0005f8fa2..65e7d24831 100644 --- a/libs/remix-simulator/src/VmProxy.ts +++ b/libs/remix-simulator/src/VmProxy.ts @@ -4,7 +4,6 @@ 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 { isBigNumber } from 'web3-utils' import { toChecksumAddress, bufferToHex, Address, toBuffer } from '@ethereumjs/util' import utils from 'web3-utils' import { ethers } from 'ethers' @@ -84,7 +83,8 @@ 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) => utils.toBN.apply(this, args) + // TODO Is this still needed? + // this.toBigNumber = (...args) => utils.toBN.apply(this, args) this.isAddress = (...args) => utils.isAddress.apply(this, args) this.utils = utils this.txsMapBlock = {} @@ -278,7 +278,8 @@ export class VmProxy { } let consoleArgs = iface.decodeFunctionData(functionDesc, payload) consoleArgs = consoleArgs.map((value) => { - if (isBigNumber(value)) { + // Copied from: https://github.com/web3/web3.js/blob/e68194bdc590d811d4bf66dde12f99659861a110/packages/web3-utils/src/utils.js#L48C10-L48C10 + if (value && value.constructor && value.constructor.name === 'BigNumber') { return value.toString() } return value diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index dc6d940e65..39a4f9ae8e 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -1,4 +1,4 @@ -import { toHex, toDecimal } from 'web3-utils' +import { toHex, toNumber } from 'web3-utils' import BN from 'bn.js' import { toChecksumAddress, Address, bigIntToHex } from '@ethereumjs/util' import { processTx } from './txProcess' @@ -292,7 +292,7 @@ export class Transactions { const txIndex = payload.params[1] const txBlock = this.vmContext.blocks[payload.params[0]] - const txHash = '0x' + txBlock.transactions[toDecimal(txIndex)].hash().toString('hex') + const txHash = '0x' + txBlock.transactions[toNumber(txIndex) as number].hash().toString('hex') this.vmContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { if (error) { @@ -337,7 +337,7 @@ export class Transactions { const txIndex = payload.params[1] const txBlock = this.vmContext.blocks[payload.params[0]] - const txHash = '0x' + txBlock.transactions[toDecimal(txIndex)].hash().toString('hex') + const txHash = '0x' + txBlock.transactions[toNumber(txIndex) as number].hash().toString('hex') this.vmContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { if (error) { diff --git a/libs/remix-tests/src/runTestFiles.ts b/libs/remix-tests/src/runTestFiles.ts index a811f9b441..acf84cb45c 100644 --- a/libs/remix-tests/src/runTestFiles.ts +++ b/libs/remix-tests/src/runTestFiles.ts @@ -62,10 +62,12 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3 async.waterfall([ function getAccountList (next) { if (accounts) return next(null) - web3.eth.getAccounts((_err: Error | null | undefined, _accounts) => { - accounts = _accounts - next(null) - }) + web3.eth.getAccounts() + .then(_accounts => { + accounts = _accounts + next(null) + }) + .catch((_err: Error | null | undefined) => next(null)) }, function compile (next) { compileFileOrFiles(filepath, isDirectory, { accounts }, compilerConfig, next)