Skip to content

Commit 307256e

Browse files
authored
Merge pull request #880 from onflow/mpeter/check-error-code-with-empty-revert-data
Check the returned error code on empty revert data
2 parents 039545d + 5e926de commit 307256e

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

tests/web3js/debug_traces_test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,4 +859,50 @@ it('should retrieve call traces', async () => {
859859
)
860860
assert.equal(updateTrace.value, '0x0')
861861
assert.equal(updateTrace.type, 'CALL')
862+
863+
// assert return value of empty revert data for default struct logger tracer
864+
let callStoreButRevert = deployed.contract.methods.storeButRevert(150n).encodeABI()
865+
traceCall = {
866+
from: conf.eoa.address,
867+
to: contractAddress,
868+
data: callStoreButRevert,
869+
value: '0x0',
870+
gasPrice: web3.utils.toHex(conf.minGasPrice),
871+
gas: '0x95ab'
872+
}
873+
response = await helpers.callRPCMethod(
874+
'debug_traceCall',
875+
[traceCall, 'latest', { tracer: null }]
876+
)
877+
assert.equal(response.status, 200)
878+
assert.isDefined(response.body)
879+
880+
let traceResult = response.body.result
881+
assert.equal(traceResult.gas, 26677)
882+
assert.equal(traceResult.failed, true)
883+
assert.equal(traceResult.returnValue, '0x')
884+
assert.lengthOf(traceResult.structLogs, 138)
885+
886+
// assert return value of non-empty revert data for default struct logger tracer
887+
let callCustomError = deployed.contract.methods.customError().encodeABI()
888+
traceCall = {
889+
from: conf.eoa.address,
890+
to: contractAddress,
891+
data: callCustomError,
892+
value: '0x0',
893+
gasPrice: web3.utils.toHex(conf.minGasPrice),
894+
gas: '0x95ab'
895+
}
896+
response = await helpers.callRPCMethod(
897+
'debug_traceCall',
898+
[traceCall, 'latest', { tracer: null }]
899+
)
900+
assert.equal(response.status, 200)
901+
assert.isDefined(response.body)
902+
903+
traceResult = response.body.result
904+
assert.equal(traceResult.gas, 21786)
905+
assert.equal(traceResult.failed, true)
906+
assert.equal(traceResult.returnValue, '0x9195785a00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001056616c756520697320746f6f206c6f7700000000000000000000000000000000')
907+
assert.lengthOf(traceResult.structLogs, 210)
862908
})

tests/web3js/eth_deploy_contract_and_interact_test.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,41 @@ it('deploy contract and interact', async () => {
211211
)
212212
}
213213

214+
// check that gas estimation reports proper error code and data for empty reverts
215+
try {
216+
let callStoreButRevert = deployed.contract.methods.storeButRevert(150n).encodeABI()
217+
result = await web3.eth.estimateGas({
218+
from: conf.eoa.address,
219+
to: contractAddress,
220+
data: callStoreButRevert,
221+
gas: 1_000_000,
222+
gasPrice: conf.minGasPrice
223+
})
224+
assert.fail('expected eth_estimateGas to revert with empty revert data')
225+
} catch (error) {
226+
assert.equal(error.innerError.code, 3)
227+
assert.equal(error.innerError.data, '0x')
228+
assert.equal(error.innerError.message, 'execution reverted')
229+
}
230+
231+
// check that contract call reports proper error code and data for empty reverts
232+
try {
233+
let callStoreButRevert = deployed.contract.methods.storeButRevert(150n).encodeABI()
234+
result = await web3.eth.call({
235+
from: conf.eoa.address,
236+
to: contractAddress,
237+
data: callStoreButRevert,
238+
gas: 1_000_000,
239+
gasPrice: conf.minGasPrice
240+
})
241+
assert.fail('expected eth_call to revert with empty revert data')
242+
} catch (error) {
243+
assert.equal(error.innerError.code, 3)
244+
assert.equal(error.innerError.data, '0x')
245+
assert.equal(error.innerError.message, 'execution reverted')
246+
}
247+
248+
// check that block height is properly handled by gas estimation endpoint
214249
let gasEstimate = await web3.eth.estimateGas(
215250
{
216251
from: conf.eoa.address,
@@ -219,7 +254,7 @@ it('deploy contract and interact', async () => {
219254
gas: 1_000_000,
220255
gasPrice: 0
221256
},
222-
'0x1'
257+
'0x1' // give a block height at which the contract did not exist
223258
)
224259
assert.equal(gasEstimate, 22026n)
225260

@@ -231,7 +266,7 @@ it('deploy contract and interact', async () => {
231266
gas: 1_000_000,
232267
gasPrice: 0
233268
},
234-
'latest'
269+
'latest' // give a block height at which the contract did exist
235270
)
236271
assert.equal(gasEstimate, 25050n)
237272

0 commit comments

Comments
 (0)