Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
load_external_block_file.cpp
Go to the documentation of this file.
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 <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 <
test/util/time.h
>
13
#include <util/time.h>
14
#include <validation.h>
15
16
#include <cstdint>
17
#include <vector>
18
19
namespace
{
20
const
TestingSetup
*
g_setup
;
21
}
// namespace
22
23
void
initialize_load_external_block_file
()
24
{
25
static
const
auto
testing_setup =
MakeNoLogFileContext<const TestingSetup>
();
26
g_setup
= testing_setup.get();
27
}
28
29
FUZZ_TARGET
(load_external_block_file, .
init
=
initialize_load_external_block_file
)
30
{
31
FuzzedDataProvider
fuzzed_data_provider{buffer.data(), buffer.size()};
32
FakeNodeClock
clock{
ConsumeTime
(fuzzed_data_provider)};
33
FuzzedFileProvider
fuzzed_file_provider{fuzzed_data_provider};
34
AutoFile
fuzzed_block_file{fuzzed_file_provider.
open
()};
35
if
(fuzzed_block_file.
IsNull
()) {
36
return
;
37
}
38
if
(fuzzed_data_provider.
ConsumeBool
()) {
39
// Corresponds to the -reindex case (track orphan blocks across files).
40
FlatFilePos
flat_file_pos;
41
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
42
g_setup
->
m_node
.
chainman
->LoadExternalBlockFile(fuzzed_block_file, &flat_file_pos, &blocks_with_unknown_parent);
43
}
else
{
44
// Corresponds to the -loadblock= case (orphan blocks aren't tracked across files).
45
g_setup
->
m_node
.
chainman
->LoadExternalBlockFile(fuzzed_block_file);
46
}
47
}
FuzzedDataProvider.h
g_setup
const TestingSetup * g_setup
Definition
block_index_tree.cpp:22
AutoFile
Non-refcounted RAII wrapper for FILE*.
Definition
streams.h:395
AutoFile::IsNull
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
Definition
streams.h:448
FakeNodeClock
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition
time.h:54
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedFileProvider
Definition
util.h:289
FuzzedFileProvider::open
FILE * open()
Definition
util.cpp:251
clientversion.h
flatfile.h
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
initialize_load_external_block_file
void initialize_load_external_block_file()
Definition
load_external_block_file.cpp:23
init
Definition
basic.cpp:11
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:241
BasicTestingSetup::m_node
node::NodeContext m_node
Definition
setup_common.h:60
FlatFilePos
Definition
flatfile.h:15
TestingSetup
Testing setup that configures a complete environment.
Definition
setup_common.h:115
node::NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition
context.h:76
ConsumeTime
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition
util.cpp:34
util.h
time.h
Generated on
for Bitcoin Core by
1.18.0