Bitcoin Core  22.99.0
P2P Digital Currency
load_external_block_file.cpp
Go to the documentation of this file.
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>
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 const TestingSetup* g_setup;
18 } // namespace
19 
21 {
22  static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
23  g_setup = testing_setup.get();
24 }
25 
27 {
28  FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
29  FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
30  FILE* fuzzed_block_file = fuzzed_file_provider.open();
31  if (fuzzed_block_file == nullptr) {
32  return;
33  }
34  FlatFilePos flat_file_pos;
35  g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile(fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
36 }
FUZZ_TARGET_INIT
FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
Definition: load_external_block_file.cpp:26
setup_common.h
flatfile.h
util.h
chainparams.h
ConsumeFile
FuzzedFileProvider ConsumeFile(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:301
FlatFilePos
Definition: flatfile.h:14
FuzzedDataProvider.h
FuzzedFileProvider::open
FILE * open()
Definition: util.cpp:395
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
TestingSetup
Testing setup that configures a complete environment.
Definition: setup_common.h:99
initialize_load_external_block_file
void initialize_load_external_block_file()
Definition: load_external_block_file.cpp:20
FuzzedFileProvider
Definition: util.h:280