Bitcoin Core 28.99.0
P2P Digital Currency
validation_load_mempool.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2022 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
6
7#include <node/mempool_args.h>
10#include <test/fuzz/fuzz.h>
11#include <test/fuzz/util.h>
14#include <test/util/txmempool.h>
15#include <txmempool.h>
16#include <util/check.h>
17#include <util/time.h>
18#include <util/translation.h>
19#include <validation.h>
20
21#include <cstdint>
22#include <vector>
23
26
28
29namespace {
30const TestingSetup* g_setup;
31} // namespace
32
34{
35 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
36 g_setup = testing_setup.get();
37}
38
40{
42 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
43 SetMockTime(ConsumeTime(fuzzed_data_provider));
44 FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
45
46 bilingual_str error;
47 CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error};
48 Assert(error.empty());
49
50 auto& chainstate{static_cast<DummyChainState&>(g_setup->m_node.chainman->ActiveChainstate())};
51 chainstate.SetMempool(&pool);
52
53 auto fuzzed_fopen = [&](const fs::path&, const char*) {
54 return fuzzed_file_provider.open();
55 };
56 (void)LoadMempool(pool, MempoolPath(g_setup->m_args), chainstate,
57 {
58 .mockable_fopen_function = fuzzed_fopen,
59 });
60 pool.SetLoadTried(true);
61 (void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
62}
#define Assert(val)
Identity function.
Definition: check.h:85
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:304
void SetMempool(CTxMemPool *mempool)
Definition: mempool.h:18
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
fs::path MempoolPath(const ArgsManager &argsman)
bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, Chainstate &active_chainstate, ImportMempoolOptions &&opts)
Import the file and attempt to add its contents to the mempool.
bool DumpMempool(const CTxMemPool &pool, const fs::path &dump_path, FopenFn mockable_fopen_function, bool skip_file_commit)
Testing setup that configures a complete environment.
Definition: setup_common.h:120
Bilingual messages:
Definition: translation.h:21
bool empty() const
Definition: translation.h:32
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition: util.cpp:34
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
Definition: random.cpp:19
@ ZEROS
Seed with a compile time constant of zeros.
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
Definition: txmempool.cpp:20
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:35
FUZZ_TARGET(validation_load_mempool,.init=initialize_validation_load_mempool)
void initialize_validation_load_mempool()