-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add fuzzing harness for LoadMempool(...) and DumpMempool(...)
- Loading branch information
1 parent
0043325
commit 80a379a
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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 <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() | ||
{ | ||
static TestingSetup setup{CBaseChainParams::REGTEST, {"-nodebuglogfile"}}; | ||
} | ||
|
||
void test_one_input(const std::vector<uint8_t>& buffer) | ||
{ | ||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | ||
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider); | ||
fuzzed_file_provider_ptr = &fuzzed_file_provider; | ||
|
||
CTxMemPool pool; | ||
(void)LoadMempool(pool, fuzzed_fopen); | ||
(void)DumpMempool(pool, fuzzed_fopen, true); | ||
|
||
fuzzed_file_provider_ptr = nullptr; | ||
} |