6565import java .util .Map ;
6666import java .util .Optional ;
6767import java .util .OptionalLong ;
68+ import java .util .stream .Stream ;
6869
6970import com .google .common .base .Supplier ;
7071import com .google .common .base .Suppliers ;
7374import org .junit .jupiter .api .BeforeEach ;
7475import org .junit .jupiter .api .Test ;
7576import org .junit .jupiter .api .extension .ExtendWith ;
77+ import org .junit .jupiter .params .ParameterizedTest ;
78+ import org .junit .jupiter .params .provider .Arguments ;
79+ import org .junit .jupiter .params .provider .MethodSource ;
7680import org .mockito .Mock ;
7781import org .mockito .junit .jupiter .MockitoExtension ;
7882import org .mockito .junit .jupiter .MockitoSettings ;
@@ -91,7 +95,7 @@ public class TransactionSimulatorTest {
9195
9296 private static final Address DEFAULT_FROM =
9397 Address .fromHexString ("0x0000000000000000000000000000000000000000" );
94- private static final long GAS_CAP = 500_000L ;
98+ private static final long RPC_GAS_CAP = 500_000L ;
9599 private static final long TRANSFER_GAS_LIMIT = 21_000L ;
96100 private static final long DEFAULT_BLOCK_GAS_LIMIT = 30_000_000L ;
97101 private TransactionSimulator uncappedTransactionSimulator ;
@@ -117,7 +121,7 @@ public void setUp() {
117121 // capped at a lower limit
118122 this .cappedTransactionSimulator =
119123 new TransactionSimulator (
120- blockchain , worldStateArchive , protocolSchedule , miningConfiguration , GAS_CAP );
124+ blockchain , worldStateArchive , protocolSchedule , miningConfiguration , RPC_GAS_CAP );
121125 // capped at default limit
122126 this .defaultCappedTransactionSimulator =
123127 new TransactionSimulator (
@@ -643,7 +647,7 @@ public void shouldReturnSuccessfulResultWhenEip1559TransactionProcessingIsSucces
643647 @ Test
644648 public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap () {
645649 final CallParameter callParameter =
646- eip1559TransactionCallParameterBuilder ().gas (GAS_CAP + 1 ).build ();
650+ eip1559TransactionCallParameterBuilder ().gas (RPC_GAS_CAP + 1 ).build ();
647651
648652 mockBlockchainAndWorldState (callParameter );
649653
@@ -652,7 +656,7 @@ public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap() {
652656 .type (TransactionType .EIP1559 )
653657 .chainId (BigInteger .ONE )
654658 .nonce (1L )
655- .gasLimit (GAS_CAP )
659+ .gasLimit (RPC_GAS_CAP )
656660 .maxFeePerGas (callParameter .getMaxFeePerGas ().orElseThrow ())
657661 .maxPriorityFeePerGas (callParameter .getMaxPriorityFeePerGas ().orElseThrow ())
658662 .to (callParameter .getTo ().orElseThrow ())
@@ -675,7 +679,7 @@ public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap() {
675679 @ Test
676680 public void shouldUseProvidedGasLimitWhenBelowRpcCapGas () {
677681 final CallParameter callParameter =
678- eip1559TransactionCallParameterBuilder ().gas (GAS_CAP / 2 ).build ();
682+ eip1559TransactionCallParameterBuilder ().gas (RPC_GAS_CAP / 2 ).build ();
679683
680684 final var blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE , DEFAULT_BLOCK_GAS_LIMIT );
681685
@@ -686,7 +690,7 @@ public void shouldUseProvidedGasLimitWhenBelowRpcCapGas() {
686690 .type (TransactionType .EIP1559 )
687691 .chainId (BigInteger .ONE )
688692 .nonce (1L )
689- .gasLimit (GAS_CAP / 2 )
693+ .gasLimit (RPC_GAS_CAP / 2 )
690694 .maxFeePerGas (callParameter .getMaxFeePerGas ().orElseThrow ())
691695 .maxPriorityFeePerGas (callParameter .getMaxPriorityFeePerGas ().orElseThrow ())
692696 .to (callParameter .getTo ().orElseThrow ())
@@ -728,7 +732,7 @@ public void shouldUseRpcGasCapWhenGasLimitNotPresent() {
728732 .value (callParameter .getValue ().orElseThrow ())
729733 .payload (callParameter .getPayload ().orElseThrow ())
730734 .signature (FAKE_SIGNATURE )
731- .gasLimit (GAS_CAP )
735+ .gasLimit (RPC_GAS_CAP )
732736 .build ();
733737
734738 // call process with original transaction
@@ -773,14 +777,19 @@ public void shouldUseBlockGasLimitWhenGasLimitNotPresent() {
773777 verifyTransactionWasProcessed (expectedTransaction );
774778 }
775779
776- @ Test
777- public void shouldUseTxGasLimitCapWhenWhenGasLimitNotPresent () {
778- final long txGasLimitCap = DEFAULT_BLOCK_GAS_LIMIT - 1 ;
779-
780+ @ ParameterizedTest
781+ @ MethodSource ("shouldUseTxGasLimitCapWhenWhenGasLimitNotPresent" )
782+ public void shouldUseTxGasLimitCapWhenWhenGasLimitNotPresent (
783+ final RpcGasCapVariant rpcGasCapVariant ,
784+ final long blockGasLimit ,
785+ final long txGasLimitCap ,
786+ final long expectedGasLimit ) {
780787 final CallParameter callParameter =
781788 eip1559TransactionCallParameterBuilder ().gas (OptionalLong .empty ()).build ();
782789
783- mockBlockchainAndWorldState (callParameter );
790+ final BlockHeader blockHeader = mockBlockHeader (Hash .ZERO , 1L , Wei .ONE , blockGasLimit );
791+
792+ mockBlockchainAndWorldState (callParameter , blockHeader );
784793 mockProtocolSpecForProcessWithWorldUpdater (txGasLimitCap );
785794
786795 final Transaction expectedTransaction =
@@ -795,17 +804,62 @@ public void shouldUseTxGasLimitCapWhenWhenGasLimitNotPresent() {
795804 .value (callParameter .getValue ().orElseThrow ())
796805 .payload (callParameter .getPayload ().orElseThrow ())
797806 .signature (FAKE_SIGNATURE )
798- .gasLimit (txGasLimitCap )
807+ .gasLimit (expectedGasLimit )
799808 .build ();
800809
801- // call process with original transaction
802- defaultCappedTransactionSimulator .process (
810+ final var simulator =
811+ switch (rpcGasCapVariant ) {
812+ case DEFAULT -> defaultCappedTransactionSimulator ;
813+ case UNCAPPED -> uncappedTransactionSimulator ;
814+ case CAPPED -> cappedTransactionSimulator ;
815+ };
816+
817+ simulator .process (
803818 callParameter , TransactionValidationParams .transactionSimulator (), NO_TRACING , 1L );
804819
805- // expect transaction with the gas limit cap to be processed
806820 verifyTransactionWasProcessed (expectedTransaction );
807821 }
808822
823+ private enum RpcGasCapVariant {
824+ DEFAULT ,
825+ CAPPED ,
826+ UNCAPPED ;
827+ }
828+
829+ private static Stream <Arguments > shouldUseTxGasLimitCapWhenWhenGasLimitNotPresent () {
830+ return Stream .of (
831+ Arguments .of (
832+ RpcGasCapVariant .DEFAULT ,
833+ DEFAULT_BLOCK_GAS_LIMIT ,
834+ DEFAULT_BLOCK_GAS_LIMIT - 1 ,
835+ DEFAULT_BLOCK_GAS_LIMIT - 1 ),
836+ Arguments .of (
837+ RpcGasCapVariant .DEFAULT ,
838+ DEFAULT_BLOCK_GAS_LIMIT ,
839+ DEFAULT_BLOCK_GAS_LIMIT + 1 ,
840+ DEFAULT_BLOCK_GAS_LIMIT ),
841+ Arguments .of (
842+ RpcGasCapVariant .CAPPED ,
843+ DEFAULT_BLOCK_GAS_LIMIT ,
844+ DEFAULT_BLOCK_GAS_LIMIT - 1 ,
845+ RPC_GAS_CAP ),
846+ Arguments .of (
847+ RpcGasCapVariant .CAPPED ,
848+ DEFAULT_BLOCK_GAS_LIMIT ,
849+ DEFAULT_BLOCK_GAS_LIMIT + 1 ,
850+ RPC_GAS_CAP ),
851+ Arguments .of (
852+ RpcGasCapVariant .UNCAPPED ,
853+ DEFAULT_BLOCK_GAS_LIMIT ,
854+ DEFAULT_BLOCK_GAS_LIMIT - 1 ,
855+ DEFAULT_BLOCK_GAS_LIMIT - 1 ),
856+ Arguments .of (
857+ RpcGasCapVariant .UNCAPPED ,
858+ DEFAULT_BLOCK_GAS_LIMIT ,
859+ DEFAULT_BLOCK_GAS_LIMIT + 1 ,
860+ DEFAULT_BLOCK_GAS_LIMIT ));
861+ }
862+
809863 @ Test
810864 public void shouldReturnSuccessfulResultWhenBlobTransactionProcessingIsSuccessful () {
811865 final CallParameter callParameter = blobTransactionCallParameter ();
0 commit comments