Files
bitcoin/src/test/node_init_tests.cpp
Ryan Ofsky 3ae592537d test: Prevent disk space warning during node_init_tests
mzumsande pointed out https://github.com/bitcoin/bitcoin/pull/32345#issuecomment-3286964369 that this test was causing a warning:

   Warning: Disk space for "/tmp/test_common bitcoin/node_init_tests/init_test/bf78678cb7723a3e84b5/blocks" may not accommodate the block files. Approximately 810 GB of data will be stored in this directory.

Fix by setting regtest instead of mainnet network before running the test.

Github-Pull: #33391
Rebased-From: bdf01c6f61
2025-09-16 09:49:48 +01:00

57 lines
1.7 KiB
C++

// 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;
//! Like BasicTestingSetup, but using regtest network instead of mainnet.
struct InitTestSetup : BasicTestingSetup {
InitTestSetup() : BasicTestingSetup{ChainType::REGTEST} {}
};
BOOST_FIXTURE_TEST_SUITE(node_init_tests, InitTestSetup)
//! 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()