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