@@ -320,34 +320,6 @@ func validateEvents(events chan core.NewTxsEvent, count int) error {
320320 return nil
321321}
322322
323- // validateQueuedEvents checks that the correct number of transaction addition events
324- // were fired on the pool's event feed.
325- func validateQueuedEvents (events chan core.NewQueuedTxsEvent , count int ) error {
326- var received []* types.Transaction
327-
328- for len (received ) < count {
329- select {
330- case ev := <- events :
331- received = append (received , ev .Txs ... )
332- case <- time .After (time .Second ):
333- return fmt .Errorf ("event #%d not fired" , len (received ))
334- }
335- }
336- if len (received ) > count {
337- return fmt .Errorf ("more than %d events fired: %v" , count , received [count :])
338- }
339- select {
340- case ev := <- events :
341- return fmt .Errorf ("more than %d events fired: %v" , count , ev .Txs )
342-
343- case <- time .After (50 * time .Millisecond ):
344- // This branch should be "default", but it's a data race between goroutines,
345- // reading the event channel and pushing into it, so better wait a bit ensuring
346- // really nothing gets injected.
347- }
348- return nil
349- }
350-
351323func deriveSender (tx * types.Transaction ) (common.Address , error ) {
352324 return types .Sender (types.HomesteadSigner {}, tx )
353325}
@@ -469,145 +441,6 @@ func TestInvalidTransactions(t *testing.T) {
469441 }
470442}
471443
472- func TestSubscribePendingAndQueuedTransactions (t * testing.T ) {
473- t .Parallel ()
474-
475- // Create the pool to test the pricing enforcement with
476- statedb , _ := state .New (types .EmptyRootHash , state .NewDatabaseForTesting ())
477- blockchain := newTestBlockChain (params .TestChainConfig , 1000000 , statedb , new (event.Feed ))
478-
479- pool := New (testTxPoolConfig , blockchain )
480- pool .Init (testTxPoolConfig .PriceLimit , blockchain .CurrentBlock (), newReserver ())
481- defer pool .Close ()
482-
483- // Keep listening for authenticated transactions.
484- events := make (chan core.NewQueuedTxsEvent , 32 )
485- sub := pool .SubscribeQueuedTransactions (events )
486- defer sub .Unsubscribe ()
487-
488- createAccounts := func (numbers int , txpool * LegacyPool ) []* ecdsa.PrivateKey {
489- keys := []* ecdsa.PrivateKey {}
490- for i := 0 ; i < numbers ; i ++ {
491- key , _ := crypto .GenerateKey ()
492- txpool .currentState .AddBalance (crypto .PubkeyToAddress (key .PublicKey ), uint256 .NewInt (1000000 ), tracing .BalanceChangeUnspecified )
493-
494- keys = append (keys , key )
495- }
496- return keys
497- }
498-
499- tests := []struct {
500- name string
501- setup func (txPool * LegacyPool )
502- validEvents int
503- }{
504- {
505- name : "valid transaction" ,
506- validEvents : 10 ,
507- setup : func (txPool * LegacyPool ) {
508- keys := createAccounts (4 , txPool )
509- txs := types.Transactions {}
510-
511- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (2 ), keys [0 ]))
512- txs = append (txs , pricedTransaction (1 , 100000 , big .NewInt (1 ), keys [0 ]))
513- txs = append (txs , pricedTransaction (2 , 100000 , big .NewInt (2 ), keys [0 ]))
514-
515- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [1 ]))
516- txs = append (txs , pricedTransaction (1 , 100000 , big .NewInt (2 ), keys [1 ]))
517- txs = append (txs , pricedTransaction (2 , 100000 , big .NewInt (2 ), keys [1 ]))
518-
519- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (2 ), keys [2 ]))
520- txs = append (txs , pricedTransaction (1 , 100000 , big .NewInt (1 ), keys [2 ]))
521- txs = append (txs , pricedTransaction (2 , 100000 , big .NewInt (2 ), keys [2 ]))
522-
523- ltx := pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [3 ])
524-
525- pool .addRemotes (txs )
526- pool .addRemoteSync (ltx )
527- },
528- },
529-
530- {
531- name : "duplicate transaction" ,
532- validEvents : 1 ,
533- setup : func (txPool * LegacyPool ) {
534- keys := createAccounts (1 , txPool )
535- txs := types.Transactions {}
536-
537- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [0 ]))
538- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [0 ]))
539-
540- pool .addRemotesSync (txs )
541- },
542- },
543- {
544- name : "bump gas price" ,
545- validEvents : 2 ,
546- setup : func (txPool * LegacyPool ) {
547- keys := createAccounts (1 , txPool )
548- txs := types.Transactions {}
549-
550- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [0 ]))
551- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (2 ), keys [0 ]))
552-
553- pool .addRemotesSync (txs )
554- },
555- },
556- {
557- name : "duplicate nonce with different gas price" ,
558- validEvents : 2 ,
559- setup : func (txPool * LegacyPool ) {
560- keys := createAccounts (1 , txPool )
561- txs := types.Transactions {}
562-
563- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [0 ]))
564- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (2 ), keys [0 ]))
565-
566- pool .addRemotesSync (txs )
567- },
568- },
569- {
570- name : "duplicate nonce with different gas limit" ,
571- validEvents : 2 ,
572- setup : func (txPool * LegacyPool ) {
573- keys := createAccounts (1 , txPool )
574- txs := types.Transactions {}
575-
576- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [0 ]))
577- txs = append (txs , pricedTransaction (0 , 80000 , big .NewInt (1 ), keys [0 ]))
578-
579- pool .addRemotesSync (txs )
580- },
581- },
582- {
583- name : "discontinuous nonce" ,
584- validEvents : 2 ,
585- setup : func (txPool * LegacyPool ) {
586- keys := createAccounts (1 , txPool )
587- txs := types.Transactions {}
588-
589- txs = append (txs , pricedTransaction (0 , 100000 , big .NewInt (1 ), keys [0 ]))
590- txs = append (txs , pricedTransaction (10000 , 80000 , big .NewInt (1 ), keys [0 ]))
591-
592- pool .addRemotesSync (txs )
593- },
594- },
595- }
596-
597- for _ , tt := range tests {
598- t .Run (tt .name , func (t * testing.T ) {
599- tt .setup (pool )
600-
601- if err := validateQueuedEvents (events , tt .validEvents ); err != nil {
602- t .Fatalf ("event firing failed: %v" , err )
603- }
604- if err := validatePoolInternals (pool ); err != nil {
605- t .Fatalf ("pool internal state corrupted: %v" , err )
606- }
607- })
608- }
609- }
610-
611444func TestQueue (t * testing.T ) {
612445 t .Parallel ()
613446
0 commit comments