MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_FIXTURE_TEST_CASE

Function BOOST_FIXTURE_TEST_CASE

src/test/txindex_tests.cpp:16–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14BOOST_AUTO_TEST_SUITE(txindex_tests)
15
16BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
17{
18 TxIndex txindex(1 << 20, true);
19
20 CTransactionRef tx_disk;
21 uint256 block_hash;
22
23 // Transaction should not be found in the index before it is started.
24 for (const auto& txn : m_coinbase_txns) {
25 BOOST_CHECK(!txindex.FindTx(txn->GetHash(), block_hash, tx_disk));
26 }
27
28 // BlockUntilSyncedToCurrentChain should return false before txindex is started.
29 BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain());
30
31 BOOST_REQUIRE(txindex.Start(m_node.chainman->ActiveChainstate()));
32
33 // Allow tx index to catch up with the block index.
34 constexpr int64_t timeout_ms = 10 * 1000;
35 int64_t time_start = GetTimeMillis();
36 while (!txindex.BlockUntilSyncedToCurrentChain()) {
37 BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis());
38 UninterruptibleSleep(std::chrono::milliseconds{100});
39 }
40
41 // Check that txindex excludes genesis block transactions.
42 //ELEMENTS: we do include them
43 const CBlock& genesis_block = Params().GenesisBlock();
44 for (const auto& txn : genesis_block.vtx) {
45 BOOST_CHECK(txindex.FindTx(txn->GetHash(), block_hash, tx_disk));
46 }
47
48 // Check that txindex has all txs that were in the chain before it started.
49 for (const auto& txn : m_coinbase_txns) {
50 if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) {
51 BOOST_ERROR("FindTx failed");
52 } else if (tx_disk->GetHash() != txn->GetHash()) {
53 BOOST_ERROR("Read incorrect tx");
54 }
55 }
56
57 // Check that new transactions in new blocks make it into the index.
58 for (int i = 0; i < 10; i++) {
59 CScript coinbase_script_pub_key = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
60 std::vector<CMutableTransaction> no_txns;
61 const CBlock& block = CreateAndProcessBlock(no_txns, coinbase_script_pub_key);
62 const CTransaction& txn = *block.vtx[0];
63
64 BOOST_CHECK(txindex.BlockUntilSyncedToCurrentChain());
65 if (!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)) {
66 BOOST_ERROR("FindTx failed");
67 } else if (tx_disk->GetHash() != txn.GetHash()) {
68 BOOST_ERROR("Read incorrect tx");
69 }
70 }
71
72 // shutdown sequence (c.f. Shutdown() in init.cpp)
73 txindex.Stop();

Callers

nothing calls this directly

Calls 12

GetTimeMillisFunction · 0.85
UninterruptibleSleepFunction · 0.85
GetScriptForDestinationFunction · 0.85
PKHashClass · 0.85
FindTxMethod · 0.80
ParamsClass · 0.50
GetHashMethod · 0.45
StartMethod · 0.45
GetPubKeyMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected