MCPcopy Create free account
hub / github.com/CPChain/chain / TestTransactionQueueAccountLimiting

Function TestTransactionQueueAccountLimiting

core/tx_pool_test.go:725–756  ·  view source on GitHub ↗

Tests that if the transaction count belonging to a single account goes above some threshold, the higher transactions are dropped to prevent DOS attacks.

(t *testing.T)

Source from the content-addressed store, hash-verified

723// Tests that if the transaction count belonging to a single account goes above
724// some threshold, the higher transactions are dropped to prevent DOS attacks.
725func TestTransactionQueueAccountLimiting(t *testing.T) {
726 t.Parallel()
727
728 // Create a test account and fund it
729 pool, key := setupTxPool()
730 defer pool.Stop()
731
732 account, _ := deriveSender(transaction(0, 0, key))
733 pool.currentState.AddBalance(account, big.NewInt(1000000))
734
735 // Keep queuing up transactions and make sure all above a limit are dropped
736 for i := uint64(1); i <= testTxPoolConfig.AccountQueue+5; i++ {
737 if err := pool.AddRemote(transaction(i, 100000, key)); err != nil {
738 t.Fatalf("tx %d: failed to add transaction: %v", i, err)
739 }
740 if len(pool.pending) != 0 {
741 t.Errorf("tx %d: pending pool size mismatch: have %d, want %d", i, len(pool.pending), 0)
742 }
743 if i <= testTxPoolConfig.AccountQueue {
744 if pool.queue[account].Len() != int(i) {
745 t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, pool.queue[account].Len(), i)
746 }
747 } else {
748 if pool.queue[account].Len() != int(testTxPoolConfig.AccountQueue) {
749 t.Errorf("tx %d: queue limit mismatch: have %d, want %d", i, pool.queue[account].Len(), testTxPoolConfig.AccountQueue)
750 }
751 }
752 }
753 if pool.all.Count() != int(testTxPoolConfig.AccountQueue) {
754 t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue)
755 }
756}
757
758// Tests that if the transaction count belonging to multiple accounts go above
759// some threshold, the higher transactions are dropped to prevent DOS attacks.

Callers

nothing calls this directly

Calls 8

setupTxPoolFunction · 0.85
deriveSenderFunction · 0.85
transactionFunction · 0.85
AddRemoteMethod · 0.80
StopMethod · 0.65
AddBalanceMethod · 0.65
LenMethod · 0.65
CountMethod · 0.45

Tested by

no test coverage detected