Tests that if an account runs out of funds, any pending and queued transactions are dropped.
(t *testing.T)
| 458 | // Tests that if an account runs out of funds, any pending and queued transactions |
| 459 | // are dropped. |
| 460 | func TestTransactionDropping(t *testing.T) { |
| 461 | t.Parallel() |
| 462 | |
| 463 | // Create a test account and fund it |
| 464 | pool, key := setupTxPool() |
| 465 | defer pool.Stop() |
| 466 | |
| 467 | account, _ := deriveSender(transaction(0, 0, key)) |
| 468 | pool.currentState.AddBalance(account, big.NewInt(1000)) |
| 469 | |
| 470 | // Add some pending and some queued transactions |
| 471 | var ( |
| 472 | tx0 = transaction(0, 100, key) |
| 473 | tx1 = transaction(1, 200, key) |
| 474 | tx2 = transaction(2, 300, key) |
| 475 | tx10 = transaction(10, 100, key) |
| 476 | tx11 = transaction(11, 200, key) |
| 477 | tx12 = transaction(12, 300, key) |
| 478 | ) |
| 479 | pool.promoteTx(account, tx0.Hash(), tx0) |
| 480 | pool.promoteTx(account, tx1.Hash(), tx1) |
| 481 | pool.promoteTx(account, tx2.Hash(), tx2) |
| 482 | pool.enqueueTx(tx10.Hash(), tx10) |
| 483 | pool.enqueueTx(tx11.Hash(), tx11) |
| 484 | pool.enqueueTx(tx12.Hash(), tx12) |
| 485 | |
| 486 | // Check that pre and post validations leave the pool as is |
| 487 | if pool.pending[account].Len() != 3 { |
| 488 | t.Errorf("pending transaction mismatch: have %d, want %d", pool.pending[account].Len(), 3) |
| 489 | } |
| 490 | if pool.queue[account].Len() != 3 { |
| 491 | t.Errorf("queued transaction mismatch: have %d, want %d", pool.queue[account].Len(), 3) |
| 492 | } |
| 493 | if pool.all.Count() != 6 { |
| 494 | t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), 6) |
| 495 | } |
| 496 | pool.lockedReset(nil, nil) |
| 497 | if pool.pending[account].Len() != 3 { |
| 498 | t.Errorf("pending transaction mismatch: have %d, want %d", pool.pending[account].Len(), 3) |
| 499 | } |
| 500 | if pool.queue[account].Len() != 3 { |
| 501 | t.Errorf("queued transaction mismatch: have %d, want %d", pool.queue[account].Len(), 3) |
| 502 | } |
| 503 | if pool.all.Count() != 6 { |
| 504 | t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), 6) |
| 505 | } |
| 506 | // Reduce the balance of the account, and check that invalidated transactions are dropped |
| 507 | pool.currentState.AddBalance(account, big.NewInt(-650)) |
| 508 | pool.lockedReset(nil, nil) |
| 509 | |
| 510 | if _, ok := pool.pending[account].txs.items[tx0.Nonce()]; !ok { |
| 511 | t.Errorf("funded pending transaction missing: %v", tx0) |
| 512 | } |
| 513 | if _, ok := pool.pending[account].txs.items[tx1.Nonce()]; !ok { |
| 514 | t.Errorf("funded pending transaction missing: %v", tx0) |
| 515 | } |
| 516 | if _, ok := pool.pending[account].txs.items[tx2.Nonce()]; ok { |
| 517 | t.Errorf("out-of-fund pending transaction present: %v", tx1) |
nothing calls this directly
no test coverage detected