fuzz: Remove FuzzedAutoFileProvider

The code is clearer without it.

This is also needed for a future commit.
This commit is contained in:
MarcoFalke 2023-11-14 17:30:46 +01:00
parent fb85bb2776
commit fa5388fad3
No known key found for this signature in database
7 changed files with 14 additions and 36 deletions

View file

@ -17,8 +17,10 @@
FUZZ_TARGET(autofile)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
AutoFile auto_file{fuzzed_auto_file_provider.open()};
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
AutoFile auto_file{
fuzzed_file_provider.open(),
};
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
CallOneOf(
fuzzed_data_provider,

View file

@ -17,7 +17,7 @@
FUZZ_TARGET(buffered_file)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
std::optional<BufferedFile> opt_buffered_file;
CAutoFile fuzzed_file{fuzzed_file_provider.open(), 0};
try {

View file

@ -27,7 +27,7 @@ void initialize_load_external_block_file()
FUZZ_TARGET(load_external_block_file, .init = initialize_load_external_block_file)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
CAutoFile fuzzed_block_file{fuzzed_file_provider.open(), CLIENT_VERSION};
if (fuzzed_block_file.IsNull()) {
return;

View file

@ -13,6 +13,7 @@
#include <test/fuzz/util/mempool.h>
#include <test/util/setup_common.h>
#include <memory>
#include <optional>
#include <vector>
@ -81,8 +82,8 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
}
{
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()};
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
AutoFile fuzzed_auto_file{fuzzed_file_provider.open()};
block_policy_estimator.Write(fuzzed_auto_file);
block_policy_estimator.Read(fuzzed_auto_file);
}

View file

@ -4,13 +4,13 @@
#include <policy/fees.h>
#include <policy/fees_args.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <cstdint>
#include <vector>
#include <memory>
namespace {
const BasicTestingSetup* g_setup;
@ -25,8 +25,8 @@ void initialize_policy_estimator_io()
FUZZ_TARGET(policy_estimator_io, .init = initialize_policy_estimator_io)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()};
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
AutoFile fuzzed_auto_file{fuzzed_file_provider.open()};
// Re-using block_policy_estimator across runs to avoid costly creation of CBlockPolicyEstimator object.
static CBlockPolicyEstimator block_policy_estimator{FeeestPath(*g_setup->m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES};
if (block_policy_estimator.Read(fuzzed_auto_file)) {

View file

@ -263,31 +263,6 @@ public:
static int close(void* cookie);
};
[[nodiscard]] inline FuzzedFileProvider ConsumeFile(FuzzedDataProvider& fuzzed_data_provider) noexcept
{
return {fuzzed_data_provider};
}
class FuzzedAutoFileProvider
{
FuzzedFileProvider m_fuzzed_file_provider;
public:
FuzzedAutoFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_file_provider{fuzzed_data_provider}
{
}
AutoFile open()
{
return AutoFile{m_fuzzed_file_provider.open()};
}
};
[[nodiscard]] inline FuzzedAutoFileProvider ConsumeAutoFile(FuzzedDataProvider& fuzzed_data_provider) noexcept
{
return {fuzzed_data_provider};
}
#define WRITE_TO_STREAM_CASE(type, consume) \
[&] { \
type o = consume; \

View file

@ -38,7 +38,7 @@ FUZZ_TARGET(validation_load_mempool, .init = initialize_validation_load_mempool)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
SetMockTime(ConsumeTime(fuzzed_data_provider));
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};