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

Function testTransactionLimitingEquivalency

core/tx_pool_test.go:963–1007  ·  view source on GitHub ↗
(t *testing.T, origin uint64)

Source from the content-addressed store, hash-verified

961func TestTransactionPendingLimitingEquivalency(t *testing.T) { testTransactionLimitingEquivalency(t, 0) }
962
963func testTransactionLimitingEquivalency(t *testing.T, origin uint64) {
964 t.Parallel()
965
966 // Add a batch of transactions to a pool one by one
967 pool1, key1 := setupTxPool()
968 defer pool1.Stop()
969
970 account1, _ := deriveSender(transaction(0, 0, key1))
971 pool1.currentState.AddBalance(account1, big.NewInt(1000000))
972
973 for i := uint64(0); i < testTxPoolConfig.AccountQueue+5; i++ {
974 if err := pool1.AddRemote(transaction(origin+i, 100000, key1)); err != nil {
975 t.Fatalf("tx %d: failed to add transaction: %v", i, err)
976 }
977 }
978 // Add a batch of transactions to a pool in one big batch
979 pool2, key2 := setupTxPool()
980 defer pool2.Stop()
981
982 account2, _ := deriveSender(transaction(0, 0, key2))
983 pool2.currentState.AddBalance(account2, big.NewInt(1000000))
984
985 txs := []*types.Transaction{}
986 for i := uint64(0); i < testTxPoolConfig.AccountQueue+5; i++ {
987 txs = append(txs, transaction(origin+i, 100000, key2))
988 }
989 pool2.AddRemotes(txs)
990
991 // Ensure the batch optimization honors the same pool mechanics
992 if len(pool1.pending) != len(pool2.pending) {
993 t.Errorf("pending transaction count mismatch: one-by-one algo: %d, batch algo: %d", len(pool1.pending), len(pool2.pending))
994 }
995 if len(pool1.queue) != len(pool2.queue) {
996 t.Errorf("queued transaction count mismatch: one-by-one algo: %d, batch algo: %d", len(pool1.queue), len(pool2.queue))
997 }
998 if pool1.all.Count() != pool2.all.Count() {
999 t.Errorf("total transaction count mismatch: one-by-one algo %d, batch algo %d", pool1.all.Count(), pool2.all.Count())
1000 }
1001 if err := validateTxPoolInternals(pool1); err != nil {
1002 t.Errorf("pool 1 internal state corrupted: %v", err)
1003 }
1004 if err := validateTxPoolInternals(pool2); err != nil {
1005 t.Errorf("pool 2 internal state corrupted: %v", err)
1006 }
1007}
1008
1009// Tests that if the transaction count belonging to multiple accounts go above
1010// some hard threshold, the higher transactions are dropped to prevent DOS

Calls 9

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

Tested by

no test coverage detected