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

Function testTransactionJournaling

core/tx_pool_test.go:1578–1684  ·  view source on GitHub ↗
(t *testing.T, nolocals bool)

Source from the content-addressed store, hash-verified

1576func TestTransactionJournalingNoLocals(t *testing.T) { testTransactionJournaling(t, true) }
1577
1578func testTransactionJournaling(t *testing.T, nolocals bool) {
1579 t.Parallel()
1580
1581 // Create a temporary file for the journal
1582 file, err := ioutil.TempFile("", "")
1583 if err != nil {
1584 t.Fatalf("failed to create temporary journal: %v", err)
1585 }
1586 journal := file.Name()
1587 defer os.Remove(journal)
1588
1589 // Clean up the temporary file, we only need the path for now
1590 file.Close()
1591 os.Remove(journal)
1592
1593 // Create the original pool to inject transaction into the journal
1594 statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase()))
1595 blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
1596
1597 config := testTxPoolConfig
1598 config.NoLocals = nolocals
1599 config.Journal = journal
1600 config.Rejournal = time.Second
1601
1602 pool := NewTxPool(config, configs.TestChainConfig, blockchain)
1603
1604 // Create two test accounts to ensure remotes expire but locals do not
1605 local, _ := crypto.GenerateKey()
1606 remote, _ := crypto.GenerateKey()
1607
1608 pool.currentState.AddBalance(crypto.PubkeyToAddress(local.PublicKey), big.NewInt(1000000000))
1609 pool.currentState.AddBalance(crypto.PubkeyToAddress(remote.PublicKey), big.NewInt(1000000000))
1610
1611 // Add three local and a remote transactions and ensure they are queued up
1612 if err := pool.AddLocal(pricedTransaction(0, 100000, big.NewInt(1), local)); err != nil {
1613 t.Fatalf("failed to add local transaction: %v", err)
1614 }
1615 if err := pool.AddLocal(pricedTransaction(1, 100000, big.NewInt(1), local)); err != nil {
1616 t.Fatalf("failed to add local transaction: %v", err)
1617 }
1618 if err := pool.AddLocal(pricedTransaction(2, 100000, big.NewInt(1), local)); err != nil {
1619 t.Fatalf("failed to add local transaction: %v", err)
1620 }
1621 if err := pool.AddRemote(pricedTransaction(0, 100000, big.NewInt(1), remote)); err != nil {
1622 t.Fatalf("failed to add remote transaction: %v", err)
1623 }
1624 pending, queued := pool.Stats()
1625 if pending != 4 {
1626 t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 4)
1627 }
1628 if queued != 0 {
1629 t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 0)
1630 }
1631 if err := validateTxPoolInternals(pool); err != nil {
1632 t.Fatalf("pool internal state corrupted: %v", err)
1633 }
1634 // Terminate the old pool, bump the local nonce, create a new pool and ensure relevant transaction survive
1635 pool.Stop()

Callers 2

Calls 14

AddLocalMethod · 0.95
AddRemoteMethod · 0.95
StatsMethod · 0.95
StopMethod · 0.95
lockedResetMethod · 0.95
NewTxPoolFunction · 0.85
pricedTransactionFunction · 0.85
validateTxPoolInternalsFunction · 0.85
SleepMethod · 0.80
CloseMethod · 0.65
AddBalanceMethod · 0.65
SetNonceMethod · 0.65

Tested by

no test coverage detected