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

Function BOOST_FIXTURE_TEST_CASE

src/test/coinstatsindex_tests.cpp:19–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17BOOST_AUTO_TEST_SUITE(coinstatsindex_tests)
18
19BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
20{
21 CoinStatsIndex coin_stats_index{1 << 20, true};
22
23 CCoinsStats coin_stats{CoinStatsHashType::MUHASH};
24 const CBlockIndex* block_index;
25 {
26 LOCK(cs_main);
27 block_index = m_node.chainman->ActiveChain().Tip();
28 }
29
30 // CoinStatsIndex should not be found before it is started.
31 BOOST_CHECK(!coin_stats_index.LookUpStats(block_index, coin_stats));
32
33 // BlockUntilSyncedToCurrentChain should return false before CoinStatsIndex
34 // is started.
35 BOOST_CHECK(!coin_stats_index.BlockUntilSyncedToCurrentChain());
36
37 BOOST_REQUIRE(coin_stats_index.Start(m_node.chainman->ActiveChainstate()));
38
39 // Allow the CoinStatsIndex to catch up with the block index that is syncing
40 // in a background thread.
41 const auto timeout = GetTime<std::chrono::seconds>() + 120s;
42 while (!coin_stats_index.BlockUntilSyncedToCurrentChain()) {
43 BOOST_REQUIRE(timeout > GetTime<std::chrono::milliseconds>());
44 UninterruptibleSleep(100ms);
45 }
46
47 // Check that CoinStatsIndex works for genesis block.
48 const CBlockIndex* genesis_block_index;
49 {
50 LOCK(cs_main);
51 genesis_block_index = m_node.chainman->ActiveChain().Genesis();
52 }
53 BOOST_CHECK(coin_stats_index.LookUpStats(genesis_block_index, coin_stats));
54
55 // Check that CoinStatsIndex updates with new blocks.
56 coin_stats_index.LookUpStats(block_index, coin_stats);
57
58 const CScript script_pub_key{CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG};
59 std::vector<CMutableTransaction> noTxns;
60 CreateAndProcessBlock(noTxns, script_pub_key);
61
62 // Let the CoinStatsIndex to catch up again.
63 BOOST_CHECK(coin_stats_index.BlockUntilSyncedToCurrentChain());
64
65 CCoinsStats new_coin_stats{CoinStatsHashType::MUHASH};
66 const CBlockIndex* new_block_index;
67 {
68 LOCK(cs_main);
69 new_block_index = m_node.chainman->ActiveChain().Tip();
70 }
71 coin_stats_index.LookUpStats(new_block_index, new_coin_stats);
72
73 BOOST_CHECK(block_index != new_block_index);
74
75 // Shutdown sequence (c.f. Shutdown() in init.cpp)
76 coin_stats_index.Stop();

Callers

nothing calls this directly

Calls 10

UninterruptibleSleepFunction · 0.85
ToByteVectorFunction · 0.85
LookUpStatsMethod · 0.80
GenesisMethod · 0.80
CScriptClass · 0.50
TipMethod · 0.45
StartMethod · 0.45
GetPubKeyMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected