|
11 | 11 | #include <test/fuzz/FuzzedDataProvider.h>
|
12 | 12 | #include <test/fuzz/fuzz.h>
|
13 | 13 | #include <test/fuzz/util.h>
|
| 14 | +#include <test/util/setup_common.h> |
14 | 15 | #include <time.h>
|
15 | 16 | #include <util/asmap.h>
|
| 17 | +#include <util/system.h> |
16 | 18 |
|
17 | 19 | #include <cassert>
|
18 | 20 | #include <cstdint>
|
19 | 21 | #include <optional>
|
20 | 22 | #include <string>
|
21 | 23 | #include <vector>
|
22 | 24 |
|
| 25 | +namespace { |
| 26 | +const BasicTestingSetup* g_setup; |
| 27 | + |
| 28 | +int32_t GetCheckRatio() |
| 29 | +{ |
| 30 | + return std::clamp<int32_t>(g_setup->m_node.args->GetIntArg("-checkaddrman", 0), 0, 1000000); |
| 31 | +} |
| 32 | +} // namespace |
| 33 | + |
23 | 34 | void initialize_addrman()
|
24 | 35 | {
|
25 |
| - SelectParams(CBaseChainParams::REGTEST); |
| 36 | + static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::REGTEST); |
| 37 | + g_setup = testing_setup.get(); |
26 | 38 | }
|
27 | 39 |
|
28 | 40 | FUZZ_TARGET_INIT(data_stream_addr_man, initialize_addrman)
|
29 | 41 | {
|
30 | 42 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
31 | 43 | CDataStream data_stream = ConsumeDataStream(fuzzed_data_provider);
|
32 |
| - AddrMan addr_man(/*asmap=*/std::vector<bool>(), /*deterministic=*/false, /*consistency_check_ratio=*/0); |
| 44 | + AddrMan addr_man{/*asmap=*/std::vector<bool>(), /*deterministic=*/false, GetCheckRatio()}; |
33 | 45 | try {
|
34 | 46 | ReadFromStream(addr_man, data_stream);
|
35 | 47 | } catch (const std::exception&) {
|
@@ -113,7 +125,7 @@ class AddrManDeterministic : public AddrMan
|
113 | 125 | {
|
114 | 126 | public:
|
115 | 127 | explicit AddrManDeterministic(std::vector<bool> asmap, FuzzedDataProvider& fuzzed_data_provider)
|
116 |
| - : AddrMan(std::move(asmap), /*deterministic=*/true, /*consistency_check_ratio=*/0) |
| 128 | + : AddrMan{std::move(asmap), /*deterministic=*/true, GetCheckRatio()} |
117 | 129 | {
|
118 | 130 | WITH_LOCK(m_impl->cs, m_impl->insecure_rand = FastRandomContext{ConsumeUInt256(fuzzed_data_provider)});
|
119 | 131 | }
|
|
0 commit comments