@@ -150,6 +150,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke
150
150
})
151
151
authList = append (authList , auth )
152
152
}
153
+ return pricedSetCodeTxWithAuth (nonce , gaslimit , gasFee , tip , key , authList )
154
+ }
155
+
156
+ func pricedSetCodeTxWithAuth (nonce uint64 , gaslimit uint64 , gasFee , tip * uint256.Int , key * ecdsa.PrivateKey , authList []types.SetCodeAuthorization ) * types.Transaction {
153
157
return types .MustSignNewTx (key , types .LatestSignerForChainID (params .TestChainConfig .ChainID ), & types.SetCodeTx {
154
158
ChainID : uint256 .MustFromBig (params .TestChainConfig .ChainID ),
155
159
Nonce : nonce ,
@@ -2494,6 +2498,65 @@ func TestSetCodeTransactions(t *testing.T) {
2494
2498
}
2495
2499
}
2496
2500
2501
+ func TestSetCodeTransactionsReorg (t * testing.T ) {
2502
+ t .Parallel ()
2503
+
2504
+ // Create the pool to test the status retrievals with
2505
+ statedb , _ := state .New (types .EmptyRootHash , state .NewDatabaseForTesting ())
2506
+ blockchain := newTestBlockChain (params .MergedTestChainConfig , 1000000 , statedb , new (event.Feed ))
2507
+
2508
+ pool := New (testTxPoolConfig , blockchain )
2509
+ pool .Init (testTxPoolConfig .PriceLimit , blockchain .CurrentBlock (), makeAddressReserver ())
2510
+ defer pool .Close ()
2511
+
2512
+ // Create the test accounts
2513
+ var (
2514
+ keyA , _ = crypto .GenerateKey ()
2515
+ addrA = crypto .PubkeyToAddress (keyA .PublicKey )
2516
+ )
2517
+ testAddBalance (pool , addrA , big .NewInt (params .Ether ))
2518
+ // Send an authorization for 0x42
2519
+ var authList []types.SetCodeAuthorization
2520
+ auth , _ := types .SignSetCode (keyA , types.SetCodeAuthorization {
2521
+ ChainID : * uint256 .MustFromBig (params .TestChainConfig .ChainID ),
2522
+ Address : common.Address {0x42 },
2523
+ Nonce : 0 ,
2524
+ })
2525
+ authList = append (authList , auth )
2526
+ if err := pool .addRemoteSync (pricedSetCodeTxWithAuth (0 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keyA , authList )); err != nil {
2527
+ t .Fatalf ("failed to add with remote setcode transaction: %v" , err )
2528
+ }
2529
+ // Simulate the chain moving
2530
+ blockchain .statedb .SetNonce (addrA , 1 , tracing .NonceChangeAuthorization )
2531
+ blockchain .statedb .SetCode (addrA , types .AddressToDelegation (auth .Address ))
2532
+ <- pool .requestReset (nil , nil )
2533
+ // Set an authorization for 0x00
2534
+ auth , _ = types .SignSetCode (keyA , types.SetCodeAuthorization {
2535
+ ChainID : * uint256 .MustFromBig (params .TestChainConfig .ChainID ),
2536
+ Address : common.Address {},
2537
+ Nonce : 0 ,
2538
+ })
2539
+ authList = append (authList , auth )
2540
+ if err := pool .addRemoteSync (pricedSetCodeTxWithAuth (1 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keyA , authList )); err != nil {
2541
+ t .Fatalf ("failed to add with remote setcode transaction: %v" , err )
2542
+ }
2543
+ // Try to add a transactions in
2544
+ if err := pool .addRemoteSync (pricedTransaction (2 , 100000 , big .NewInt (1000 ), keyA )); ! errors .Is (err , txpool .ErrAccountLimitExceeded ) {
2545
+ t .Fatalf ("unexpected error %v, expecting %v" , err , txpool .ErrAccountLimitExceeded )
2546
+ }
2547
+ // Simulate the chain moving
2548
+ blockchain .statedb .SetNonce (addrA , 2 , tracing .NonceChangeAuthorization )
2549
+ blockchain .statedb .SetCode (addrA , nil )
2550
+ <- pool .requestReset (nil , nil )
2551
+ // Now send two transactions from addrA
2552
+ if err := pool .addRemoteSync (pricedTransaction (2 , 100000 , big .NewInt (1000 ), keyA )); err != nil {
2553
+ t .Fatalf ("failed to added single transaction: %v" , err )
2554
+ }
2555
+ if err := pool .addRemoteSync (pricedTransaction (3 , 100000 , big .NewInt (1000 ), keyA )); err != nil {
2556
+ t .Fatalf ("failed to added single transaction: %v" , err )
2557
+ }
2558
+ }
2559
+
2497
2560
// Benchmarks the speed of validating the contents of the pending queue of the
2498
2561
// transaction pool.
2499
2562
func BenchmarkPendingDemotion100 (b * testing.B ) { benchmarkPendingDemotion (b , 100 ) }
0 commit comments