Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/bloom_filter.cpp
// Copyright (c) 2020 The Bitcoin Core developers | // Copyright (c) 2020 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bloom.h> | #include <bloom.h> | ||||
#include <optional.h> | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <test/fuzz/FuzzedDataProvider.h> | #include <test/fuzz/FuzzedDataProvider.h> | ||||
#include <test/fuzz/fuzz.h> | #include <test/fuzz/fuzz.h> | ||||
#include <test/fuzz/util.h> | #include <test/fuzz/util.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <cassert> | #include <cassert> | ||||
#include <cstdint> | #include <cstdint> | ||||
Show All 18 Lines | while (fuzzed_data_provider.remaining_bytes() > 0) { | ||||
ConsumeRandomLengthByteVector(fuzzed_data_provider); | ConsumeRandomLengthByteVector(fuzzed_data_provider); | ||||
(void)bloom_filter.contains(b); | (void)bloom_filter.contains(b); | ||||
bloom_filter.insert(b); | bloom_filter.insert(b); | ||||
const bool present = bloom_filter.contains(b); | const bool present = bloom_filter.contains(b); | ||||
assert(present); | assert(present); | ||||
break; | break; | ||||
} | } | ||||
case 1: { | case 1: { | ||||
const Optional<COutPoint> out_point = | const std::optional<COutPoint> out_point = | ||||
ConsumeDeserializable<COutPoint>(fuzzed_data_provider); | ConsumeDeserializable<COutPoint>(fuzzed_data_provider); | ||||
if (!out_point) { | if (!out_point) { | ||||
break; | break; | ||||
} | } | ||||
(void)bloom_filter.contains(*out_point); | (void)bloom_filter.contains(*out_point); | ||||
bloom_filter.insert(*out_point); | bloom_filter.insert(*out_point); | ||||
const bool present = bloom_filter.contains(*out_point); | const bool present = bloom_filter.contains(*out_point); | ||||
assert(present); | assert(present); | ||||
break; | break; | ||||
} | } | ||||
case 2: { | case 2: { | ||||
const Optional<uint256> u256 = | const std::optional<uint256> u256 = | ||||
ConsumeDeserializable<uint256>(fuzzed_data_provider); | ConsumeDeserializable<uint256>(fuzzed_data_provider); | ||||
if (!u256) { | if (!u256) { | ||||
break; | break; | ||||
} | } | ||||
(void)bloom_filter.contains(*u256); | (void)bloom_filter.contains(*u256); | ||||
bloom_filter.insert(*u256); | bloom_filter.insert(*u256); | ||||
const bool present = bloom_filter.contains(*u256); | const bool present = bloom_filter.contains(*u256); | ||||
assert(present); | assert(present); | ||||
break; | break; | ||||
} | } | ||||
case 3: | case 3: | ||||
bloom_filter.clear(); | bloom_filter.clear(); | ||||
break; | break; | ||||
case 4: | case 4: | ||||
bloom_filter.reset( | bloom_filter.reset( | ||||
fuzzed_data_provider.ConsumeIntegral<unsigned int>()); | fuzzed_data_provider.ConsumeIntegral<unsigned int>()); | ||||
break; | break; | ||||
case 5: { | case 5: { | ||||
const Optional<CMutableTransaction> mut_tx = | const std::optional<CMutableTransaction> mut_tx = | ||||
ConsumeDeserializable<CMutableTransaction>( | ConsumeDeserializable<CMutableTransaction>( | ||||
fuzzed_data_provider); | fuzzed_data_provider); | ||||
if (!mut_tx) { | if (!mut_tx) { | ||||
break; | break; | ||||
} | } | ||||
const CTransaction tx{*mut_tx}; | const CTransaction tx{*mut_tx}; | ||||
(void)bloom_filter.IsRelevantAndUpdate(tx); | (void)bloom_filter.IsRelevantAndUpdate(tx); | ||||
break; | break; | ||||
} | } | ||||
case 6: | case 6: | ||||
bloom_filter.UpdateEmptyFull(); | bloom_filter.UpdateEmptyFull(); | ||||
break; | break; | ||||
} | } | ||||
(void)bloom_filter.IsWithinSizeConstraints(); | (void)bloom_filter.IsWithinSizeConstraints(); | ||||
} | } | ||||
} | } |