Branch data Line data Source code
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 <init.h>
6 : : #include <interfaces/init.h>
7 : : #include <logging.h>
8 : : #include <rpc/server.h>
9 : :
10 : : #include <boost/test/unit_test.hpp>
11 : : #include <test/util/common.h>
12 : : #include <test/util/setup_common.h>
13 : :
14 : : using node::NodeContext;
15 : :
16 : : //! Like BasicTestingSetup, but using regtest network instead of mainnet.
17 : 1 : struct InitTestSetup : BasicTestingSetup {
18 [ + - ]: 2 : InitTestSetup() : BasicTestingSetup{ChainType::REGTEST} {}
19 : : };
20 : :
21 : : BOOST_FIXTURE_TEST_SUITE(node_init_tests, InitTestSetup)
22 : :
23 : : //! Custom implementation of interfaces::Init for testing.
24 : 1 : class TestInit : public interfaces::Init
25 : : {
26 : : public:
27 [ + - ]: 1 : TestInit(NodeContext& node) : m_node(node)
28 : : {
29 [ + - ]: 1 : InitContext(m_node);
30 : 1 : m_node.init = this;
31 : 1 : }
32 : 0 : std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
33 : 1 : std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
34 : : {
35 [ - + ]: 1 : return MakeWalletLoader(chain, *Assert(m_node.args));
36 : : }
37 : : NodeContext& m_node;
38 : : };
39 : :
40 [ + - + - : 10 : BOOST_AUTO_TEST_CASE(init_test)
+ - + - -
+ + - + -
+ - + - +
- + - + -
- + + - +
- + - + -
+ - - + +
- + - + -
+ - + - +
- + - - +
+ - + - +
- + - + -
- + + - ]
41 : : {
42 : : // Clear state set by BasicTestingSetup that AppInitMain assumes is unset.
43 : 1 : LogInstance().DisconnectTestLogger();
44 [ + - ]: 1 : m_node.args->SetConfigFilePath({});
45 : :
46 : : // Prevent the test from trying to listen on ports 8332 and 8333.
47 [ + - + - ]: 2 : m_node.args->ForceSetArg("-server", "0");
48 [ + - + - ]: 2 : m_node.args->ForceSetArg("-listen", "0");
49 : :
50 : : // Run through initialization and shutdown code.
51 : 1 : TestInit init{m_node};
52 [ + - + - : 2 : BOOST_CHECK(AppInitInterfaces(m_node));
+ - + - ]
53 [ + - + - : 2 : BOOST_CHECK(AppInitMain(m_node));
+ - + - ]
54 [ + - ]: 1 : Interrupt(m_node);
55 [ + - ]: 1 : Shutdown(m_node);
56 : 1 : }
57 : :
58 : : BOOST_AUTO_TEST_SUITE_END()
|