aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-09-20 11:35:09 +0000
committerfanquake <fanquake@gmail.com>2023-09-20 11:38:56 +0000
commit1bf915db9930ff86aad90f449a06f5cc98a54da8 (patch)
treed3b5c8641c42fb773dcbc0de07b8457587b0a855 /src/test
parentabe4fedab735c145881e85dc2b02cf819a241635 (diff)
parentfad52baf1e9bf9d55a300922e73d3bc3169a8843 (diff)
Merge bitcoin/bitcoin#28470: fuzz: Rework addr fuzzing
fad52baf1e9bf9d55a300922e73d3bc3169a8843 fuzz: Rework addr fuzzing (MarcoFalke) fa5b6d29ee90911271d4304a6f39c38743a84f33 fuzz: Drop unused params from serialize helpers (MarcoFalke) Pull request description: Some minor fixups to addr fuzzing ACKs for top commit: dergoegge: utACK fad52baf1e9bf9d55a300922e73d3bc3169a8843 Tree-SHA512: 6a2b07fb1a65cf855d5e7c0a52bfcb81d46dbc5d4b3e72cef359987cbd28dbfeb2fc54f210e9737cb131b40ac5f88a90e9af284e441e0b37196121590bbaf015
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/deserialize.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp
index 100a6b4ee4..510ee7fb5b 100644
--- a/src/test/fuzz/deserialize.cpp
+++ b/src/test/fuzz/deserialize.cpp
@@ -91,9 +91,9 @@ void DeserializeFromFuzzingInput(FuzzBufferType buffer, T&& obj, const P& params
}
template <typename T>
-CDataStream Serialize(const T& obj, const int version = INIT_PROTO_VERSION, const int ser_type = SER_NETWORK)
+CDataStream Serialize(const T& obj)
{
- CDataStream ds(ser_type, version);
+ CDataStream ds{SER_NETWORK, INIT_PROTO_VERSION};
ds << obj;
return ds;
}
@@ -107,12 +107,10 @@ T Deserialize(CDataStream ds)
}
template <typename T>
-void DeserializeFromFuzzingInput(FuzzBufferType buffer, T&& obj, const std::optional<int> protocol_version = std::nullopt, const int ser_type = SER_NETWORK)
+void DeserializeFromFuzzingInput(FuzzBufferType buffer, T&& obj)
{
- CDataStream ds(buffer, ser_type, INIT_PROTO_VERSION);
- if (protocol_version) {
- ds.SetVersion(*protocol_version);
- } else {
+ CDataStream ds{buffer, SER_NETWORK, INIT_PROTO_VERSION};
+ {
try {
int version;
ds >> version;
@@ -135,9 +133,9 @@ void AssertEqualAfterSerializeDeserialize(const T& obj, const P& params)
assert(Deserialize<T>(Serialize(obj, params), params) == obj);
}
template <typename T>
-void AssertEqualAfterSerializeDeserialize(const T& obj, const int version = INIT_PROTO_VERSION, const int ser_type = SER_NETWORK)
+void AssertEqualAfterSerializeDeserialize(const T& obj)
{
- assert(Deserialize<T>(Serialize(obj, version, ser_type)) == obj);
+ assert(Deserialize<T>(Serialize(obj)) == obj);
}
} // namespace
@@ -254,7 +252,7 @@ FUZZ_TARGET(netaddr_deserialize, .init = initialize_deserialize)
if (!maybe_na) return;
const CNetAddr& na{*maybe_na};
if (na.IsAddrV1Compatible()) {
- AssertEqualAfterSerializeDeserialize(na, ConsumeDeserializationParams<CNetAddr::SerParams>(fdp));
+ AssertEqualAfterSerializeDeserialize(na, CNetAddr::V1);
}
AssertEqualAfterSerializeDeserialize(na, CNetAddr::V2);
}
@@ -266,7 +264,7 @@ FUZZ_TARGET(service_deserialize, .init = initialize_deserialize)
if (!maybe_s) return;
const CService& s{*maybe_s};
if (s.IsAddrV1Compatible()) {
- AssertEqualAfterSerializeDeserialize(s, ConsumeDeserializationParams<CNetAddr::SerParams>(fdp));
+ AssertEqualAfterSerializeDeserialize(s, CNetAddr::V1);
}
AssertEqualAfterSerializeDeserialize(s, CNetAddr::V2);
if (ser_params.enc == CNetAddr::Encoding::V1) {
@@ -281,8 +279,8 @@ FUZZ_TARGET_DESERIALIZE(messageheader_deserialize, {
FUZZ_TARGET(address_deserialize, .init = initialize_deserialize)
{
FuzzedDataProvider fdp{buffer.data(), buffer.size()};
- const auto ser_enc{ConsumeDeserializationParams<CNetAddr::SerParams>(fdp)};
- const auto maybe_a{ConsumeDeserializable<CAddress>(fdp, CAddress::SerParams{{ser_enc}, CAddress::Format::Network})};
+ const auto ser_enc{ConsumeDeserializationParams<CAddress::SerParams>(fdp)};
+ const auto maybe_a{ConsumeDeserializable<CAddress>(fdp, ser_enc)};
if (!maybe_a) return;
const CAddress& a{*maybe_a};
// A CAddress in V1 mode will roundtrip