diff --git a/tests/web3js/debug_traces_test.js b/tests/web3js/debug_traces_test.js index afc90586..fbe26a75 100644 --- a/tests/web3js/debug_traces_test.js +++ b/tests/web3js/debug_traces_test.js @@ -859,4 +859,50 @@ it('should retrieve call traces', async () => { ) assert.equal(updateTrace.value, '0x0') assert.equal(updateTrace.type, 'CALL') + + // assert return value of empty revert data for default struct logger tracer + let callStoreButRevert = deployed.contract.methods.storeButRevert(150n).encodeABI() + traceCall = { + from: conf.eoa.address, + to: contractAddress, + data: callStoreButRevert, + value: '0x0', + gasPrice: web3.utils.toHex(conf.minGasPrice), + gas: '0x95ab' + } + response = await helpers.callRPCMethod( + 'debug_traceCall', + [traceCall, 'latest', { tracer: null }] + ) + assert.equal(response.status, 200) + assert.isDefined(response.body) + + let traceResult = response.body.result + assert.equal(traceResult.gas, 26677) + assert.equal(traceResult.failed, true) + assert.equal(traceResult.returnValue, '0x') + assert.lengthOf(traceResult.structLogs, 138) + + // assert return value of non-empty revert data for default struct logger tracer + let callCustomError = deployed.contract.methods.customError().encodeABI() + traceCall = { + from: conf.eoa.address, + to: contractAddress, + data: callCustomError, + value: '0x0', + gasPrice: web3.utils.toHex(conf.minGasPrice), + gas: '0x95ab' + } + response = await helpers.callRPCMethod( + 'debug_traceCall', + [traceCall, 'latest', { tracer: null }] + ) + assert.equal(response.status, 200) + assert.isDefined(response.body) + + traceResult = response.body.result + assert.equal(traceResult.gas, 21786) + assert.equal(traceResult.failed, true) + assert.equal(traceResult.returnValue, '0x9195785a00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001056616c756520697320746f6f206c6f7700000000000000000000000000000000') + assert.lengthOf(traceResult.structLogs, 210) }) diff --git a/tests/web3js/eth_deploy_contract_and_interact_test.js b/tests/web3js/eth_deploy_contract_and_interact_test.js index 3a96c07a..fd94875c 100644 --- a/tests/web3js/eth_deploy_contract_and_interact_test.js +++ b/tests/web3js/eth_deploy_contract_and_interact_test.js @@ -211,6 +211,41 @@ it('deploy contract and interact', async () => { ) } + // check that gas estimation reports proper error code and data for empty reverts + try { + let callStoreButRevert = deployed.contract.methods.storeButRevert(150n).encodeABI() + result = await web3.eth.estimateGas({ + from: conf.eoa.address, + to: contractAddress, + data: callStoreButRevert, + gas: 1_000_000, + gasPrice: conf.minGasPrice + }) + assert.fail('expected eth_estimateGas to revert with empty revert data') + } catch (error) { + assert.equal(error.innerError.code, 3) + assert.equal(error.innerError.data, '0x') + assert.equal(error.innerError.message, 'execution reverted') + } + + // check that contract call reports proper error code and data for empty reverts + try { + let callStoreButRevert = deployed.contract.methods.storeButRevert(150n).encodeABI() + result = await web3.eth.call({ + from: conf.eoa.address, + to: contractAddress, + data: callStoreButRevert, + gas: 1_000_000, + gasPrice: conf.minGasPrice + }) + assert.fail('expected eth_call to revert with empty revert data') + } catch (error) { + assert.equal(error.innerError.code, 3) + assert.equal(error.innerError.data, '0x') + assert.equal(error.innerError.message, 'execution reverted') + } + + // check that block height is properly handled by gas estimation endpoint let gasEstimate = await web3.eth.estimateGas( { from: conf.eoa.address, @@ -219,7 +254,7 @@ it('deploy contract and interact', async () => { gas: 1_000_000, gasPrice: 0 }, - '0x1' + '0x1' // give a block height at which the contract did not exist ) assert.equal(gasEstimate, 22026n) @@ -231,7 +266,7 @@ it('deploy contract and interact', async () => { gas: 1_000_000, gasPrice: 0 }, - 'latest' + 'latest' // give a block height at which the contract did exist ) assert.equal(gasEstimate, 25050n)