Tests that if a transaction is dropped from the current pending pool (e.g. out of fund), all consecutive (still valid, but not executable) transactions are postponed back into the future queue to prevent broadcasting them.
(t *testing.T)
| 553 | // of fund), all consecutive (still valid, but not executable) transactions are |
| 554 | // postponed back into the future queue to prevent broadcasting them. |
| 555 | func TestTransactionPostponing(t *testing.T) { |
| 556 | t.Parallel() |
| 557 | |
| 558 | // Create the pool to test the postponing with |
| 559 | statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase())) |
| 560 | blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} |
| 561 | |
| 562 | pool := NewTxPool(testTxPoolConfig, configs.TestChainConfig, blockchain) |
| 563 | defer pool.Stop() |
| 564 | |
| 565 | // Create two test accounts to produce different gap profiles with |
| 566 | keys := make([]*ecdsa.PrivateKey, 2) |
| 567 | accs := make([]common.Address, len(keys)) |
| 568 | |
| 569 | for i := 0; i < len(keys); i++ { |
| 570 | keys[i], _ = crypto.GenerateKey() |
| 571 | accs[i] = crypto.PubkeyToAddress(keys[i].PublicKey) |
| 572 | |
| 573 | pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(50100)) |
| 574 | } |
| 575 | // Add a batch consecutive pending transactions for validation |
| 576 | txs := []*types.Transaction{} |
| 577 | for i, key := range keys { |
| 578 | |
| 579 | for j := 0; j < 100; j++ { |
| 580 | var tx *types.Transaction |
| 581 | if (i+j)%2 == 0 { |
| 582 | tx = transaction(uint64(j), 25000, key) |
| 583 | } else { |
| 584 | tx = transaction(uint64(j), 50000, key) |
| 585 | } |
| 586 | txs = append(txs, tx) |
| 587 | } |
| 588 | } |
| 589 | for i, err := range pool.AddRemotes(txs) { |
| 590 | if err != nil { |
| 591 | t.Fatalf("tx %d: failed to add transactions: %v", i, err) |
| 592 | } |
| 593 | } |
| 594 | // Check that pre and post validations leave the pool as is |
| 595 | if pending := pool.pending[accs[0]].Len() + pool.pending[accs[1]].Len(); pending != len(txs) { |
| 596 | t.Errorf("pending transaction mismatch: have %d, want %d", pending, len(txs)) |
| 597 | } |
| 598 | if len(pool.queue) != 0 { |
| 599 | t.Errorf("queued accounts mismatch: have %d, want %d", len(pool.queue), 0) |
| 600 | } |
| 601 | if pool.all.Count() != len(txs) { |
| 602 | t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), len(txs)) |
| 603 | } |
| 604 | pool.lockedReset(nil, nil) |
| 605 | if pending := pool.pending[accs[0]].Len() + pool.pending[accs[1]].Len(); pending != len(txs) { |
| 606 | t.Errorf("pending transaction mismatch: have %d, want %d", pending, len(txs)) |
| 607 | } |
| 608 | if len(pool.queue) != 0 { |
| 609 | t.Errorf("queued accounts mismatch: have %d, want %d", len(pool.queue), 0) |
| 610 | } |
| 611 | if pool.all.Count() != len(txs) { |
| 612 | t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), len(txs)) |
nothing calls this directly
no test coverage detected