@@ -149,6 +149,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke
149
149
})
150
150
authList = append (authList , auth )
151
151
}
152
+ return pricedSetCodeTxWithAuth (nonce , gaslimit , gasFee , tip , key , authList )
153
+ }
154
+
155
+ func pricedSetCodeTxWithAuth (nonce uint64 , gaslimit uint64 , gasFee , tip * uint256.Int , key * ecdsa.PrivateKey , authList []types.SetCodeAuthorization ) * types.Transaction {
152
156
return types .MustSignNewTx (key , types .LatestSignerForChainID (params .TestChainConfig .ChainID ), & types.SetCodeTx {
153
157
ChainID : uint256 .MustFromBig (params .TestChainConfig .ChainID ),
154
158
Nonce : nonce ,
@@ -2393,6 +2397,65 @@ func TestSetCodeTransactions(t *testing.T) {
2393
2397
}
2394
2398
}
2395
2399
2400
+ func TestSetCodeTransactionsReorg (t * testing.T ) {
2401
+ t .Parallel ()
2402
+
2403
+ // Create the pool to test the status retrievals with
2404
+ statedb , _ := state .New (types .EmptyRootHash , state .NewDatabaseForTesting ())
2405
+ blockchain := newTestBlockChain (params .MergedTestChainConfig , 1000000 , statedb , new (event.Feed ))
2406
+
2407
+ pool := New (testTxPoolConfig , blockchain )
2408
+ pool .Init (testTxPoolConfig .PriceLimit , blockchain .CurrentBlock (), makeAddressReserver ())
2409
+ defer pool .Close ()
2410
+
2411
+ // Create the test accounts
2412
+ var (
2413
+ keyA , _ = crypto .GenerateKey ()
2414
+ addrA = crypto .PubkeyToAddress (keyA .PublicKey )
2415
+ )
2416
+ testAddBalance (pool , addrA , big .NewInt (params .Ether ))
2417
+ // Send an authorization for 0x42
2418
+ var authList []types.SetCodeAuthorization
2419
+ auth , _ := types .SignSetCode (keyA , types.SetCodeAuthorization {
2420
+ ChainID : * uint256 .MustFromBig (params .TestChainConfig .ChainID ),
2421
+ Address : common.Address {0x42 },
2422
+ Nonce : 0 ,
2423
+ })
2424
+ authList = append (authList , auth )
2425
+ if err := pool .addRemoteSync (pricedSetCodeTxWithAuth (0 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keyA , authList )); err != nil {
2426
+ t .Fatalf ("failed to add with remote setcode transaction: %v" , err )
2427
+ }
2428
+ // Simulate the chain moving
2429
+ blockchain .statedb .SetNonce (addrA , 1 , tracing .NonceChangeAuthorization )
2430
+ blockchain .statedb .SetCode (addrA , types .AddressToDelegation (auth .Address ))
2431
+ <- pool .requestReset (nil , nil )
2432
+ // Set an authorization for 0x00
2433
+ auth , _ = types .SignSetCode (keyA , types.SetCodeAuthorization {
2434
+ ChainID : * uint256 .MustFromBig (params .TestChainConfig .ChainID ),
2435
+ Address : common.Address {},
2436
+ Nonce : 0 ,
2437
+ })
2438
+ authList = append (authList , auth )
2439
+ if err := pool .addRemoteSync (pricedSetCodeTxWithAuth (1 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keyA , authList )); err != nil {
2440
+ t .Fatalf ("failed to add with remote setcode transaction: %v" , err )
2441
+ }
2442
+ // Try to add a transactions in
2443
+ if err := pool .addRemoteSync (pricedTransaction (2 , 100000 , big .NewInt (1000 ), keyA )); ! errors .Is (err , txpool .ErrAccountLimitExceeded ) {
2444
+ t .Fatalf ("unexpected error %v, expecting %v" , err , txpool .ErrAccountLimitExceeded )
2445
+ }
2446
+ // Simulate the chain moving
2447
+ blockchain .statedb .SetNonce (addrA , 2 , tracing .NonceChangeAuthorization )
2448
+ blockchain .statedb .SetCode (addrA , nil )
2449
+ <- pool .requestReset (nil , nil )
2450
+ // Now send two transactions from addrA
2451
+ if err := pool .addRemoteSync (pricedTransaction (2 , 100000 , big .NewInt (1000 ), keyA )); err != nil {
2452
+ t .Fatalf ("failed to added single transaction: %v" , err )
2453
+ }
2454
+ if err := pool .addRemoteSync (pricedTransaction (3 , 100000 , big .NewInt (1000 ), keyA )); err != nil {
2455
+ t .Fatalf ("failed to added single transaction: %v" , err )
2456
+ }
2457
+ }
2458
+
2396
2459
// Benchmarks the speed of validating the contents of the pending queue of the
2397
2460
// transaction pool.
2398
2461
func BenchmarkPendingDemotion100 (b * testing.B ) { benchmarkPendingDemotion (b , 100 ) }
0 commit comments