@@ -79,7 +79,8 @@ public class TransactionSimulatorTest {
7979
8080 private static final Address DEFAULT_FROM =
8181 Address .fromHexString ("0x0000000000000000000000000000000000000000" );
82- private static final long GASCAP = 500L ;
82+ private static final long GAS_CAP = 500000L ;
83+ private static final long TRANSFER_GAS_LIMIT = 21000L ;
8384 private TransactionSimulator transactionSimulator ;
8485 private TransactionSimulator cappedTransactionSimulator ;
8586
@@ -96,7 +97,7 @@ public void setUp() {
9697 this .transactionSimulator =
9798 new TransactionSimulator (blockchain , worldStateArchive , protocolSchedule , 0 );
9899 this .cappedTransactionSimulator =
99- new TransactionSimulator (blockchain , worldStateArchive , protocolSchedule , GASCAP );
100+ new TransactionSimulator (blockchain , worldStateArchive , protocolSchedule , GAS_CAP );
100101 }
101102
102103 @ Test
@@ -124,7 +125,7 @@ public void shouldReturnSuccessfulResultWhenProcessingIsSuccessful() {
124125 .type (TransactionType .FRONTIER )
125126 .nonce (1L )
126127 .gasPrice (callParameter .getGasPrice ())
127- .gasLimit (callParameter .getGasLimit ())
128+ .gasLimit (blockHeader .getGasLimit ())
128129 .to (callParameter .getTo ())
129130 .sender (callParameter .getFrom ())
130131 .value (callParameter .getValue ())
@@ -155,7 +156,7 @@ public void shouldSetGasPriceToZeroWhenExceedingBalanceAllowed() {
155156 .type (TransactionType .FRONTIER )
156157 .nonce (1L )
157158 .gasPrice (Wei .ZERO )
158- .gasLimit (callParameter .getGasLimit ())
159+ .gasLimit (blockHeader .getGasLimit ())
159160 .to (callParameter .getTo ())
160161 .sender (callParameter .getFrom ())
161162 .value (callParameter .getValue ())
@@ -175,7 +176,8 @@ public void shouldSetGasPriceToZeroWhenExceedingBalanceAllowed() {
175176
176177 @ Test
177178 public void shouldSetFeePerGasToZeroWhenExceedingBalanceAllowed () {
178- final CallParameter callParameter = eip1559TransactionCallParameter (Wei .ONE , Wei .ONE );
179+ final CallParameter callParameter =
180+ eip1559TransactionCallParameter (Wei .ONE , Wei .ONE , TRANSFER_GAS_LIMIT );
179181
180182 final BlockHeader blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE );
181183
@@ -187,7 +189,7 @@ public void shouldSetFeePerGasToZeroWhenExceedingBalanceAllowed() {
187189 .type (TransactionType .EIP1559 )
188190 .chainId (BigInteger .ONE )
189191 .nonce (1L )
190- .gasLimit (callParameter . getGasLimit () )
192+ .gasLimit (TRANSFER_GAS_LIMIT )
191193 .maxFeePerGas (Wei .ZERO )
192194 .maxPriorityFeePerGas (Wei .ZERO )
193195 .to (callParameter .getTo ())
@@ -223,7 +225,7 @@ public void shouldNotSetGasPriceToZeroWhenExceedingBalanceIsNotAllowed() {
223225 .type (TransactionType .FRONTIER )
224226 .nonce (1L )
225227 .gasPrice (callParameter .getGasPrice ())
226- .gasLimit (callParameter .getGasLimit ())
228+ .gasLimit (blockHeader .getGasLimit ())
227229 .to (callParameter .getTo ())
228230 .sender (callParameter .getFrom ())
229231 .value (callParameter .getValue ())
@@ -244,7 +246,8 @@ public void shouldNotSetGasPriceToZeroWhenExceedingBalanceIsNotAllowed() {
244246
245247 @ Test
246248 public void shouldNotSetFeePerGasToZeroWhenExceedingBalanceIsNotAllowed () {
247- final CallParameter callParameter = eip1559TransactionCallParameter (Wei .ONE , Wei .ONE );
249+ final CallParameter callParameter =
250+ eip1559TransactionCallParameter (Wei .ONE , Wei .ONE , TRANSFER_GAS_LIMIT );
248251
249252 final BlockHeader blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE );
250253
@@ -256,7 +259,7 @@ public void shouldNotSetFeePerGasToZeroWhenExceedingBalanceIsNotAllowed() {
256259 .type (TransactionType .EIP1559 )
257260 .chainId (BigInteger .ONE )
258261 .nonce (1L )
259- .gasLimit (callParameter . getGasLimit () )
262+ .gasLimit (TRANSFER_GAS_LIMIT )
260263 .maxFeePerGas (callParameter .getMaxFeePerGas ().orElseThrow ())
261264 .maxPriorityFeePerGas (callParameter .getMaxPriorityFeePerGas ().orElseThrow ())
262265 .to (callParameter .getTo ())
@@ -349,7 +352,7 @@ public void shouldReturnFailureResultWhenProcessingFails() {
349352 .type (TransactionType .FRONTIER )
350353 .nonce (1L )
351354 .gasPrice (callParameter .getGasPrice ())
352- .gasLimit (callParameter .getGasLimit ())
355+ .gasLimit (blockHeader .getGasLimit ())
353356 .to (callParameter .getTo ())
354357 .sender (callParameter .getFrom ())
355358 .value (callParameter .getValue ())
@@ -390,7 +393,7 @@ public void shouldReturnSuccessfulResultWhenProcessingIsSuccessfulByHash() {
390393 .type (TransactionType .FRONTIER )
391394 .nonce (1L )
392395 .gasPrice (callParameter .getGasPrice ())
393- .gasLimit (callParameter .getGasLimit ())
396+ .gasLimit (blockHeader .getGasLimit ())
394397 .to (callParameter .getTo ())
395398 .sender (callParameter .getFrom ())
396399 .value (callParameter .getValue ())
@@ -479,7 +482,7 @@ public void shouldReturnFailureResultWhenProcessingFailsByHash() {
479482 .type (TransactionType .FRONTIER )
480483 .nonce (1L )
481484 .gasPrice (callParameter .getGasPrice ())
482- .gasLimit (callParameter .getGasLimit ())
485+ .gasLimit (blockHeader .getGasLimit ())
483486 .to (callParameter .getTo ())
484487 .sender (callParameter .getFrom ())
485488 .value (callParameter .getValue ())
@@ -509,7 +512,7 @@ public void shouldReturnSuccessfulResultWhenEip1559TransactionProcessingIsSucces
509512 .type (TransactionType .EIP1559 )
510513 .chainId (BigInteger .ONE )
511514 .nonce (1L )
512- .gasLimit (callParameter .getGasLimit ())
515+ .gasLimit (blockHeader .getGasLimit ())
513516 .maxFeePerGas (callParameter .getMaxFeePerGas ().orElseThrow ())
514517 .maxPriorityFeePerGas (callParameter .getMaxPriorityFeePerGas ().orElseThrow ())
515518 .to (callParameter .getTo ())
@@ -530,7 +533,7 @@ public void shouldReturnSuccessfulResultWhenEip1559TransactionProcessingIsSucces
530533 @ Test
531534 public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap () {
532535 final CallParameter callParameter =
533- eip1559TransactionCallParameter (Wei .ZERO , Wei .ZERO , GASCAP + 1 );
536+ eip1559TransactionCallParameter (Wei .ZERO , Wei .ZERO , GAS_CAP + 1 );
534537
535538 final BlockHeader blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE );
536539
@@ -542,7 +545,7 @@ public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap() {
542545 .type (TransactionType .EIP1559 )
543546 .chainId (BigInteger .ONE )
544547 .nonce (1L )
545- .gasLimit (GASCAP )
548+ .gasLimit (GAS_CAP )
546549 .maxFeePerGas (callParameter .getMaxFeePerGas ().orElseThrow ())
547550 .maxPriorityFeePerGas (callParameter .getMaxPriorityFeePerGas ().orElseThrow ())
548551 .to (callParameter .getTo ())
@@ -566,11 +569,48 @@ public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap() {
566569 }
567570
568571 @ Test
569- public void shouldUseRpcGasCapWhenCapIsHigherThanGasLimit () {
570- // generate a transaction with a gas limit that is lower than the gas cap,
571- // expect the gas cap to override parameter gas limit
572+ public void shouldUseProvidedGasLimitWhenBelowRpcCapGas () {
572573 final CallParameter callParameter =
573- eip1559TransactionCallParameter (Wei .ZERO , Wei .ZERO , GASCAP - 1 );
574+ eip1559TransactionCallParameter (Wei .ZERO , Wei .ZERO , GAS_CAP / 2 );
575+
576+ final BlockHeader blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE );
577+
578+ mockBlockchainForBlockHeader (blockHeader );
579+ mockWorldStateForAccount (blockHeader , callParameter .getFrom (), 1L );
580+
581+ final Transaction expectedTransaction =
582+ Transaction .builder ()
583+ .type (TransactionType .EIP1559 )
584+ .chainId (BigInteger .ONE )
585+ .nonce (1L )
586+ .gasLimit (GAS_CAP / 2 )
587+ .maxFeePerGas (callParameter .getMaxFeePerGas ().orElseThrow ())
588+ .maxPriorityFeePerGas (callParameter .getMaxPriorityFeePerGas ().orElseThrow ())
589+ .to (callParameter .getTo ())
590+ .sender (callParameter .getFrom ())
591+ .value (callParameter .getValue ())
592+ .payload (callParameter .getPayload ())
593+ .signature (FAKE_SIGNATURE )
594+ .build ();
595+
596+ mockProtocolSpecForProcessWithWorldUpdater ();
597+
598+ // call process with original transaction
599+ cappedTransactionSimulator .process (
600+ callParameter ,
601+ TransactionValidationParams .transactionSimulator (),
602+ OperationTracer .NO_TRACING ,
603+ 1L );
604+
605+ // expect overwritten transaction to be processed
606+ verifyTransactionWasProcessed (expectedTransaction );
607+ }
608+
609+ @ Test
610+ public void shouldUseRpcGasCapWhenGasLimitNoPresent () {
611+ // generate call parameters that do not specify a gas limit,
612+ // expect the rpc gas cap to be used for simulation
613+ final CallParameter callParameter = eip1559TransactionCallParameter (Wei .ZERO , Wei .ZERO , -1 );
574614
575615 final BlockHeader blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE );
576616
@@ -591,7 +631,7 @@ public void shouldUseRpcGasCapWhenCapIsHigherThanGasLimit() {
591631 .value (callParameter .getValue ())
592632 .payload (callParameter .getPayload ())
593633 .signature (FAKE_SIGNATURE )
594- .gasLimit (GASCAP )
634+ .gasLimit (GAS_CAP )
595635 .build ();
596636
597637 // call process with original transaction
@@ -781,7 +821,7 @@ private CallParameter legacyTransactionCallParameter(final Wei gasPrice) {
781821 return new CallParameter (
782822 Address .fromHexString ("0x0" ),
783823 Address .fromHexString ("0x0" ),
784- 0 ,
824+ - 1 ,
785825 gasPrice ,
786826 Wei .of (0 ),
787827 Bytes .EMPTY );
@@ -793,7 +833,7 @@ private CallParameter eip1559TransactionCallParameter() {
793833
794834 private CallParameter eip1559TransactionCallParameter (
795835 final Wei maxFeePerGas , final Wei maxPriorityFeePerGas ) {
796- return eip1559TransactionCallParameter (maxFeePerGas , maxPriorityFeePerGas , 0L );
836+ return eip1559TransactionCallParameter (maxFeePerGas , maxPriorityFeePerGas , - 1 );
797837 }
798838
799839 private CallParameter eip1559TransactionCallParameter (
0 commit comments