Skip to content

Commit b30930d

Browse files
committed
Handle execution revert errors on eth_estimateGas endpoint
1 parent 4fd9489 commit b30930d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

services/requester/requester.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ func (e *EVM) EstimateGas(
373373
if err != nil {
374374
return 0, fmt.Errorf("failed to decode EVM result from gas estimation: %w", err)
375375
}
376+
376377
if evmResult.ErrorCode != 0 {
378+
if evmResult.ErrorCode == evmTypes.ExecutionErrCodeExecutionReverted {
379+
return 0, errs.NewRevertError(evmResult.ReturnedData)
380+
}
377381
return 0, getErrorForCode(evmResult.ErrorCode)
378382
}
379383

tests/web3js/eth_deploy_contract_and_interact_test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,40 @@ it('deploy contract and interact', async() => {
173173
)
174174
}
175175

176+
// check that revert reason for custom error is correctly returned for gas estimation
177+
try {
178+
let callCustomError = deployed.contract.methods.customError().encodeABI()
179+
result = await web3.eth.estimateGas({
180+
from: conf.eoa.address,
181+
to: contractAddress,
182+
data: callCustomError,
183+
gas: 1_000_000,
184+
gasPrice: 0
185+
})
186+
} catch (error) {
187+
assert.equal(error.innerError.message, 'execution reverted')
188+
assert.equal(
189+
error.innerError.data,
190+
'0x9195785a00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001056616c756520697320746f6f206c6f7700000000000000000000000000000000'
191+
)
192+
}
193+
194+
// check that assertion error is correctly returned for gas estimation
195+
try {
196+
let callAssertError = deployed.contract.methods.assertError().encodeABI()
197+
result = await web3.eth.estimateGas({
198+
from: conf.eoa.address,
199+
to: contractAddress,
200+
data: callAssertError,
201+
gas: 1_000_000,
202+
gasPrice: 0
203+
})
204+
} catch (error) {
205+
assert.equal(error.innerError.message, 'execution reverted: Assert Error Message')
206+
assert.equal(
207+
error.innerError.data,
208+
'0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000014417373657274204572726f72204d657373616765000000000000000000000000'
209+
)
210+
}
211+
176212
}).timeout(10*1000)

0 commit comments

Comments
 (0)