LCOV - code coverage report
Current view: top level - src/test/fuzz - validation_load_mempool.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 24 24
Test Date: 2026-11-21 05:38:30 Functions: 100.0 % 3 3
Branches: 50.0 % 36 18

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-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 <node/mempool_persist.h>
       6                 :             : #include <test/util/time.h>
       7                 :             : 
       8                 :             : #include <node/mempool_args.h>
       9                 :             : #include <node/mempool_persist_args.h>
      10                 :             : #include <test/fuzz/FuzzedDataProvider.h>
      11                 :             : #include <test/fuzz/fuzz.h>
      12                 :             : #include <test/fuzz/util.h>
      13                 :             : #include <test/fuzz/util/mempool.h>
      14                 :             : #include <test/fuzz/util/reachability.h>
      15                 :             : #include <test/util/setup_common.h>
      16                 :             : #include <test/util/txmempool.h>
      17                 :             : #include <txmempool.h>
      18                 :             : #include <util/check.h>
      19                 :             : #include <util/time.h>
      20                 :             : #include <util/translation.h>
      21                 :             : #include <validation.h>
      22                 :             : 
      23                 :             : #include <cstdint>
      24                 :             : #include <vector>
      25                 :             : 
      26                 :             : using node::DumpMempool;
      27                 :             : using node::LoadMempool;
      28                 :             : 
      29                 :             : using node::MempoolPath;
      30                 :             : 
      31                 :             : namespace {
      32                 :             : const TestingSetup* g_setup;
      33                 :             : constexpr ReachabilityGoal MEMPOOL_LOAD_SUCCEEDS{"mempool loading succeeds"};
      34                 :             : } // namespace
      35                 :             : 
      36                 :           1 : void initialize_validation_load_mempool()
      37                 :             : {
      38                 :           1 :     RegisterReachabilityGoal(MEMPOOL_LOAD_SUCCEEDS);
      39   [ +  -  +  -  :           1 :     static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
                   +  - ]
      40                 :           1 :     g_setup = testing_setup.get();
      41                 :           1 : }
      42                 :             : 
      43         [ +  - ]:        1844 : FUZZ_TARGET(validation_load_mempool, .init = initialize_validation_load_mempool)
      44                 :             : {
      45                 :        1368 :     SeedRandomStateForTest(SeedRand::ZEROS);
      46                 :        1368 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      47                 :        1368 :     FakeNodeClock clock{ConsumeTime(fuzzed_data_provider)};
      48         [ +  - ]:        1368 :     FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
      49                 :             : 
      50         [ +  - ]:        1368 :     bilingual_str error;
      51   [ +  -  +  - ]:        1368 :     CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error};
      52         [ +  - ]:        1368 :     Assert(error.empty());
      53                 :             : 
      54         [ +  - ]:        1368 :     auto& chainstate{static_cast<DummyChainState&>(g_setup->m_node.chainman->ActiveChainstate())};
      55         [ +  - ]:        1368 :     chainstate.SetMempool(&pool);
      56                 :             : 
      57                 :        4104 :     auto fuzzed_fopen = [&](const fs::path&, const char*) {
      58                 :        2736 :         return fuzzed_file_provider.open();
      59                 :        1368 :     };
      60                 :        1368 :     const bool load_success{
      61   [ +  -  +  - ]:        2736 :         LoadMempool(pool, MempoolPath(g_setup->m_args), chainstate,
      62                 :             :                     {
      63                 :             :                         .mockable_fopen_function = fuzzed_fopen,
      64                 :             :                     })};
      65         [ +  - ]:        1368 :     pool.SetLoadTried(true);
      66   [ +  -  +  - ]:        2736 :     (void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
      67         [ +  - ]:        1368 :     ObserveReachabilityGoal(load_success, MEMPOOL_LOAD_SUCCEEDS);
      68         [ +  - ]:        4104 : }
        

Generated by: LCOV version 2.5.0-full