mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
test: Add unit test coverage for Init and Shutdown code
Currently this code is not called in unit tests. Calling should make it possible to write tests for things like IPC exceptions being thrown during shutdown.
This commit is contained in:
51
src/test/node_init_tests.cpp
Normal file
51
src/test/node_init_tests.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2025 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <init.h>
|
||||
#include <interfaces/init.h>
|
||||
#include <rpc/server.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
using node::NodeContext;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(node_init_tests, BasicTestingSetup)
|
||||
|
||||
//! Custom implementation of interfaces::Init for testing.
|
||||
class TestInit : public interfaces::Init
|
||||
{
|
||||
public:
|
||||
TestInit(NodeContext& node) : m_node(node)
|
||||
{
|
||||
InitContext(m_node);
|
||||
m_node.init = this;
|
||||
}
|
||||
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
|
||||
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
|
||||
{
|
||||
return MakeWalletLoader(chain, *Assert(m_node.args));
|
||||
}
|
||||
NodeContext& m_node;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_test)
|
||||
{
|
||||
// Clear state set by BasicTestingSetup that AppInitMain assumes is unset.
|
||||
LogInstance().DisconnectTestLogger();
|
||||
m_node.args->SetConfigFilePath({});
|
||||
|
||||
// Prevent the test from trying to listen on ports 8332 and 8333.
|
||||
m_node.args->ForceSetArg("-server", "0");
|
||||
m_node.args->ForceSetArg("-listen", "0");
|
||||
|
||||
// Run through initialization and shutdown code.
|
||||
TestInit init{m_node};
|
||||
BOOST_CHECK(AppInitInterfaces(m_node));
|
||||
BOOST_CHECK(AppInitMain(m_node));
|
||||
Interrupt(m_node);
|
||||
Shutdown(m_node);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user