Skip to content

Commit ee0ab1e

Browse files
committed
fuzz: Initialize a TestingSetup for test_one_input
For fuzz tests that need it.
1 parent 0d61634 commit ee0ab1e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/test/fuzz/coins_view.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <vector>
2828

2929
namespace {
30+
const TestingSetup* g_setup;
3031
const Coin EMPTY_COIN{};
3132

3233
bool operator==(const Coin& a, const Coin& b)
@@ -39,6 +40,7 @@ bool operator==(const Coin& a, const Coin& b)
3940
void initialize_coins_view()
4041
{
4142
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
43+
g_setup = testing_setup.get();
4244
}
4345

4446
FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
@@ -268,7 +270,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
268270
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
269271
bool expected_code_path = false;
270272
try {
271-
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_chainman.m_blockman)), stats);
273+
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_setup->m_node.chainman->m_blockman)), stats);
272274
} catch (const std::logic_error&) {
273275
expected_code_path = true;
274276
}

src/test/fuzz/load_external_block_file.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
#include <cstdint>
1414
#include <vector>
1515

16+
namespace {
17+
const TestingSetup* g_setup;
18+
} // namespace
19+
1620
void initialize_load_external_block_file()
1721
{
1822
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
23+
g_setup = testing_setup.get();
1924
}
2025

2126
FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
@@ -27,5 +32,5 @@ FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
2732
return;
2833
}
2934
FlatFilePos flat_file_pos;
30-
::ChainstateActive().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
35+
g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
3136
}

src/test/fuzz/validation_load_mempool.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
#include <cstdint>
1515
#include <vector>
1616

17+
namespace {
18+
const TestingSetup* g_setup;
19+
} // namespace
20+
1721
void initialize_validation_load_mempool()
1822
{
1923
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
24+
g_setup = testing_setup.get();
2025
}
2126

2227
FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
@@ -29,6 +34,6 @@ FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
2934
auto fuzzed_fopen = [&](const fs::path&, const char*) {
3035
return fuzzed_file_provider.open();
3136
};
32-
(void)LoadMempool(pool, ::ChainstateActive(), fuzzed_fopen);
37+
(void)LoadMempool(pool, g_setup->m_node.chainman->ActiveChainstate(), fuzzed_fopen);
3338
(void)DumpMempool(pool, fuzzed_fopen, true);
3439
}

0 commit comments

Comments
 (0)