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

Function TestTransactionQueue

core/tx_pool_test.go:264–316  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

262}
263
264func TestTransactionQueue(t *testing.T) {
265 t.Parallel()
266
267 pool, key := setupTxPool()
268 defer pool.Stop()
269
270 tx := transaction(0, 100, key)
271 from, _ := deriveSender(tx)
272 pool.currentState.AddBalance(from, big.NewInt(1000))
273 pool.lockedReset(nil, nil)
274 pool.enqueueTx(tx.Hash(), tx)
275
276 pool.promoteExecutables([]common.Address{from})
277 if len(pool.pending) != 1 {
278 t.Error("expected valid txs to be 1 is", len(pool.pending))
279 }
280
281 tx = transaction(1, 100, key)
282 from, _ = deriveSender(tx)
283 pool.currentState.SetNonce(from, 2)
284 pool.enqueueTx(tx.Hash(), tx)
285 pool.promoteExecutables([]common.Address{from})
286 if _, ok := pool.pending[from].txs.items[tx.Nonce()]; ok {
287 t.Error("expected transaction to be in tx pool")
288 }
289
290 if len(pool.queue) > 0 {
291 t.Error("expected transaction queue to be empty. is", len(pool.queue))
292 }
293
294 pool, key = setupTxPool()
295 defer pool.Stop()
296
297 tx1 := transaction(0, 100, key)
298 tx2 := transaction(10, 100, key)
299 tx3 := transaction(11, 100, key)
300 from, _ = deriveSender(tx1)
301 pool.currentState.AddBalance(from, big.NewInt(1000))
302 pool.lockedReset(nil, nil)
303
304 pool.enqueueTx(tx1.Hash(), tx1)
305 pool.enqueueTx(tx2.Hash(), tx2)
306 pool.enqueueTx(tx3.Hash(), tx3)
307
308 pool.promoteExecutables([]common.Address{from})
309
310 if len(pool.pending) != 1 {
311 t.Error("expected tx pool to be 1, got", len(pool.pending))
312 }
313 if pool.queue[from].Len() != 2 {
314 t.Error("expected len(queue) == 2, got", pool.queue[from].Len())
315 }
316}
317
318func TestTransactionNegativeValue(t *testing.T) {
319 t.Parallel()

Callers

nothing calls this directly

Calls 13

setupTxPoolFunction · 0.85
transactionFunction · 0.85
deriveSenderFunction · 0.85
lockedResetMethod · 0.80
enqueueTxMethod · 0.80
promoteExecutablesMethod · 0.80
StopMethod · 0.65
AddBalanceMethod · 0.65
HashMethod · 0.65
ErrorMethod · 0.65
SetNonceMethod · 0.65
NonceMethod · 0.65

Tested by

no test coverage detected