@@ -219,12 +219,17 @@ func (f *dummyFilter) FilterTx(ctx context.Context, tx *types.Transaction) bool
219219}
220220
221221func setupPoolWithConfig (config * params.ChainConfig ) (* LegacyPool , * ecdsa.PrivateKey ) {
222+ return setupPoolWithTxPoolConfig (config , testTxPoolConfig )
223+ }
224+
225+ // setupPoolWithTxPoolConfig creates a new pool with custom pool configuration
226+ func setupPoolWithTxPoolConfig (chainConfig * params.ChainConfig , poolConfig Config ) (* LegacyPool , * ecdsa.PrivateKey ) {
222227 statedb , _ := state .New (types .EmptyRootHash , state .NewDatabaseForTesting ())
223- blockchain := newTestBlockChain (config , 10000000 , statedb , new (event.Feed ))
228+ blockchain := newTestBlockChain (chainConfig , 10000000 , statedb , new (event.Feed ))
224229
225230 key , _ := crypto .GenerateKey ()
226- pool := New (testTxPoolConfig , blockchain )
227- if err := pool .Init (testTxPoolConfig .PriceLimit , blockchain .CurrentBlock (), newReserver ()); err != nil {
231+ pool := New (poolConfig , blockchain )
232+ if err := pool .Init (poolConfig .PriceLimit , blockchain .CurrentBlock (), newReserver ()); err != nil {
228233 panic (err )
229234 }
230235 // wait for the pool to initialize
@@ -2767,3 +2772,51 @@ func BenchmarkMultiAccountBatchInsert(b *testing.B) {
27672772 pool .addRemotesSync ([]* types.Transaction {tx })
27682773 }
27692774}
2775+
2776+ func TestTxPoolMaxTxGasLimit (t * testing.T ) {
2777+ t .Parallel ()
2778+
2779+ // Create custom config with MaxTxGasLimit set
2780+ config := testTxPoolConfig
2781+ config .MaxTxGasLimit = 50000
2782+
2783+ pool , key := setupPoolWithTxPoolConfig (params .TestChainConfig , config )
2784+ defer pool .Close ()
2785+
2786+ // Create transaction that exceeds the limit
2787+ tx := transaction (0 , 100000 , key ) // gas limit > 50000
2788+ from , _ := deriveSender (tx )
2789+ testAddBalance (pool , from , big .NewInt (1000000 ))
2790+
2791+ // Should be rejected
2792+ if err := pool .addRemoteSync (tx ); ! errors .Is (err , txpool .ErrTxGasLimitExceeded ) {
2793+ t .Errorf ("Expected ErrTxGasLimitExceeded, got %v" , err )
2794+ }
2795+
2796+ // Create transaction within the limit
2797+ tx2 := transaction (0 , 30000 , key ) // gas limit < 50000
2798+ if err := pool .addRemoteSync (tx2 ); err != nil {
2799+ t .Errorf ("Expected transaction within limit to be accepted, got %v" , err )
2800+ }
2801+ }
2802+
2803+ func TestTxPoolMaxTxGasLimitDisabled (t * testing.T ) {
2804+ t .Parallel ()
2805+
2806+ // Test with default config (MaxTxGasLimit = 0, disabled)
2807+ config := testTxPoolConfig
2808+ config .MaxTxGasLimit = 0
2809+
2810+ pool , key := setupPoolWithTxPoolConfig (params .TestChainConfig , config )
2811+ defer pool .Close ()
2812+
2813+ // Create transaction with high gas limit
2814+ tx := transaction (0 , 100000 , key )
2815+ from , _ := deriveSender (tx )
2816+ testAddBalance (pool , from , big .NewInt (1000000 ))
2817+
2818+ // Should be accepted since MaxTxGasLimit is disabled (0)
2819+ if err := pool .addRemoteSync (tx ); err != nil {
2820+ t .Errorf ("Expected transaction to be accepted when MaxTxGasLimit is disabled, got %v" , err )
2821+ }
2822+ }
0 commit comments