(t *testing.T, nolocals bool)
| 768 | } |
| 769 | |
| 770 | func 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) { |
no test coverage detected