(t *testing.T, nolocals bool)
| 854 | func TestTransactionQueueTimeLimitingNoLocals(t *testing.T) { testTransactionQueueTimeLimiting(t, true) } |
| 855 | |
| 856 | func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) { |
| 857 | // Reduce the eviction interval to a testable amount |
| 858 | defer func(old time.Duration) { evictionInterval = old }(evictionInterval) |
| 859 | evictionInterval = time.Second |
| 860 | |
| 861 | // Create the pool to test the non-expiration enforcement |
| 862 | statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase())) |
| 863 | blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} |
| 864 | |
| 865 | config := testTxPoolConfig |
| 866 | config.Lifetime = time.Second |
| 867 | config.NoLocals = nolocals |
| 868 | |
| 869 | pool := NewTxPool(config, configs.TestChainConfig, blockchain) |
| 870 | defer pool.Stop() |
| 871 | |
| 872 | // Create two test accounts to ensure remotes expire but locals do not |
| 873 | local, _ := crypto.GenerateKey() |
| 874 | remote, _ := crypto.GenerateKey() |
| 875 | |
| 876 | pool.currentState.AddBalance(crypto.PubkeyToAddress(local.PublicKey), big.NewInt(1000000000)) |
| 877 | pool.currentState.AddBalance(crypto.PubkeyToAddress(remote.PublicKey), big.NewInt(1000000000)) |
| 878 | |
| 879 | // Add the two transactions and ensure they both are queued up |
| 880 | if err := pool.AddLocal(pricedTransaction(1, 100000, big.NewInt(1), local)); err != nil { |
| 881 | t.Fatalf("failed to add local transaction: %v", err) |
| 882 | } |
| 883 | if err := pool.AddRemote(pricedTransaction(1, 100000, big.NewInt(1), remote)); err != nil { |
| 884 | t.Fatalf("failed to add remote transaction: %v", err) |
| 885 | } |
| 886 | pending, queued := pool.Stats() |
| 887 | if pending != 0 { |
| 888 | t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 0) |
| 889 | } |
| 890 | if queued != 2 { |
| 891 | t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 2) |
| 892 | } |
| 893 | if err := validateTxPoolInternals(pool); err != nil { |
| 894 | t.Fatalf("pool internal state corrupted: %v", err) |
| 895 | } |
| 896 | // Wait a bit for eviction to run and clean up any leftovers, and ensure only the local remains |
| 897 | time.Sleep(2 * config.Lifetime) |
| 898 | |
| 899 | pending, queued = pool.Stats() |
| 900 | if pending != 0 { |
| 901 | t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 0) |
| 902 | } |
| 903 | if nolocals { |
| 904 | if queued != 0 { |
| 905 | t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 0) |
| 906 | } |
| 907 | } else { |
| 908 | if queued != 1 { |
| 909 | t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 1) |
| 910 | } |
| 911 | } |
| 912 | if err := validateTxPoolInternals(pool); err != nil { |
| 913 | t.Fatalf("pool internal state corrupted: %v", err) |
no test coverage detected