Skip to content

Commit

Permalink
tests: Add fuzzing harness for LoadMempool(...) and DumpMempool(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift committed Feb 22, 2021
1 parent 57814a0 commit 4af0132
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Makefile.test.include
Expand Up @@ -294,7 +294,8 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/transaction.cpp \
test/fuzz/tx_in.cpp \
test/fuzz/tx_out.cpp \
test/fuzz/txrequest.cpp
test/fuzz/txrequest.cpp \
test/fuzz/validation_load_mempool.cpp
endif # ENABLE_FUZZ_BINARY

nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
Expand Down
45 changes: 45 additions & 0 deletions src/test/fuzz/validation_load_mempool.cpp
@@ -0,0 +1,45 @@
// Copyright (c) 2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparamsbase.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <util/time.h>
#include <validation.h>

#include <cstdint>
#include <vector>

namespace {
FuzzedFileProvider* fuzzed_file_provider_ptr = nullptr;

FILE* fuzzed_fopen(const fs::path&, const char*)
{
return fuzzed_file_provider_ptr->open();
}
} // namespace

void initialize_validation_load_mempool()
{
static TestingSetup setup{CBaseChainParams::REGTEST, {"-nodebuglogfile"}};
}

FUZZ_TARGET_INIT(validation_load_mempool, 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);
fuzzed_file_provider_ptr = &fuzzed_file_provider;

CTxMemPool pool{};
BlockManager blockman{};
CChainState chainstate{pool, blockman};
(void)LoadMempool(pool, chainstate, fuzzed_fopen);
(void)DumpMempool(pool, fuzzed_fopen, true);

fuzzed_file_provider_ptr = nullptr;
}

0 comments on commit 4af0132

Please sign in to comment.