@@ -38,9 +38,13 @@ import (
3838 "github.com/celo-org/celo-blockchain/params"
3939)
4040
41- // testTxPoolConfig is a transaction pool configuration without stateful disk
42- // sideeffects used during testing.
43- var testTxPoolConfig TxPoolConfig
41+ var (
42+ // testTxPoolConfig is a transaction pool configuration without stateful disk
43+ // sideeffects used during testing.
44+ testTxPoolConfig TxPoolConfig
45+ // eip155Signer to use for generating replay-protected transactions
46+ eip155Signer = types .NewEIP155Signer (params .TestChainConfig .ChainID )
47+ )
4448
4549func init () {
4650 testTxPoolConfig = DefaultTxPoolConfig
@@ -103,6 +107,11 @@ func pricedDataTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key
103107 return tx
104108}
105109
110+ func protectedTransaction (nonce uint64 , gaslimit uint64 , key * ecdsa.PrivateKey ) * types.Transaction {
111+ tx , _ := types .SignTx (types .NewTransaction (nonce , common.Address {}, big .NewInt (100 ), gaslimit , big .NewInt (1 ), nil , nil , nil , nil ), eip155Signer , key )
112+ return tx
113+ }
114+
106115func setupTxPool () (* TxPool , * ecdsa.PrivateKey ) {
107116 statedb , _ := state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
108117 blockchain := & testBlockChain {statedb , 10000000 , new (event.Feed )}
@@ -759,6 +768,54 @@ func TestTransactionGapFilling(t *testing.T) {
759768 }
760769}
761770
771+ // Tests that pool.handleDonutActivation() removes transactions without replay protection
772+ // When we change TestChangeConfig to enable Donut this test will need:
773+ // (a) to set pool.donut = false at its start (so we can add unprotected transactions)
774+ // (b) different functions to generate protected vs unprotected transactions, since we will
775+ // need to update transaction() and the others to use replay protection
776+ func TestHandleDonutActivation (t * testing.T ) {
777+ t .Parallel ()
778+
779+ // Create a test account and fund it
780+ pool , key := setupTxPool ()
781+ defer pool .Stop ()
782+
783+ account := crypto .PubkeyToAddress (key .PublicKey )
784+ pool .currentState .AddBalance (account , big .NewInt (1000000 ))
785+
786+ pool .AddRemotesSync ([]* types.Transaction {
787+ protectedTransaction (0 , 100000 , key ),
788+ transaction (1 , 100000 , key ),
789+ protectedTransaction (2 , 100000 , key ),
790+ transaction (7 , 100000 , key ),
791+ protectedTransaction (8 , 100000 , key ),
792+ transaction (9 , 100000 , key ),
793+ transaction (10 , 100000 , key ),
794+ })
795+
796+ pending , queued := pool .Stats ()
797+ if pending != 3 {
798+ t .Fatalf ("pending transactions mismatched: have %d, want %d" , pending , 3 )
799+ }
800+ if queued != 4 {
801+ t .Fatalf ("queued transactions mismatched: have %d, want %d" , queued , 4 )
802+ }
803+
804+ pool .handleDonutActivation ()
805+
806+ pending , queued = pool .Stats ()
807+ if pending != 1 {
808+ t .Fatalf ("pending transactions mismatched: have %d, want %d" , pending , 1 )
809+ }
810+ if queued != 2 {
811+ t .Fatalf ("queued transactions mismatched: have %d, want %d" , queued , 2 )
812+ }
813+
814+ if err := validateTxPoolInternals (pool ); err != nil {
815+ t .Fatalf ("pool internal state corrupted: %v" , err )
816+ }
817+ }
818+
762819// Tests that if the transaction count belonging to a single account goes above
763820// some threshold, the higher transactions are dropped to prevent DOS attacks.
764821func TestTransactionQueueAccountLimiting (t * testing.T ) {
0 commit comments