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

Function TestTransactionPoolRepricingKeepsLocals

core/tx_pool_test.go:1262–1317  ·  view source on GitHub ↗

Tests that setting the transaction pool gas price to a higher value does not remove local transactions.

(t *testing.T)

Source from the content-addressed store, hash-verified

1260// Tests that setting the transaction pool gas price to a higher value does not
1261// remove local transactions.
1262func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {
1263 t.Parallel()
1264
1265 // Create the pool to test the pricing enforcement with
1266 statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase()))
1267 blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
1268
1269 pool := NewTxPool(testTxPoolConfig, configs.TestChainConfig, blockchain)
1270 defer pool.Stop()
1271
1272 // Create a number of test accounts and fund them
1273 keys := make([]*ecdsa.PrivateKey, 3)
1274 for i := 0; i < len(keys); i++ {
1275 keys[i], _ = crypto.GenerateKey()
1276 pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000*1000000))
1277 }
1278 // Create transaction (both pending and queued) with a linearly growing gasprice
1279 for i := uint64(0); i < 500; i++ {
1280 // Add pending
1281 p_tx := pricedTransaction(i, 100000, big.NewInt(int64(i)), keys[2])
1282 if err := pool.AddLocal(p_tx); err != nil {
1283 t.Fatal(err)
1284 }
1285 // Add queued
1286 q_tx := pricedTransaction(i+501, 100000, big.NewInt(int64(i)), keys[2])
1287 if err := pool.AddLocal(q_tx); err != nil {
1288 t.Fatal(err)
1289 }
1290 }
1291 pending, queued := pool.Stats()
1292 expPending, expQueued := 500, 500
1293 validate := func() {
1294 pending, queued = pool.Stats()
1295 if pending != expPending {
1296 t.Fatalf("pending transactions mismatched: have %d, want %d", pending, expPending)
1297 }
1298 if queued != expQueued {
1299 t.Fatalf("queued transactions mismatched: have %d, want %d", queued, expQueued)
1300 }
1301
1302 if err := validateTxPoolInternals(pool); err != nil {
1303 t.Fatalf("pool internal state corrupted: %v", err)
1304 }
1305 }
1306 validate()
1307
1308 // Reprice the pool and check that nothing is dropped
1309 pool.SetGasPrice(big.NewInt(2))
1310 validate()
1311
1312 pool.SetGasPrice(big.NewInt(2))
1313 pool.SetGasPrice(big.NewInt(4))
1314 pool.SetGasPrice(big.NewInt(8))
1315 pool.SetGasPrice(big.NewInt(100))
1316 validate()
1317}
1318
1319// Tests that when the pool reaches its global transaction limit, underpriced

Callers

nothing calls this directly

Calls 10

StopMethod · 0.95
AddLocalMethod · 0.95
StatsMethod · 0.95
SetGasPriceMethod · 0.95
NewTxPoolFunction · 0.85
pricedTransactionFunction · 0.85
validateTxPoolInternalsFunction · 0.85
validateFunction · 0.85
AddBalanceMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected