Tests that setting the transaction pool gas price to a higher value correctly discards everything cheaper than that and moves any gapped transactions back from the pending pool to the queue. Note, local transactions are never allowed to be dropped.
(t *testing.T)
| 1139 | // |
| 1140 | // Note, local transactions are never allowed to be dropped. |
| 1141 | func TestTransactionPoolRepricing(t *testing.T) { |
| 1142 | t.Parallel() |
| 1143 | |
| 1144 | // Create the pool to test the pricing enforcement with |
| 1145 | statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase())) |
| 1146 | blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} |
| 1147 | |
| 1148 | pool := NewTxPool(testTxPoolConfig, configs.TestChainConfig, blockchain) |
| 1149 | defer pool.Stop() |
| 1150 | |
| 1151 | // Keep track of transaction events to ensure all executables get announced |
| 1152 | events := make(chan NewTxsEvent, 32) |
| 1153 | sub := pool.txFeed.Subscribe(events) |
| 1154 | defer sub.Unsubscribe() |
| 1155 | |
| 1156 | // Create a number of test accounts and fund them |
| 1157 | keys := make([]*ecdsa.PrivateKey, 4) |
| 1158 | for i := 0; i < len(keys); i++ { |
| 1159 | keys[i], _ = crypto.GenerateKey() |
| 1160 | pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000)) |
| 1161 | } |
| 1162 | // Generate and queue a batch of transactions, both pending and queued |
| 1163 | txs := types.Transactions{} |
| 1164 | |
| 1165 | txs = append(txs, pricedTransaction(0, 100000, big.NewInt(2), keys[0])) |
| 1166 | txs = append(txs, pricedTransaction(1, 100000, big.NewInt(1), keys[0])) |
| 1167 | txs = append(txs, pricedTransaction(2, 100000, big.NewInt(2), keys[0])) |
| 1168 | |
| 1169 | txs = append(txs, pricedTransaction(0, 100000, big.NewInt(1), keys[1])) |
| 1170 | txs = append(txs, pricedTransaction(1, 100000, big.NewInt(2), keys[1])) |
| 1171 | txs = append(txs, pricedTransaction(2, 100000, big.NewInt(2), keys[1])) |
| 1172 | |
| 1173 | txs = append(txs, pricedTransaction(1, 100000, big.NewInt(2), keys[2])) |
| 1174 | txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) |
| 1175 | txs = append(txs, pricedTransaction(3, 100000, big.NewInt(2), keys[2])) |
| 1176 | |
| 1177 | ltx := pricedTransaction(0, 100000, big.NewInt(1), keys[3]) |
| 1178 | |
| 1179 | // Import the batch and that both pending and queued transactions match up |
| 1180 | pool.AddRemotes(txs) |
| 1181 | pool.AddLocal(ltx) |
| 1182 | |
| 1183 | pending, queued := pool.Stats() |
| 1184 | if pending != 7 { |
| 1185 | t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 7) |
| 1186 | } |
| 1187 | if queued != 3 { |
| 1188 | t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 3) |
| 1189 | } |
| 1190 | if err := validateEvents(events, 7); err != nil { |
| 1191 | t.Fatalf("original event firing failed: %v", err) |
| 1192 | } |
| 1193 | if err := validateTxPoolInternals(pool); err != nil { |
| 1194 | t.Fatalf("pool internal state corrupted: %v", err) |
| 1195 | } |
| 1196 | // Reprice the pool and check that underpriced transactions get dropped |
| 1197 | pool.SetGasPrice(big.NewInt(2)) |
| 1198 |
nothing calls this directly
no test coverage detected