aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/util
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-01-31 18:04:44 +0100
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-09-05 10:13:25 +0200
commitfac81affb527132945773a5315bd27fec61ec52f (patch)
tree90aa401bd50bf12519a45737f335856256ff614e /src/test/fuzz/util
parentfaec591d64e40ba7ec7656cbfdda1a05953bde13 (diff)
Use serialization parameters for CAddress serialization
This also cleans up the addrman (de)serialization code paths to only allow `Disk` serialization. Some unit tests previously forced a `Network` serialization, which does not make sense, because Bitcoin Core in production will always `Disk` serialize. This cleanup idea was suggested by Pieter Wuille and implemented by Anthony Towns. Co-authored-by: Pieter Wuille <pieter@wuille.net> Co-authored-by: Anthony Towns <aj@erisian.com.au>
Diffstat (limited to 'src/test/fuzz/util')
-rw-r--r--src/test/fuzz/util/net.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/fuzz/util/net.cpp b/src/test/fuzz/util/net.cpp
index 65bc336297..1545e11065 100644
--- a/src/test/fuzz/util/net.cpp
+++ b/src/test/fuzz/util/net.cpp
@@ -55,6 +55,27 @@ CAddress ConsumeAddress(FuzzedDataProvider& fuzzed_data_provider) noexcept
return {ConsumeService(fuzzed_data_provider), ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS), NodeSeconds{std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<uint32_t>()}}};
}
+template <typename P>
+P ConsumeDeserializationParams(FuzzedDataProvider& fuzzed_data_provider) noexcept
+{
+ constexpr std::array ADDR_ENCODINGS{
+ CNetAddr::Encoding::V1,
+ CNetAddr::Encoding::V2,
+ };
+ constexpr std::array ADDR_FORMATS{
+ CAddress::Format::Disk,
+ CAddress::Format::Network,
+ };
+ if constexpr (std::is_same_v<P, CNetAddr::SerParams>) {
+ return P{PickValue(fuzzed_data_provider, ADDR_ENCODINGS)};
+ }
+ if constexpr (std::is_same_v<P, CAddress::SerParams>) {
+ return P{{PickValue(fuzzed_data_provider, ADDR_ENCODINGS)}, PickValue(fuzzed_data_provider, ADDR_FORMATS)};
+ }
+}
+template CNetAddr::SerParams ConsumeDeserializationParams(FuzzedDataProvider&) noexcept;
+template CAddress::SerParams ConsumeDeserializationParams(FuzzedDataProvider&) noexcept;
+
FuzzedSock::FuzzedSock(FuzzedDataProvider& fuzzed_data_provider)
: m_fuzzed_data_provider{fuzzed_data_provider}, m_selectable{fuzzed_data_provider.ConsumeBool()}
{