mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
fuzz: Initialize a TestingSetup for test_one_input
For fuzz tests that need it.
This commit is contained in:
parent
0d61634c06
commit
ee0ab1e959
3 changed files with 15 additions and 3 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <vector>
|
||||
|
||||
namespace {
|
||||
const TestingSetup* g_setup;
|
||||
const Coin EMPTY_COIN{};
|
||||
|
||||
bool operator==(const Coin& a, const Coin& b)
|
||||
|
@ -39,6 +40,7 @@ bool operator==(const Coin& a, const Coin& b)
|
|||
void initialize_coins_view()
|
||||
{
|
||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||
g_setup = testing_setup.get();
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
|
||||
|
@ -268,7 +270,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
|
|||
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
|
||||
bool expected_code_path = false;
|
||||
try {
|
||||
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_chainman.m_blockman)), stats);
|
||||
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_setup->m_node.chainman->m_blockman)), stats);
|
||||
} catch (const std::logic_error&) {
|
||||
expected_code_path = true;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,14 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
const TestingSetup* g_setup;
|
||||
} // namespace
|
||||
|
||||
void initialize_load_external_block_file()
|
||||
{
|
||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||
g_setup = testing_setup.get();
|
||||
}
|
||||
|
||||
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)
|
|||
return;
|
||||
}
|
||||
FlatFilePos flat_file_pos;
|
||||
::ChainstateActive().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
|
||||
g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
|
||||
}
|
||||
|
|
|
@ -14,9 +14,14 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
const TestingSetup* g_setup;
|
||||
} // namespace
|
||||
|
||||
void initialize_validation_load_mempool()
|
||||
{
|
||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||
g_setup = testing_setup.get();
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
|
||||
|
@ -29,6 +34,6 @@ FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
|
|||
auto fuzzed_fopen = [&](const fs::path&, const char*) {
|
||||
return fuzzed_file_provider.open();
|
||||
};
|
||||
(void)LoadMempool(pool, ::ChainstateActive(), fuzzed_fopen);
|
||||
(void)LoadMempool(pool, g_setup->m_node.chainman->ActiveChainstate(), fuzzed_fopen);
|
||||
(void)DumpMempool(pool, fuzzed_fopen, true);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue