LCOV - code coverage report
Current view: top level - src/test/fuzz - load_external_block_file.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 4 20 20.0 %
Date: 2023-09-26 12:08:55 Functions: 5 7 71.4 %

          Line data    Source code
       1             : // Copyright (c) 2020-2021 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 <flatfile.h>
       7             : #include <test/fuzz/FuzzedDataProvider.h>
       8             : #include <test/fuzz/fuzz.h>
       9             : #include <test/fuzz/util.h>
      10             : #include <test/util/setup_common.h>
      11             : #include <validation.h>
      12             : 
      13             : #include <cstdint>
      14             : #include <vector>
      15             : 
      16             : namespace {
      17           2 : const TestingSetup* g_setup;
      18           2 : } // namespace
      19             : 
      20           0 : void initialize_load_external_block_file()
      21             : {
      22           0 :     static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
      23           0 :     g_setup = testing_setup.get();
      24           0 : }
      25             : 
      26           4 : FUZZ_TARGET(load_external_block_file, .init = initialize_load_external_block_file)
      27             : {
      28           0 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      29           0 :     FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
      30           0 :     FILE* fuzzed_block_file = fuzzed_file_provider.open();
      31           0 :     if (fuzzed_block_file == nullptr) {
      32           0 :         return;
      33             :     }
      34           0 :     if (fuzzed_data_provider.ConsumeBool()) {
      35             :         // Corresponds to the -reindex case (track orphan blocks across files).
      36           0 :         FlatFilePos flat_file_pos;
      37           0 :         std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
      38           0 :         g_setup->m_node.chainman->LoadExternalBlockFile(fuzzed_block_file, &flat_file_pos, &blocks_with_unknown_parent);
      39           0 :     } else {
      40             :         // Corresponds to the -loadblock= case (orphan blocks aren't tracked across files).
      41           0 :         g_setup->m_node.chainman->LoadExternalBlockFile(fuzzed_block_file);
      42             :     }
      43           0 : }

Generated by: LCOV version 1.14