diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-02-08 13:34:40 +0100 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-08-02 14:49:47 +0200 |
commit | 6408b24517f3418e2a408071b4c2ce26571f3167 (patch) | |
tree | a063c07d029e3977862b89764327f011ef0a471e /src/test/fuzz/addrman.cpp | |
parent | dcd116950fed0890020bc7283c5fa753f866047f (diff) | |
download | bitcoin-6408b24517f3418e2a408071b4c2ce26571f3167.tar.xz |
fuzz: move init code to the CAddrManDeterministic constructor
Move the addrman init code from the test case to a newly added
`CAddrManDeterministic` constructor. This way it can be reused by other
tests.
Diffstat (limited to 'src/test/fuzz/addrman.cpp')
-rw-r--r-- | src/test/fuzz/addrman.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/test/fuzz/addrman.cpp b/src/test/fuzz/addrman.cpp index 344d1dde8e..94369fa5a0 100644 --- a/src/test/fuzz/addrman.cpp +++ b/src/test/fuzz/addrman.cpp @@ -25,10 +25,15 @@ void initialize_addrman() class CAddrManDeterministic : public CAddrMan { public: - void MakeDeterministic(const uint256& random_seed) + explicit CAddrManDeterministic(FuzzedDataProvider& fuzzed_data_provider) { - WITH_LOCK(cs, insecure_rand = FastRandomContext{random_seed}); - Clear(); + WITH_LOCK(cs, insecure_rand = FastRandomContext{ConsumeUInt256(fuzzed_data_provider)}); + if (fuzzed_data_provider.ConsumeBool()) { + m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider); + if (!SanityCheckASMap(m_asmap)) { + m_asmap.clear(); + } + } } }; @@ -36,14 +41,7 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); SetMockTime(ConsumeTime(fuzzed_data_provider)); - CAddrManDeterministic addr_man; - addr_man.MakeDeterministic(ConsumeUInt256(fuzzed_data_provider)); - if (fuzzed_data_provider.ConsumeBool()) { - addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider); - if (!SanityCheckASMap(addr_man.m_asmap)) { - addr_man.m_asmap.clear(); - } - } + CAddrManDeterministic addr_man{fuzzed_data_provider}; if (fuzzed_data_provider.ConsumeBool()) { const std::vector<uint8_t> serialized_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)}; CDataStream ds(serialized_data, SER_DISK, INIT_PROTO_VERSION); |