@@ -70,7 +70,7 @@ func TestTxPriorityQueue_PriorityAndNonceOrdering(t *testing.T) {
70
70
{sender : "3" , isEVM : true , evmAddress : "0xabc" , evmNonce : 3 , priority : 9 },
71
71
{sender : "2" , isEVM : true , evmAddress : "0xabc" , evmNonce : 1 , priority : 7 },
72
72
},
73
- expectedOutput : []int64 {1 , 2 , 3 },
73
+ expectedOutput : []int64 {1 , 3 },
74
74
},
75
75
{
76
76
name : "PriorityWithEVMAndNonEVMDuplicateNonce" ,
@@ -380,17 +380,23 @@ func TestTxPriorityQueue_TryReplacement(t *testing.T) {
380
380
expectedQueue []* WrappedTx
381
381
expectedHeap []* WrappedTx
382
382
}{
383
- {& WrappedTx {isEVM : false }, []* WrappedTx {}, false , false , []* WrappedTx {}, []* WrappedTx {}},
384
- {& WrappedTx {isEVM : true , evmAddress : "addr1" }, []* WrappedTx {}, false , false , []* WrappedTx {}, []* WrappedTx {}},
383
+ // non-evm transaction is inserted into empty queue
384
+ {& WrappedTx {isEVM : false }, []* WrappedTx {}, false , false , []* WrappedTx {{isEVM : false }}, []* WrappedTx {{isEVM : false }}},
385
+ // evm transaction is inserted into empty queue
386
+ {& WrappedTx {isEVM : true , evmAddress : "addr1" }, []* WrappedTx {}, false , false , []* WrappedTx {{isEVM : true , evmAddress : "addr1" }}, []* WrappedTx {{isEVM : true , evmAddress : "addr1" }}},
387
+ // evm transaction (new nonce) is inserted into queue with existing tx (lower nonce)
385
388
{
386
389
& WrappedTx {isEVM : true , evmAddress : "addr1" , evmNonce : 1 , priority : 100 , tx : []byte ("abc" )}, []* WrappedTx {
387
390
{isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("def" )},
388
391
}, false , false , []* WrappedTx {
389
392
{isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("def" )},
393
+ {isEVM : true , evmAddress : "addr1" , evmNonce : 1 , priority : 100 , tx : []byte ("abc" )},
390
394
}, []* WrappedTx {
391
395
{isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("def" )},
396
+ {isEVM : true , evmAddress : "addr1" , evmNonce : 1 , priority : 100 , tx : []byte ("abc" )},
392
397
},
393
398
},
399
+ // evm transaction (new nonce) is not inserted because it's a duplicate nonce and same priority
394
400
{
395
401
& WrappedTx {isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("abc" )}, []* WrappedTx {
396
402
{isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("def" )},
@@ -400,6 +406,7 @@ func TestTxPriorityQueue_TryReplacement(t *testing.T) {
400
406
{isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("def" )},
401
407
},
402
408
},
409
+ // evm transaction (new nonce) replaces the existing nonce transaction because its priority is higher
403
410
{
404
411
& WrappedTx {isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 101 , tx : []byte ("abc" )}, []* WrappedTx {
405
412
{isEVM : true , evmAddress : "addr1" , evmNonce : 0 , priority : 100 , tx : []byte ("def" )},
@@ -425,13 +432,13 @@ func TestTxPriorityQueue_TryReplacement(t *testing.T) {
425
432
for _ , e := range test .existing {
426
433
pq .PushTx (e )
427
434
}
428
- replaced , dropped := pq .TryReplacement (test .tx )
435
+ replaced , inserted := pq .PushTx (test .tx )
429
436
if test .expectedReplaced {
430
437
require .NotNil (t , replaced )
431
438
} else {
432
439
require .Nil (t , replaced )
433
440
}
434
- require .Equal (t , test .expectedDropped , dropped )
441
+ require .Equal (t , test .expectedDropped , ! inserted )
435
442
for i , q := range pq .evmQueue [test .tx .evmAddress ] {
436
443
require .Equal (t , test .expectedQueue [i ].tx .Key (), q .tx .Key ())
437
444
require .Equal (t , test .expectedQueue [i ].priority , q .priority )
0 commit comments