Skip to content

Commit 68afd3e

Browse files
tests: Add fuzzing harness for LoadMempool(...) and DumpMempool(...)
1 parent 91af6b9 commit 68afd3e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/Makefile.test.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ test_fuzz_fuzz_SOURCES = \
296296
test/fuzz/transaction.cpp \
297297
test/fuzz/tx_in.cpp \
298298
test/fuzz/tx_out.cpp \
299-
test/fuzz/txrequest.cpp
299+
test/fuzz/txrequest.cpp \
300+
test/fuzz/validation_load_mempool.cpp
300301
endif # ENABLE_FUZZ_BINARY
301302

302303
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2020 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 <chainparamsbase.h>
6+
#include <test/fuzz/FuzzedDataProvider.h>
7+
#include <test/fuzz/fuzz.h>
8+
#include <test/fuzz/util.h>
9+
#include <test/util/setup_common.h>
10+
#include <txmempool.h>
11+
#include <util/time.h>
12+
#include <validation.h>
13+
14+
#include <cstdint>
15+
#include <vector>
16+
17+
void initialize_validation_load_mempool()
18+
{
19+
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
20+
}
21+
22+
FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
23+
{
24+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
25+
SetMockTime(ConsumeTime(fuzzed_data_provider));
26+
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
27+
28+
CTxMemPool pool{};
29+
auto fuzzed_fopen = [&](const fs::path&, const char*) {
30+
return fuzzed_file_provider.open();
31+
};
32+
(void)LoadMempool(pool, ::ChainstateActive(), fuzzed_fopen);
33+
(void)DumpMempool(pool, fuzzed_fopen, true);
34+
}

0 commit comments

Comments
 (0)