Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2025-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.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>19#include <boost/test/unit_test.hpp>20#include <test/util/common.h>21#include <test/util/setup_common.h>23#include <memory>25using node::NodeContext;27//! Like BasicTestingSetup, but using regtest network instead of mainnet.28struct InitTestSetup : BasicTestingSetup {29InitTestSetup() : BasicTestingSetup{ChainType::REGTEST} {}30};32BOOST_FIXTURE_TEST_SUITE(node_init_tests, InitTestSetup)34//! Custom implementation of interfaces::Init for testing.35class TestInit : public interfaces::Init36{37public:38TestInit(NodeContext& node) : m_node(node)39{40InitContext(m_node);41m_node.init = this;42}43std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }44std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override45{46return MakeWalletLoader(chain, *Assert(m_node.args));47}48NodeContext& m_node;49};51BOOST_AUTO_TEST_CASE(init_test)52{53// Clear state set by BasicTestingSetup that AppInitMain assumes is unset.54LogInstance().DisconnectTestLogger();55m_node.args->SetConfigFilePath({});57// Prevent the test from trying to listen on ports 8332 and 8333.58m_node.args->ForceSetArg("-server", "0");59m_node.args->ForceSetArg("-listen", "0");61// Run through initialization and shutdown code.62TestInit init{m_node};63BOOST_CHECK(AppInitInterfaces(m_node));64BOOST_CHECK(AppInitMain(m_node));65Interrupt(m_node);67// Model a block update left queued after the scheduler stops during shutdown68m_node.scheduler->stop();69constexpr unsigned int queued_height{123};70m_node.validation_signals->MempoolTransactionsRemovedForBlock(std::make_shared<CBlock>(Params().GenesisBlock()), {}, queued_height);71BOOST_REQUIRE_GT(m_node.validation_signals->CallbacksPending(), 0);73Shutdown(m_node);75AutoFile estimates_file{fsbridge::fopen(BlockPolicyFeeEstPath(*m_node.args), "rb")};76int version;77unsigned int best_seen_height;78estimates_file >> version >> best_seen_height;79BOOST_CHECK_EQUAL(best_seen_height, queued_height);80}82BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.