Skip to content

Commit

Permalink
add tests for tx_pool reannouce local pending transactions
Browse files Browse the repository at this point in the history
Signed-off-by: Keefe-Liu <[email protected]>
  • Loading branch information
keefel committed Nov 19, 2021
1 parent 440e41e commit be9f643
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,47 @@ func TestTransactionSlotCount(t *testing.T) {
}
}

// Tests the local pending transaction announced again correctly.
func TestTransactionPendingReannouce(t *testing.T) {
t.Parallel()

// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}

config := testTxPoolConfig
// This ReannounceTime will be modified to time.Minute when creating tx_pool.
config.ReannounceTime = time.Second
reannounceInterval = time.Second

pool := NewTxPool(config, params.TestChainConfig, blockchain)
// Modify ReannounceTime to trigger quicker.
pool.config.ReannounceTime = time.Second
defer pool.Stop()

key, _ := crypto.GenerateKey()
account := crypto.PubkeyToAddress(key.PublicKey)
pool.currentState.AddBalance(account, big.NewInt(1000000))

events := make(chan ReannoTxsEvent, testTxPoolConfig.AccountQueue)
sub := pool.reannoTxFeed.Subscribe(events)
defer sub.Unsubscribe()

// Generate a batch of transactions and add to tx_pool locally.
txs := make([]*types.Transaction, 0, testTxPoolConfig.AccountQueue)
for i := uint64(0); i < testTxPoolConfig.AccountQueue; i++ {
txs = append(txs, transaction(i, 100000, key))
}
pool.AddLocals(txs)

select {
case ev := <-events:
t.Logf("received reannouce event, txs length: %d", len(ev.Txs))
case <-time.After(5 * time.Second):
t.Errorf("reannouce event not fired")
}
}

// Benchmarks the speed of validating the contents of the pending queue of the
// transaction pool.
func BenchmarkPendingDemotion100(b *testing.B) { benchmarkPendingDemotion(b, 100) }
Expand Down

0 comments on commit be9f643

Please sign in to comment.