LCOV - code coverage report
Current view: top level - src/test - node_init_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 95.2 % 21 20
Test Date: 2026-03-16 05:20:51 Functions: 83.3 % 6 5
Branches: 50.0 % 108 54

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

Generated by: LCOV version 2.0-1