@@ -23,6 +23,7 @@ import basicContractJson from '../contracts/Basic.json';
2323import ERC20MockJson from '../contracts/ERC20Mock.json' ;
2424// Contracts from local resources
2525import parentContractJson from '../contracts/Parent.json' ;
26+ import reverterContractJson from '../contracts/Reverter.json' ;
2627import storageContractJson from '../contracts/Storage.json' ;
2728import TokenCreateJson from '../contracts/TokenCreateContract.json' ;
2829// Assertions from local resources
@@ -152,11 +153,17 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
152153 basicContractAddress = basicContract . target as string ;
153154 } ) ;
154155
155- it ( '@release-light, @release should execute "eth_estimateGas"' , async function ( ) {
156- const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [ { } ] ) ;
157- expect ( res ) . to . contain ( '0x' ) ;
158- expect ( res ) . to . not . be . equal ( '0x' ) ;
159- expect ( res ) . to . not . be . equal ( '0x0' ) ;
156+ it ( '@release-light, @release should execute "eth_estimateGas" with empty object and throw error' , async function ( ) {
157+ // With the removal of fallback gas, empty transaction object should throw error
158+ const promise = relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [ { } ] ) ;
159+ await expect ( promise ) . to . eventually . be . rejected . and . satisfy ( ( error : any ) => {
160+ const errorBody = error ?. response ?. bodyJson ?. error ;
161+ return (
162+ errorBody &&
163+ errorBody . code === - 32000 &&
164+ errorBody . message . includes ( 'Error occurred during gas price estimation' )
165+ ) ;
166+ } ) ;
160167 } ) ;
161168
162169 it ( '@release should execute "eth_estimateGas" for contract call' , async function ( ) {
@@ -181,6 +188,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
181188 it ( '@release should execute "eth_estimateGas" for existing account' , async function ( ) {
182189 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
183190 {
191+ from : accounts [ 0 ] . address ,
184192 to : accounts [ 1 ] . address ,
185193 value : '0x1' ,
186194 } ,
@@ -198,6 +206,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
198206
199207 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
200208 {
209+ from : accounts [ 0 ] . address ,
201210 to : hollowAccount . address ,
202211 value : '0x1' ,
203212 } ,
@@ -206,12 +215,12 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
206215 expect ( Number ( res ) ) . to . be . greaterThanOrEqual ( Number ( minGasTxHollowAccountCreation ) ) ;
207216 } ) ;
208217
209- it ( 'should execute "eth_estimateGas" with to, from, value and gas filed ' , async function ( ) {
218+ it ( 'should execute "eth_estimateGas" with to, from, value and gas field ' , async function ( ) {
210219 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
211220 {
212- from : '0x114f60009ee6b84861c0cdae8829751e517bc4d7' ,
213- to : '0xae410f34f7487e2cd03396499cebb09b79f45d6e' ,
214- value : '0xa688906bd8b00000 ' ,
221+ from : accounts [ 0 ] . address ,
222+ to : accounts [ 1 ] . address ,
223+ value : '0x1 ' ,
215224 gas : '0xd97010' ,
216225 } ,
217226 ] ) ;
@@ -220,12 +229,12 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
220229 expect ( res ) . to . not . be . equal ( '0x0' ) ;
221230 } ) ;
222231
223- it ( 'should execute "eth_estimateGas" with to, from, value,accessList gas filed ' , async function ( ) {
232+ it ( 'should execute "eth_estimateGas" with to, from, value, accessList and gas field ' , async function ( ) {
224233 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
225234 {
226- from : '0x114f60009ee6b84861c0cdae8829751e517bc4d7' ,
227- to : '0xae410f34f7487e2cd03396499cebb09b79f45d6e' ,
228- value : '0xa688906bd8b00000 ' ,
235+ from : accounts [ 0 ] . address ,
236+ to : accounts [ 1 ] . address ,
237+ value : '0x1 ' ,
229238 gas : '0xd97010' ,
230239 accessList : [ ] ,
231240 } ,
@@ -235,12 +244,13 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
235244 expect ( res ) . to . not . be . equal ( '0x0' ) ;
236245 } ) ;
237246
238- it ( 'should execute "eth_estimateGas" with `to` filed set to null (deployment transaction)' , async function ( ) {
247+ it ( 'should execute "eth_estimateGas" with `to` field set to null (deployment transaction)' , async function ( ) {
248+ // Use the Basic contract bytecode for a valid deployment transaction
239249 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
240250 {
241- from : '0x114f60009ee6b84861c0cdae8829751e517bc4d7' ,
251+ from : accounts [ 0 ] . address ,
242252 to : null ,
243- value : `0x ${ '00' . repeat ( 5121 ) } ` ,
253+ data : basicContractJson . bytecode ,
244254 } ,
245255 ] ) ;
246256 expect ( res ) . to . contain ( '0x' ) ;
@@ -331,9 +341,9 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
331341 it ( 'should execute "eth_estimateGas" with data as 0x instead of null' , async function ( ) {
332342 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
333343 {
334- from : '0x114f60009ee6b84861c0cdae8829751e517bc4d7' ,
335- to : '0xae410f34f7487e2cd03396499cebb09b79f45d6e' ,
336- value : '0xa688906bd8b00000 ' ,
344+ from : accounts [ 0 ] . address ,
345+ to : accounts [ 1 ] . address ,
346+ value : '0x1 ' ,
337347 gas : '0xd97010' ,
338348 data : '0x' ,
339349 } ,
@@ -346,9 +356,9 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
346356 it ( 'should execute "eth_estimateGas" with input as 0x instead of data' , async function ( ) {
347357 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
348358 {
349- from : '0x114f60009ee6b84861c0cdae8829751e517bc4d7' ,
350- to : '0xae410f34f7487e2cd03396499cebb09b79f45d6e' ,
351- value : '0xa688906bd8b00000 ' ,
359+ from : accounts [ 0 ] . address ,
360+ to : accounts [ 1 ] . address ,
361+ value : '0x1 ' ,
352362 gas : '0xd97010' ,
353363 input : '0x' ,
354364 } ,
@@ -361,9 +371,9 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
361371 it ( 'should execute "eth_estimateGas" with both input and data fields present in the txObject' , async function ( ) {
362372 const res = await relay . call ( RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS , [
363373 {
364- from : '0x114f60009ee6b84861c0cdae8829751e517bc4d7' ,
365- to : '0xae410f34f7487e2cd03396499cebb09b79f45d6e' ,
366- value : '0xa688906bd8b00000 ' ,
374+ from : accounts [ 0 ] . address ,
375+ to : accounts [ 1 ] . address ,
376+ value : '0x1 ' ,
367377 gas : '0xd97010' ,
368378 input : '0x' ,
369379 data : '0x' ,
@@ -373,6 +383,83 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
373383 expect ( res ) . to . not . be . equal ( '0x' ) ;
374384 expect ( res ) . to . not . be . equal ( '0x0' ) ;
375385 } ) ;
386+
387+ describe ( 'Contract call reverts during gas estimation' , async function ( ) {
388+ let reverterContract : ethers . Contract ;
389+ let reverterContractAddress : string ;
390+
391+ // Function selectors for Reverter contract methods
392+ const REVERT_WITH_STRING_CALL_DATA = '0x0323d234' ; // revertWithString()
393+ const REVERT_WITH_CUSTOM_ERROR_CALL_DATA = '0x46fc4bb1' ; // revertWithCustomError()
394+ const REVERT_WITH_PANIC_CALL_DATA = '0x33fe3fbd' ; // revertWithPanic()
395+ const REVERT_WITH_NOTHING_CALL_DATA = '0xfe0a3dd7' ; // revertWithNothing()
396+
397+ before ( async function ( ) {
398+ reverterContract = await Utils . deployContract (
399+ reverterContractJson . abi ,
400+ reverterContractJson . bytecode ,
401+ accounts [ 0 ] . wallet ,
402+ ) ;
403+ reverterContractAddress = reverterContract . target as string ;
404+ } ) ;
405+
406+ it ( 'should throw error when eth_estimateGas is called with a contract that reverts with string message' , async function ( ) {
407+ // With the new behavior, contract reverts should throw errors instead of returning predefined gas
408+ await relay . callFailing (
409+ RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS ,
410+ [
411+ {
412+ from : accounts [ 0 ] . address ,
413+ to : reverterContractAddress ,
414+ data : REVERT_WITH_STRING_CALL_DATA ,
415+ } ,
416+ ] ,
417+ predefined . CONTRACT_REVERT ( 'Some revert message' ) ,
418+ ) ;
419+ } ) ;
420+
421+ it ( 'should throw error when eth_estimateGas is called with a contract that reverts with custom error' , async function ( ) {
422+ await relay . callFailing (
423+ RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS ,
424+ [
425+ {
426+ from : accounts [ 0 ] . address ,
427+ to : reverterContractAddress ,
428+ data : REVERT_WITH_CUSTOM_ERROR_CALL_DATA ,
429+ } ,
430+ ] ,
431+ predefined . CONTRACT_REVERT ( ) ,
432+ ) ;
433+ } ) ;
434+
435+ it ( 'should throw error when eth_estimateGas is called with a contract that reverts with panic error' , async function ( ) {
436+ await relay . callFailing (
437+ RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS ,
438+ [
439+ {
440+ from : accounts [ 0 ] . address ,
441+ to : reverterContractAddress ,
442+ data : REVERT_WITH_PANIC_CALL_DATA ,
443+ } ,
444+ ] ,
445+ predefined . CONTRACT_REVERT ( ) ,
446+ ) ;
447+ } ) ;
448+
449+ it ( 'should throw error when eth_estimateGas is called with a contract that reverts without message' , async function ( ) {
450+ await relay . callFailing (
451+ RelayCalls . ETH_ENDPOINTS . ETH_ESTIMATE_GAS ,
452+ [
453+ {
454+ from : accounts [ 0 ] . address ,
455+ to : reverterContractAddress ,
456+ data : REVERT_WITH_NOTHING_CALL_DATA ,
457+ } ,
458+ ] ,
459+ predefined . CONTRACT_REVERT ( ) ,
460+ ) ;
461+ } ) ;
462+ } ) ;
376463 } ) ;
377464
378465 describe ( 'eth_gasPrice' , async function ( ) {
0 commit comments