Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
coinstatsindex_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <chain.h>
7#include <interfaces/chain.h>
8#include <kernel/coinstats.h>
9#include <key.h>
10#include <primitives/block.h>
12#include <script/script.h>
13#include <sync.h>
16#include <util/check.h>
17#include <validation.h>
18
19#include <boost/test/unit_test.hpp>
20
21#include <memory>
22#include <optional>
23#include <span>
24#include <vector>
25
27
29{
32
34 {
36 block_index = m_node.chainman->ActiveChain().Tip();
37 }
38
39 // CoinStatsIndex should not be found before it is started.
41
42 // BlockUntilSyncedToCurrentChain should return false before CoinStatsIndex
43 // is started.
44 BOOST_CHECK(!coin_stats_index.BlockUntilSyncedToCurrentChain());
45
46 coin_stats_index.Sync();
47
48 // Check that CoinStatsIndex works for genesis block.
50 {
52 genesis_block_index = m_node.chainman->ActiveChain().Genesis();
53 }
55
56 // Check that CoinStatsIndex updates with new blocks.
58
59 const CScript script_pub_key{CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG};
60 std::vector<CMutableTransaction> noTxns;
61 CreateAndProcessBlock(noTxns, script_pub_key);
62
63 // Let the CoinStatsIndex to catch up again.
64 BOOST_CHECK(coin_stats_index.BlockUntilSyncedToCurrentChain());
65
67 {
69 new_block_index = m_node.chainman->ActiveChain().Tip();
70 }
72
74
76}
77
node::NodeContext m_node
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition chain.h:94
Serialized script, used inside transaction inputs and outputs.
Definition script.h:406
CoinStatsIndex maintains statistics on the UTXO set.
BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
BOOST_AUTO_TEST_SUITE_END()
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
#define BOOST_CHECK(expr)
Definition object.cpp:16
@ OP_CHECKSIG
Definition script.h:191
std::vector< unsigned char > ToByteVector(const T &in)
Definition script.h:68
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
std::unique_ptr< ChainstateManager > chainman
Definition context.h:74
#define LOCK(cs)
Definition sync.h:268
void StopIndex(BaseIndex &index, node::NodeContext &node)
Drain validation callbacks before stopping an index, matching Shutdown() in init.cpp.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82