Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
node_init_tests.cpp
Go to the documentation of this file.
1
// Copyright (c) 2025-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 <chainparams.h>
6
#include <
init.h
>
7
#include <
interfaces/init.h
>
8
#include <
kernel/mempool_entry.h
>
9
#include <logging.h>
10
#include <
node/context.h
>
11
#include <
policy/fees/estimator_args.h
>
12
#include <
primitives/block.h
>
13
#include <
rpc/server.h
>
14
#include <
scheduler.h
>
15
#include <
streams.h
>
16
#include <
util/fs.h
>
17
#include <
validationinterface.h
>
18
19
#include <boost/test/unit_test.hpp>
20
#include <
test/util/common.h
>
21
#include <
test/util/setup_common.h
>
22
23
#include <memory>
24
25
using
node::NodeContext
;
26
28
struct
InitTestSetup
:
BasicTestingSetup
{
29
InitTestSetup
() :
BasicTestingSetup
{
ChainType
::REGTEST} {}
30
};
31
32
BOOST_FIXTURE_TEST_SUITE
(node_init_tests,
InitTestSetup
)
33
34
35
class
TestInit
:
public
interfaces::Init
36
{
37
public
:
38
TestInit
(
NodeContext
&
node
) :
m_node
(
node
)
39
{
40
InitContext
(
m_node
);
41
m_node
.
init
=
this
;
42
}
43
std::unique_ptr<interfaces::Chain>
makeChain
()
override
{
return
interfaces::MakeChain
(
m_node
); }
44
std::unique_ptr<interfaces::WalletLoader>
makeWalletLoader
(
interfaces::Chain
& chain)
override
45
{
46
return
MakeWalletLoader(chain, *
Assert
(
m_node
.
args
));
47
}
48
NodeContext
&
m_node
;
49
};
50
51
BOOST_AUTO_TEST_CASE
(init_test)
52
{
53
// Clear state set by BasicTestingSetup that AppInitMain assumes is unset.
54
LogInstance
().
DisconnectTestLogger
();
55
m_node.args->SetConfigFilePath({});
56
57
// Prevent the test from trying to listen on ports 8332 and 8333.
58
m_node.args->ForceSetArg(
"-server"
,
"0"
);
59
m_node.args->ForceSetArg(
"-listen"
,
"0"
);
60
61
// Run through initialization and shutdown code.
62
TestInit
init
{m_node};
63
BOOST_CHECK
(
AppInitInterfaces
(m_node));
64
BOOST_CHECK
(
AppInitMain
(m_node));
65
Interrupt
(m_node);
66
67
// Model a block update left queued after the scheduler stops during shutdown
68
m_node.scheduler->stop();
69
constexpr
unsigned
int
queued_height{123};
70
m_node.validation_signals->MempoolTransactionsRemovedForBlock(std::make_shared<CBlock>(
Params
().GenesisBlock()), {}, queued_height);
71
BOOST_REQUIRE_GT(m_node.validation_signals->CallbacksPending(), 0);
72
73
Shutdown
(m_node);
74
75
AutoFile
estimates_file{
fsbridge::fopen
(
BlockPolicyFeeEstPath
(*m_node.args),
"rb"
)};
76
int
version;
77
unsigned
int
best_seen_height;
78
estimates_file >> version >> best_seen_height;
79
BOOST_CHECK_EQUAL
(best_seen_height, queued_height);
80
}
81
82
BOOST_AUTO_TEST_SUITE_END
()
Interrupt
Interrupt(node)
Shutdown
Shutdown(node)
block.h
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition
chainparams.cpp:128
ChainType
ChainType
Definition
chaintype.h:12
Assert
#define Assert(val)
Identity function.
Definition
check.h:116
AutoFile
Non-refcounted RAII wrapper for FILE*.
Definition
streams.h:395
BCLog::Logger::DisconnectTestLogger
void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Only for testing.
Definition
logging.cpp:103
TestInit
Remote init class.
Definition
ipc_tests.cpp:36
TestInit::TestInit
TestInit(NodeContext &node)
Definition
node_init_tests.cpp:38
TestInit::m_node
NodeContext & m_node
Definition
node_init_tests.cpp:48
TestInit::makeWalletLoader
std::unique_ptr< interfaces::WalletLoader > makeWalletLoader(interfaces::Chain &chain) override
Definition
node_init_tests.cpp:44
TestInit::makeChain
std::unique_ptr< interfaces::Chain > makeChain() override
Definition
node_init_tests.cpp:43
interfaces::Chain
Definition
chain.h:117
interfaces::Init
Definition
init.h:39
BOOST_FIXTURE_TEST_SUITE
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BlockPolicyFeeEstPath
fs::path BlockPolicyFeeEstPath(const ArgsManager &argsman)
Definition
estimator_args.cpp:52
estimator_args.h
fs.h
AppInitInterfaces
bool AppInitInterfaces(NodeContext &node)
Initialize node and wallet interface pointers.
Definition
init.cpp:1279
AppInitMain
bool AppInitMain(NodeContext &node, interfaces::BlockAndHeaderTipInfo *tip_info)
Bitcoin core main initialization.
Definition
init.cpp:1496
InitContext
void InitContext(NodeContext &node)
Initialize node context shutdown and args variables.
Definition
init.cpp:232
init.h
init.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(ipc_tests)
Definition
ipc_tests.cpp:202
LogInstance
BCLog::Logger & LogInstance()
Definition
logging.cpp:26
mempool_entry.h
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition
fs.cpp:23
init
Definition
basic.cpp:11
interfaces::MakeChain
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition
interfaces.cpp:1088
node
Definition
messages.h:21
context.h
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition
object.cpp:17
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition
object.cpp:16
scheduler.h
server.h
setup_common.h
streams.h
BasicTestingSetup::BasicTestingSetup
BasicTestingSetup(ChainType chainType=ChainType::MAIN, TestOpts={})
Definition
setup_common.cpp:142
InitTestSetup
Like BasicTestingSetup, but using regtest network instead of mainnet.
Definition
node_init_tests.cpp:28
InitTestSetup::InitTestSetup
InitTestSetup()
Definition
node_init_tests.cpp:29
node::NodeContext
Definition
context.h:59
node::NodeContext::args
ArgsManager * args
Definition
context.h:78
node::NodeContext::init
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
Definition
context.h:64
common.h
validationinterface.h
Generated on
for Bitcoin Core by
1.18.0