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

Function testTransactionQueueGlobalLimiting

core/tx_pool_test.go:770–845  ·  view source on GitHub ↗
(t *testing.T, nolocals bool)

Source from the content-addressed store, hash-verified

768}
769
770func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
771 t.Parallel()
772
773 // Create the pool to test the limit enforcement with
774 statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase()))
775 blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
776
777 config := testTxPoolConfig
778 config.NoLocals = nolocals
779 config.GlobalQueue = config.AccountQueue*3 - 1 // reduce the queue limits to shorten test time (-1 to make it non divisible)
780
781 pool := NewTxPool(config, configs.TestChainConfig, blockchain)
782 defer pool.Stop()
783
784 // Create a number of test accounts and fund them (last one will be the local)
785 keys := make([]*ecdsa.PrivateKey, 5)
786 for i := 0; i < len(keys); i++ {
787 keys[i], _ = crypto.GenerateKey()
788 pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000))
789 }
790 local := keys[len(keys)-1]
791
792 // Generate and queue a batch of transactions
793 nonces := make(map[common.Address]uint64)
794
795 txs := make(types.Transactions, 0, 3*config.GlobalQueue)
796 for len(txs) < cap(txs) {
797 key := keys[rand.Intn(len(keys)-1)] // skip adding transactions with the local account
798 addr := crypto.PubkeyToAddress(key.PublicKey)
799
800 txs = append(txs, transaction(nonces[addr]+1, 100000, key))
801 nonces[addr]++
802 }
803 // Import the batch and verify that limits have been enforced
804 pool.AddRemotes(txs)
805
806 queued := 0
807 for addr, list := range pool.queue {
808 if list.Len() > int(config.AccountQueue) {
809 t.Errorf("addr %x: queued accounts overflown allowance: %d > %d", addr, list.Len(), config.AccountQueue)
810 }
811 queued += list.Len()
812 }
813 if queued > int(config.GlobalQueue) {
814 t.Fatalf("total transactions overflow allowance: %d > %d", queued, config.GlobalQueue)
815 }
816 // Generate a batch of transactions from the local account and import them
817 txs = txs[:0]
818 for i := uint64(0); i < 3*config.GlobalQueue; i++ {
819 txs = append(txs, transaction(i+1, 100000, local))
820 }
821 pool.AddLocals(txs)
822
823 // If locals are disabled, the previous eviction algorithm should apply here too
824 if nolocals {
825 queued := 0
826 for addr, list := range pool.queue {
827 if list.Len() > int(config.AccountQueue) {

Calls 7

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

Tested by

no test coverage detected