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

Function TestTransactionPoolRepricing

core/tx_pool_test.go:1141–1258  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1139//
1140// Note, local transactions are never allowed to be dropped.
1141func 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

Callers

nothing calls this directly

Calls 13

StopMethod · 0.95
AddRemotesMethod · 0.95
AddLocalMethod · 0.95
StatsMethod · 0.95
SetGasPriceMethod · 0.95
AddRemoteMethod · 0.95
NewTxPoolFunction · 0.85
pricedTransactionFunction · 0.85
validateEventsFunction · 0.85
validateTxPoolInternalsFunction · 0.85
SubscribeMethod · 0.65
UnsubscribeMethod · 0.65

Tested by

no test coverage detected