LCOV - code coverage report
Current view: top level - src/test/fuzz - validation_load_mempool.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 4 22 18.2 %
Date: 2023-09-26 12:08:55 Functions: 5 8 62.5 %

          Line data    Source code
       1             : // Copyright (c) 2020-2022 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 <kernel/mempool_persist.h>
       6             : 
       7             : #include <node/mempool_args.h>
       8             : #include <node/mempool_persist_args.h>
       9             : #include <test/fuzz/FuzzedDataProvider.h>
      10             : #include <test/fuzz/fuzz.h>
      11             : #include <test/fuzz/util.h>
      12             : #include <test/fuzz/util/mempool.h>
      13             : #include <test/util/setup_common.h>
      14             : #include <test/util/txmempool.h>
      15             : #include <txmempool.h>
      16             : #include <util/time.h>
      17           2 : #include <validation.h>
      18           2 : 
      19             : #include <cstdint>
      20             : #include <vector>
      21             : 
      22             : using kernel::DumpMempool;
      23             : using kernel::LoadMempool;
      24             : 
      25             : using node::MempoolPath;
      26             : 
      27             : namespace {
      28             : const TestingSetup* g_setup;
      29             : } // namespace
      30             : 
      31           0 : void initialize_validation_load_mempool()
      32             : {
      33           0 :     static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
      34           0 :     g_setup = testing_setup.get();
      35           0 : }
      36             : 
      37           4 : FUZZ_TARGET(validation_load_mempool, .init = initialize_validation_load_mempool)
      38             : {
      39           0 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      40           0 :     SetMockTime(ConsumeTime(fuzzed_data_provider));
      41           0 :     FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
      42             : 
      43           0 :     CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};
      44             : 
      45           0 :     auto& chainstate{static_cast<DummyChainState&>(g_setup->m_node.chainman->ActiveChainstate())};
      46           0 :     chainstate.SetMempool(&pool);
      47             : 
      48           0 :     auto fuzzed_fopen = [&](const fs::path&, const char*) {
      49           0 :         return fuzzed_file_provider.open();
      50             :     };
      51           0 :     (void)LoadMempool(pool, MempoolPath(g_setup->m_args), chainstate,
      52           0 :                       {
      53           0 :                           .mockable_fopen_function = fuzzed_fopen,
      54             :                       });
      55           0 :     pool.SetLoadTried(true);
      56           0 :     (void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
      57           0 : }

Generated by: LCOV version 1.14