Branch data Line data Source code
1 : : // Copyright (c) 2020-present 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 <node/mempool_persist.h>
6 : : #include <test/util/time.h>
7 : :
8 : : #include <node/mempool_args.h>
9 : : #include <node/mempool_persist_args.h>
10 : : #include <test/fuzz/FuzzedDataProvider.h>
11 : : #include <test/fuzz/fuzz.h>
12 : : #include <test/fuzz/util.h>
13 : : #include <test/fuzz/util/mempool.h>
14 : : #include <test/util/setup_common.h>
15 : : #include <test/util/txmempool.h>
16 : : #include <txmempool.h>
17 : : #include <util/check.h>
18 : : #include <util/time.h>
19 : : #include <util/translation.h>
20 : : #include <validation.h>
21 : :
22 : : #include <cstdint>
23 : : #include <vector>
24 : :
25 : : using node::DumpMempool;
26 : : using node::LoadMempool;
27 : :
28 : : using node::MempoolPath;
29 : :
30 : : namespace {
31 : : const TestingSetup* g_setup;
32 : : } // namespace
33 : :
34 : 1 : void initialize_validation_load_mempool()
35 : : {
36 [ + - + - : 1 : static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
+ - ]
37 : 1 : g_setup = testing_setup.get();
38 : 1 : }
39 : :
40 [ + - ]: 1507 : FUZZ_TARGET(validation_load_mempool, .init = initialize_validation_load_mempool)
41 : : {
42 : 1049 : SeedRandomStateForTest(SeedRand::ZEROS);
43 : 1049 : FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
44 : 1049 : NodeClockContext clock_ctx{ConsumeTime(fuzzed_data_provider)};
45 [ + - ]: 1049 : FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
46 : :
47 [ + - ]: 1049 : bilingual_str error;
48 [ + - + - ]: 1049 : CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error};
49 [ - + ]: 1049 : Assert(error.empty());
50 : :
51 [ + - ]: 1049 : auto& chainstate{static_cast<DummyChainState&>(g_setup->m_node.chainman->ActiveChainstate())};
52 [ + - ]: 1049 : chainstate.SetMempool(&pool);
53 : :
54 : 3147 : auto fuzzed_fopen = [&](const fs::path&, const char*) {
55 : 2098 : return fuzzed_file_provider.open();
56 : 1049 : };
57 [ + - ]: 2098 : (void)LoadMempool(pool, MempoolPath(g_setup->m_args), chainstate,
58 : : {
59 : : .mockable_fopen_function = fuzzed_fopen,
60 : : });
61 [ + - ]: 1049 : pool.SetLoadTried(true);
62 [ + - + - ]: 2098 : (void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
63 [ + - ]: 3147 : }
|