LCOV - code coverage report
Current view: top level - src/test - node_init_tests.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 96.7 % 30 29
Test Date: 2026-10-11 07:59:32 Functions: 83.3 % 6 5
Branches: 50.0 % 140 70

             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 <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>
      18                 :             : 
      19                 :             : #include <boost/test/unit_test.hpp>
      20                 :             : #include <test/util/common.h>
      21                 :             : #include <test/util/setup_common.h>
      22                 :             : 
      23                 :             : #include <memory>
      24                 :             : 
      25                 :             : using node::NodeContext;
      26                 :             : 
      27                 :             : //! Like BasicTestingSetup, but using regtest network instead of mainnet.
      28                 :           2 : struct InitTestSetup : BasicTestingSetup {
      29         [ +  - ]:           2 :     InitTestSetup() : BasicTestingSetup{ChainType::REGTEST} {}
      30                 :             : };
      31                 :             : 
      32                 :             : BOOST_FIXTURE_TEST_SUITE(node_init_tests, InitTestSetup)
      33                 :             : 
      34                 :             : //! Custom implementation of interfaces::Init for testing.
      35                 :           1 : class TestInit : public interfaces::Init
      36                 :             : {
      37                 :             : public:
      38   [ +  -  +  - ]:           2 :     TestInit(NodeContext& node) : m_node(node)
      39                 :             :     {
      40         [ +  - ]:           1 :         InitContext(m_node);
      41                 :           1 :         m_node.init = this;
      42                 :           1 :     }
      43                 :           0 :     std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
      44                 :           1 :     std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
      45                 :             :     {
      46         [ -  + ]:           1 :         return MakeWalletLoader(chain, *Assert(m_node.args));
      47                 :             :     }
      48                 :             :     NodeContext& m_node;
      49                 :             : };
      50                 :             : 
      51   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(init_test)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      52                 :             : {
      53                 :             :     // Clear state set by BasicTestingSetup that AppInitMain assumes is unset.
      54                 :           1 :     LogInstance().DisconnectTestLogger();
      55         [ +  - ]:           1 :     m_node.args->SetConfigFilePath({});
      56                 :             : 
      57                 :             :     // Prevent the test from trying to listen on ports 8332 and 8333.
      58   [ +  -  +  - ]:           2 :     m_node.args->ForceSetArg("-server", "0");
      59   [ +  -  +  - ]:           2 :     m_node.args->ForceSetArg("-listen", "0");
      60                 :             : 
      61                 :             :     // Run through initialization and shutdown code.
      62                 :           1 :     TestInit init{m_node};
      63   [ +  -  +  -  :           2 :     BOOST_CHECK(AppInitInterfaces(m_node));
             +  -  +  - ]
      64   [ +  -  +  -  :           2 :     BOOST_CHECK(AppInitMain(m_node));
             +  -  +  - ]
      65         [ +  - ]:           1 :     Interrupt(m_node);
      66                 :             : 
      67                 :             :     // Model a block update left queued after the scheduler stops during shutdown
      68         [ +  - ]:           1 :     m_node.scheduler->stop();
      69                 :           1 :     constexpr unsigned int queued_height{123};
      70   [ +  -  +  -  :           2 :     m_node.validation_signals->MempoolTransactionsRemovedForBlock(std::make_shared<CBlock>(Params().GenesisBlock()), {}, queued_height);
             +  -  -  + ]
      71   [ +  -  +  -  :           1 :     BOOST_REQUIRE_GT(m_node.validation_signals->CallbacksPending(), 0);
                   +  - ]
      72                 :             : 
      73         [ +  - ]:           1 :     Shutdown(m_node);
      74                 :             : 
      75   [ +  -  +  -  :           2 :     AutoFile estimates_file{fsbridge::fopen(BlockPolicyFeeEstPath(*m_node.args), "rb")};
                   +  - ]
      76                 :           1 :     int version;
      77                 :           1 :     unsigned int best_seen_height;
      78   [ +  -  +  - ]:           1 :     estimates_file >> version >> best_seen_height;
      79   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(best_seen_height, queued_height);
      80                 :           1 : }
      81                 :             : 
      82                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1