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

Function TestTransactionStatusCheck

core/tx_pool_test.go:1688–1740  ·  view source on GitHub ↗

TestTransactionStatusCheck tests that the pool can correctly retrieve the pending status of individual transactions.

(t *testing.T)

Source from the content-addressed store, hash-verified

1686// TestTransactionStatusCheck tests that the pool can correctly retrieve the
1687// pending status of individual transactions.
1688func TestTransactionStatusCheck(t *testing.T) {
1689 t.Parallel()
1690
1691 // Create the pool to test the status retrievals with
1692 statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase()))
1693 blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
1694
1695 pool := NewTxPool(testTxPoolConfig, configs.TestChainConfig, blockchain)
1696 defer pool.Stop()
1697
1698 // Create the test accounts to check various transaction statuses with
1699 keys := make([]*ecdsa.PrivateKey, 3)
1700 for i := 0; i < len(keys); i++ {
1701 keys[i], _ = crypto.GenerateKey()
1702 pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000))
1703 }
1704 // Generate and queue a batch of transactions, both pending and queued
1705 txs := types.Transactions{}
1706
1707 txs = append(txs, pricedTransaction(0, 100000, big.NewInt(1), keys[0])) // Pending only
1708 txs = append(txs, pricedTransaction(0, 100000, big.NewInt(1), keys[1])) // Pending and queued
1709 txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[1]))
1710 txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only
1711
1712 // Import the transaction and ensure they are correctly added
1713 pool.AddRemotes(txs)
1714
1715 pending, queued := pool.Stats()
1716 if pending != 2 {
1717 t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 2)
1718 }
1719 if queued != 2 {
1720 t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 2)
1721 }
1722 if err := validateTxPoolInternals(pool); err != nil {
1723 t.Fatalf("pool internal state corrupted: %v", err)
1724 }
1725 // Retrieve the status of each transaction and validate them
1726 hashes := make([]common.Hash, len(txs))
1727 for i, tx := range txs {
1728 hashes[i] = tx.Hash()
1729 }
1730 hashes = append(hashes, common.Hash{})
1731
1732 statuses := pool.Status(hashes)
1733 expect := []TxStatus{TxStatusPending, TxStatusPending, TxStatusQueued, TxStatusQueued, TxStatusUnknown}
1734
1735 for i := 0; i < len(statuses); i++ {
1736 if statuses[i] != expect[i] {
1737 t.Errorf("transaction %d: status mismatch: have %v, want %v", i, statuses[i], expect[i])
1738 }
1739 }
1740}
1741
1742// Benchmarks the speed of validating the contents of the pending queue of the
1743// transaction pool.

Callers

nothing calls this directly

Calls 9

StopMethod · 0.95
AddRemotesMethod · 0.95
StatsMethod · 0.95
StatusMethod · 0.95
NewTxPoolFunction · 0.85
pricedTransactionFunction · 0.85
validateTxPoolInternalsFunction · 0.85
AddBalanceMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected