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

Function TestTransactionPendingMinimumAllowance

core/tx_pool_test.go:1092–1134  ·  view source on GitHub ↗

Tests that if the transaction count belonging to multiple accounts go above some hard threshold, if they are under the minimum guaranteed slot count then the transactions are still kept.

(t *testing.T)

Source from the content-addressed store, hash-verified

1090// some hard threshold, if they are under the minimum guaranteed slot count then
1091// the transactions are still kept.
1092func TestTransactionPendingMinimumAllowance(t *testing.T) {
1093 t.Parallel()
1094
1095 // Create the pool to test the limit enforcement with
1096 statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase()))
1097 blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
1098
1099 config := testTxPoolConfig
1100 // cf. https://github.com/ethereum/go-ethereum/pull/17210/files
1101 config.GlobalSlots = 1
1102
1103 pool := NewTxPool(config, configs.TestChainConfig, blockchain)
1104 defer pool.Stop()
1105
1106 // Create a number of test accounts and fund them
1107 keys := make([]*ecdsa.PrivateKey, 5)
1108 for i := 0; i < len(keys); i++ {
1109 keys[i], _ = crypto.GenerateKey()
1110 pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000))
1111 }
1112 // Generate and queue a batch of transactions
1113 nonces := make(map[common.Address]uint64)
1114
1115 txs := types.Transactions{}
1116 for _, key := range keys {
1117 addr := crypto.PubkeyToAddress(key.PublicKey)
1118 for j := 0; j < int(config.AccountSlots)*2; j++ {
1119 txs = append(txs, transaction(nonces[addr], 100000, key))
1120 nonces[addr]++
1121 }
1122 }
1123 // Import the batch and verify that limits have been enforced
1124 pool.AddRemotes(txs)
1125
1126 for addr, list := range pool.pending {
1127 if list.Len() != int(config.AccountSlots) {
1128 t.Errorf("addr %x: total pending transactions mismatch: have %d, want %d", addr, list.Len(), config.AccountSlots)
1129 }
1130 }
1131 if err := validateTxPoolInternals(pool); err != nil {
1132 t.Fatalf("pool internal state corrupted: %v", err)
1133 }
1134}
1135
1136// Tests that setting the transaction pool gas price to a higher value correctly
1137// discards everything cheaper than that and moves any gapped transactions back

Callers

nothing calls this directly

Calls 7

StopMethod · 0.95
AddRemotesMethod · 0.95
NewTxPoolFunction · 0.85
transactionFunction · 0.85
validateTxPoolInternalsFunction · 0.85
AddBalanceMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected