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: 20 20 100.0 %
Date: 2023-10-05 15:40:34 Functions: 7 7 100.0 %
Branches: 18 32 56.2 %

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

Generated by: LCOV version 1.14