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

Function TestTransactionPendingLimiting

core/tx_pool_test.go:920–956  ·  view source on GitHub ↗

Tests that even if the transaction count belonging to a single account goes above some threshold, as long as the transactions are executable, they are accepted.

(t *testing.T)

Source from the content-addressed store, hash-verified

918// above some threshold, as long as the transactions are executable, they are
919// accepted.
920func TestTransactionPendingLimiting(t *testing.T) {
921 t.Parallel()
922
923 // Create a test account and fund it
924 pool, key := setupTxPool()
925 defer pool.Stop()
926
927 account, _ := deriveSender(transaction(0, 0, key))
928 pool.currentState.AddBalance(account, big.NewInt(1000000))
929
930 // Keep track of transaction events to ensure all executables get announced
931 events := make(chan NewTxsEvent, testTxPoolConfig.AccountQueue+5)
932 sub := pool.txFeed.Subscribe(events)
933 defer sub.Unsubscribe()
934
935 // Keep queuing up transactions and make sure all above a limit are dropped
936 for i := uint64(0); i < testTxPoolConfig.AccountQueue+5; i++ {
937 if err := pool.AddRemote(transaction(i, 100000, key)); err != nil {
938 t.Fatalf("tx %d: failed to add transaction: %v", i, err)
939 }
940 if pool.pending[account].Len() != int(i)+1 {
941 t.Errorf("tx %d: pending pool size mismatch: have %d, want %d", i, pool.pending[account].Len(), i+1)
942 }
943 if len(pool.queue) != 0 {
944 t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, pool.queue[account].Len(), 0)
945 }
946 }
947 if pool.all.Count() != int(testTxPoolConfig.AccountQueue+5) {
948 t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue+5)
949 }
950 if err := validateEvents(events, int(testTxPoolConfig.AccountQueue+5)); err != nil {
951 t.Fatalf("event firing failed: %v", err)
952 }
953 if err := validateTxPoolInternals(pool); err != nil {
954 t.Fatalf("pool internal state corrupted: %v", err)
955 }
956}
957
958// Tests that the transaction limits are enforced the same way irrelevant whether
959// the transactions are added one by one or in batches.

Callers

nothing calls this directly

Calls 12

setupTxPoolFunction · 0.85
deriveSenderFunction · 0.85
transactionFunction · 0.85
validateEventsFunction · 0.85
validateTxPoolInternalsFunction · 0.85
AddRemoteMethod · 0.80
StopMethod · 0.65
AddBalanceMethod · 0.65
SubscribeMethod · 0.65
UnsubscribeMethod · 0.65
LenMethod · 0.65
CountMethod · 0.45

Tested by

no test coverage detected