@@ -140,7 +140,7 @@ public void shouldReturnErrorWhenTransientLegacyTransactionProcessorReturnsEmpty
140
140
final JsonRpcRequestContext request =
141
141
ethEstimateGasRequest (defaultLegacyTransactionCallParameter (Wei .ZERO ));
142
142
when (transactionSimulator .process (
143
- eq (modifiedLegacyTransactionCallParameter (Wei .ZERO )),
143
+ eq (modifiedLegacyTransactionCallParameter (Wei .ZERO , Optional . empty () )),
144
144
eq (Optional .empty ()), // no account overrides
145
145
any (TransactionValidationParams .class ),
146
146
any (OperationTracer .class ),
@@ -193,11 +193,26 @@ public void shouldUseGasPriceParameterWhenIsPresent() {
193
193
assertThat (method .response (request )).usingRecursiveComparison ().isEqualTo (expectedResponse );
194
194
}
195
195
196
+ @ Test
197
+ public void shouldUseNonceParameterWhenIsPresent () {
198
+ final Wei gasPrice = Wei .of (1000 );
199
+ final long nonce = 0L ;
200
+ final JsonRpcRequestContext request =
201
+ ethEstimateGasRequest (
202
+ eip1559TransactionCallParameter (Optional .of (gasPrice ), Optional .of (nonce )));
203
+ getMockTransactionSimulatorResult (
204
+ true , 1L , gasPrice , Optional .empty (), latestBlockHeader , Optional .of (nonce ));
205
+
206
+ final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse (null , Quantity .create (1L ));
207
+ assertThat (method .response (request )).usingRecursiveComparison ().isEqualTo (expectedResponse );
208
+ }
209
+
196
210
@ Test
197
211
public void shouldNotErrorWhenGasPricePresentForEip1559Transaction () {
198
212
final Wei gasPrice = Wei .of (1000 );
199
213
final JsonRpcRequestContext request =
200
- ethEstimateGasRequest (eip1559TransactionCallParameter (Optional .of (gasPrice )));
214
+ ethEstimateGasRequest (
215
+ eip1559TransactionCallParameter (Optional .of (gasPrice ), Optional .empty ()));
201
216
mockTransientProcessorResultGasEstimate (
202
217
1L , true , gasPrice , Optional .empty (), latestBlockHeader );
203
218
@@ -379,9 +394,11 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabled() {
379
394
380
395
verify (transactionSimulator )
381
396
.process (
382
- eq (modifiedLegacyTransactionCallParameter (Wei .ZERO )),
397
+ eq (modifiedLegacyTransactionCallParameter (Wei .ZERO , Optional . empty () )),
383
398
eq (Optional .empty ()), // no account overrides
384
- eq (TransactionValidationParams .transactionSimulatorAllowExceedingBalance ()),
399
+ eq (
400
+ TransactionValidationParams
401
+ .transactionSimulatorAllowExceedingBalanceAndFutureNonceParams ),
385
402
any (OperationTracer .class ),
386
403
eq (latestBlockHeader ));
387
404
}
@@ -396,9 +413,9 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeEnabled() {
396
413
397
414
verify (transactionSimulator )
398
415
.process (
399
- eq (modifiedLegacyTransactionCallParameter (Wei .ZERO )),
416
+ eq (modifiedLegacyTransactionCallParameter (Wei .ZERO , Optional . empty () )),
400
417
eq (Optional .empty ()), // no account overrides
401
- eq (TransactionValidationParams .transactionSimulator ()),
418
+ eq (TransactionValidationParams .transactionSimulatorAllowFutureNonce ()),
402
419
any (OperationTracer .class ),
403
420
eq (latestBlockHeader ));
404
421
}
@@ -456,7 +473,8 @@ private void mockTransientProcessorResultTxInvalidReason(
456
473
final String validationFailedErrorMessage ,
457
474
final BlockHeader blockHeader ) {
458
475
final TransactionSimulatorResult mockTxSimResult =
459
- getMockTransactionSimulatorResult (false , 0 , Wei .ZERO , Optional .empty (), blockHeader );
476
+ getMockTransactionSimulatorResult (
477
+ false , 0 , Wei .ZERO , Optional .empty (), blockHeader , Optional .empty ());
460
478
when (mockTxSimResult .getValidationResult ())
461
479
.thenReturn (
462
480
validationFailedErrorMessage == null
@@ -493,7 +511,7 @@ private void mockTransientProcessorResultGasEstimate(
493
511
final Optional <Bytes > revertReason ,
494
512
final BlockHeader blockHeader ) {
495
513
getMockTransactionSimulatorResult (
496
- isSuccessful , estimateGas , gasPrice , revertReason , blockHeader );
514
+ isSuccessful , estimateGas , gasPrice , revertReason , blockHeader , Optional . empty () );
497
515
}
498
516
499
517
@ SuppressWarnings ("ReferenceEquality" )
@@ -502,11 +520,12 @@ private TransactionSimulatorResult getMockTransactionSimulatorResult(
502
520
final long estimateGas ,
503
521
final Wei gasPrice ,
504
522
final Optional <Bytes > revertReason ,
505
- final BlockHeader blockHeader ) {
523
+ final BlockHeader blockHeader ,
524
+ final Optional <Long > maybeNonce ) {
506
525
final TransactionSimulatorResult mockTxSimResult = mock (TransactionSimulatorResult .class );
507
526
if (blockHeader == pendingBlockHeader ) {
508
527
when (transactionSimulator .processOnPending (
509
- eq (modifiedLegacyTransactionCallParameter (gasPrice )),
528
+ eq (modifiedLegacyTransactionCallParameter (gasPrice , maybeNonce )),
510
529
eq (Optional .empty ()), // no account overrides
511
530
any (TransactionValidationParams .class ),
512
531
any (OperationTracer .class ),
@@ -521,7 +540,7 @@ private TransactionSimulatorResult getMockTransactionSimulatorResult(
521
540
.thenReturn (Optional .of (mockTxSimResult ));
522
541
} else {
523
542
when (transactionSimulator .process (
524
- eq (modifiedLegacyTransactionCallParameter (gasPrice )),
543
+ eq (modifiedLegacyTransactionCallParameter (gasPrice , maybeNonce )),
525
544
eq (Optional .empty ()), // no account overrides
526
545
any (TransactionValidationParams .class ),
527
546
any (OperationTracer .class ),
@@ -536,7 +555,7 @@ private TransactionSimulatorResult getMockTransactionSimulatorResult(
536
555
.thenReturn (Optional .of (mockTxSimResult ));
537
556
// for testing different combination of gasPrice params
538
557
when (transactionSimulator .process (
539
- eq (modifiedEip1559TransactionCallParameter (Optional .of (gasPrice ))),
558
+ eq (modifiedEip1559TransactionCallParameter (Optional .of (gasPrice ), maybeNonce )),
540
559
eq (Optional .empty ()), // no account overrides
541
560
any (TransactionValidationParams .class ),
542
561
any (OperationTracer .class ),
@@ -569,7 +588,8 @@ private JsonCallParameter legacyTransactionCallParameter(
569
588
.build ();
570
589
}
571
590
572
- private CallParameter modifiedLegacyTransactionCallParameter (final Wei gasPrice ) {
591
+ private CallParameter modifiedLegacyTransactionCallParameter (
592
+ final Wei gasPrice , final Optional <Long > maybeNonce ) {
573
593
return new CallParameter (
574
594
Address .fromHexString ("0x0" ),
575
595
Address .fromHexString ("0x0" ),
@@ -580,14 +600,15 @@ private CallParameter modifiedLegacyTransactionCallParameter(final Wei gasPrice)
580
600
Wei .ZERO ,
581
601
Bytes .EMPTY ,
582
602
Optional .empty (),
583
- Optional . empty () );
603
+ maybeNonce );
584
604
}
585
605
586
606
private CallParameter eip1559TransactionCallParameter () {
587
- return eip1559TransactionCallParameter (Optional .empty ());
607
+ return eip1559TransactionCallParameter (Optional .empty (), Optional . empty () );
588
608
}
589
609
590
- private JsonCallParameter eip1559TransactionCallParameter (final Optional <Wei > maybeGasPrice ) {
610
+ private JsonCallParameter eip1559TransactionCallParameter (
611
+ final Optional <Wei > maybeGasPrice , final Optional <Long > maybeNonce ) {
591
612
return new JsonCallParameter .JsonCallParameterBuilder ()
592
613
.withFrom (Address .fromHexString ("0x0" ))
593
614
.withTo (Address .fromHexString ("0x0" ))
@@ -597,14 +618,16 @@ private JsonCallParameter eip1559TransactionCallParameter(final Optional<Wei> ma
597
618
.withValue (Wei .ZERO )
598
619
.withInput (Bytes .EMPTY )
599
620
.withStrict (false )
621
+ .withNonce (maybeNonce .map (UnsignedLongParameter ::new ).orElse (null ))
600
622
.build ();
601
623
}
602
624
603
625
private CallParameter modifiedEip1559TransactionCallParameter () {
604
- return modifiedEip1559TransactionCallParameter (Optional .empty ());
626
+ return modifiedEip1559TransactionCallParameter (Optional .empty (), Optional . empty () );
605
627
}
606
628
607
- private CallParameter modifiedEip1559TransactionCallParameter (final Optional <Wei > gasPrice ) {
629
+ private CallParameter modifiedEip1559TransactionCallParameter (
630
+ final Optional <Wei > gasPrice , final Optional <Long > maybeNonce ) {
608
631
return new CallParameter (
609
632
Address .fromHexString ("0x0" ),
610
633
Address .fromHexString ("0x0" ),
@@ -615,7 +638,7 @@ private CallParameter modifiedEip1559TransactionCallParameter(final Optional<Wei
615
638
Wei .ZERO ,
616
639
Bytes .EMPTY ,
617
640
Optional .empty (),
618
- Optional . empty () );
641
+ maybeNonce );
619
642
}
620
643
621
644
private JsonRpcRequestContext ethEstimateGasRequest (final CallParameter callParameter ) {
0 commit comments