aboutsummaryrefslogtreecommitdiff
path: root/src/test/net_tests.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-12-03 10:44:26 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-12-03 10:44:37 +0100
commit8b1de78577a02300340cec37e26cd6418ef6e645 (patch)
treeed76866aede610e6759fe76f841aa1613084aa56 /src/test/net_tests.cpp
parentfd1c9e26d30c0e7a891f63955fd42f61b4216cc0 (diff)
parent11daf6ceb1d9ea1f8d638b123eecfe39d162a7c3 (diff)
downloadbitcoin-8b1de78577a02300340cec37e26cd6418ef6e645.tar.xz
Merge bitcoin/bitcoin#23413: Replace MakeSpan helper with Span deduction guide
11daf6ceb1d9ea1f8d638b123eecfe39d162a7c3 More Span simplifications (Pieter Wuille) 568dd2f83900a11a4dbba1250722791a135bf0a9 Replace MakeSpan helper with Span deduction guide (Pieter Wuille) Pull request description: C++17 supports [user-defined deduction guides](https://en.cppreference.com/w/cpp/language/class_template_argument_deduction), allowing class constructors to be invoked without specifying class template arguments. Instead, the code can contain rules to infer the template arguments from the constructor argument types. This alleviates the need for the `MakeSpan` helper. Convert the existing MakeSpan rules into deduction rules for `Span` itself, and replace all invocations of `MakeSpan` with just `Span` ones. ACKs for top commit: MarcoFalke: re-ACK 11daf6ceb1d9ea1f8d638b123eecfe39d162a7c3 Only change is removing a hunk in the tests 🌕 Tree-SHA512: 10f3e82e4338f39d9b7b407cd11aac7ebe1e9191b58e3d7f4e5e338a4636c0e126b4a1d912127c7446f57ba356c8d6544482e47f97901efea6a54fffbfd7895f
Diffstat (limited to 'src/test/net_tests.cpp')
-rw-r--r--src/test/net_tests.cpp140
1 files changed, 70 insertions, 70 deletions
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index c5bd9c73fd..d0f0e7d50f 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -386,9 +386,9 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
s.SetVersion(s.GetVersion() | ADDRV2_FORMAT);
// Valid IPv4.
- s << MakeSpan(ParseHex("01" // network type (IPv4)
- "04" // address length
- "01020304")); // address
+ s << Span{ParseHex("01" // network type (IPv4)
+ "04" // address length
+ "01020304")}; // address
s >> addr;
BOOST_CHECK(addr.IsValid());
BOOST_CHECK(addr.IsIPv4());
@@ -397,35 +397,35 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
BOOST_REQUIRE(s.empty());
// Invalid IPv4, valid length but address itself is shorter.
- s << MakeSpan(ParseHex("01" // network type (IPv4)
- "04" // address length
- "0102")); // address
+ s << Span{ParseHex("01" // network type (IPv4)
+ "04" // address length
+ "0102")}; // address
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure, HasReason("end of data"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Invalid IPv4, with bogus length.
- s << MakeSpan(ParseHex("01" // network type (IPv4)
- "05" // address length
- "01020304")); // address
+ s << Span{ParseHex("01" // network type (IPv4)
+ "05" // address length
+ "01020304")}; // address
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("BIP155 IPv4 address with length 5 (should be 4)"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Invalid IPv4, with extreme length.
- s << MakeSpan(ParseHex("01" // network type (IPv4)
- "fd0102" // address length (513 as CompactSize)
- "01020304")); // address
+ s << Span{ParseHex("01" // network type (IPv4)
+ "fd0102" // address length (513 as CompactSize)
+ "01020304")}; // address
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("Address too long: 513 > 512"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Valid IPv6.
- s << MakeSpan(ParseHex("02" // network type (IPv6)
- "10" // address length
- "0102030405060708090a0b0c0d0e0f10")); // address
+ s << Span{ParseHex("02" // network type (IPv6)
+ "10" // address length
+ "0102030405060708090a0b0c0d0e0f10")}; // address
s >> addr;
BOOST_CHECK(addr.IsValid());
BOOST_CHECK(addr.IsIPv6());
@@ -434,10 +434,10 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
BOOST_REQUIRE(s.empty());
// Valid IPv6, contains embedded "internal".
- s << MakeSpan(ParseHex(
+ s << Span{ParseHex(
"02" // network type (IPv6)
"10" // address length
- "fd6b88c08724ca978112ca1bbdcafac2")); // address: 0xfd + sha256("bitcoin")[0:5] +
+ "fd6b88c08724ca978112ca1bbdcafac2")}; // address: 0xfd + sha256("bitcoin")[0:5] +
// sha256(name)[0:10]
s >> addr;
BOOST_CHECK(addr.IsInternal());
@@ -446,44 +446,44 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
BOOST_REQUIRE(s.empty());
// Invalid IPv6, with bogus length.
- s << MakeSpan(ParseHex("02" // network type (IPv6)
- "04" // address length
- "00")); // address
+ s << Span{ParseHex("02" // network type (IPv6)
+ "04" // address length
+ "00")}; // address
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("BIP155 IPv6 address with length 4 (should be 16)"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Invalid IPv6, contains embedded IPv4.
- s << MakeSpan(ParseHex("02" // network type (IPv6)
- "10" // address length
- "00000000000000000000ffff01020304")); // address
+ s << Span{ParseHex("02" // network type (IPv6)
+ "10" // address length
+ "00000000000000000000ffff01020304")}; // address
s >> addr;
BOOST_CHECK(!addr.IsValid());
BOOST_REQUIRE(s.empty());
// Invalid IPv6, contains embedded TORv2.
- s << MakeSpan(ParseHex("02" // network type (IPv6)
- "10" // address length
- "fd87d87eeb430102030405060708090a")); // address
+ s << Span{ParseHex("02" // network type (IPv6)
+ "10" // address length
+ "fd87d87eeb430102030405060708090a")}; // address
s >> addr;
BOOST_CHECK(!addr.IsValid());
BOOST_REQUIRE(s.empty());
// TORv2, no longer supported.
- s << MakeSpan(ParseHex("03" // network type (TORv2)
- "0a" // address length
- "f1f2f3f4f5f6f7f8f9fa")); // address
+ s << Span{ParseHex("03" // network type (TORv2)
+ "0a" // address length
+ "f1f2f3f4f5f6f7f8f9fa")}; // address
s >> addr;
BOOST_CHECK(!addr.IsValid());
BOOST_REQUIRE(s.empty());
// Valid TORv3.
- s << MakeSpan(ParseHex("04" // network type (TORv3)
- "20" // address length
- "79bcc625184b05194975c28b66b66b04" // address
- "69f7f6556fb1ac3189a79b40dda32f1f"
- ));
+ s << Span{ParseHex("04" // network type (TORv3)
+ "20" // address length
+ "79bcc625184b05194975c28b66b66b04" // address
+ "69f7f6556fb1ac3189a79b40dda32f1f"
+ )};
s >> addr;
BOOST_CHECK(addr.IsValid());
BOOST_CHECK(addr.IsTor());
@@ -493,20 +493,20 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
BOOST_REQUIRE(s.empty());
// Invalid TORv3, with bogus length.
- s << MakeSpan(ParseHex("04" // network type (TORv3)
- "00" // address length
- "00" // address
- ));
+ s << Span{ParseHex("04" // network type (TORv3)
+ "00" // address length
+ "00" // address
+ )};
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("BIP155 TORv3 address with length 0 (should be 32)"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Valid I2P.
- s << MakeSpan(ParseHex("05" // network type (I2P)
- "20" // address length
- "a2894dabaec08c0051a481a6dac88b64" // address
- "f98232ae42d4b6fd2fa81952dfe36a87"));
+ s << Span{ParseHex("05" // network type (I2P)
+ "20" // address length
+ "a2894dabaec08c0051a481a6dac88b64" // address
+ "f98232ae42d4b6fd2fa81952dfe36a87")};
s >> addr;
BOOST_CHECK(addr.IsValid());
BOOST_CHECK(addr.IsI2P());
@@ -516,20 +516,20 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
BOOST_REQUIRE(s.empty());
// Invalid I2P, with bogus length.
- s << MakeSpan(ParseHex("05" // network type (I2P)
- "03" // address length
- "00" // address
- ));
+ s << Span{ParseHex("05" // network type (I2P)
+ "03" // address length
+ "00" // address
+ )};
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("BIP155 I2P address with length 3 (should be 32)"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Valid CJDNS.
- s << MakeSpan(ParseHex("06" // network type (CJDNS)
- "10" // address length
- "fc000001000200030004000500060007" // address
- ));
+ s << Span{ParseHex("06" // network type (CJDNS)
+ "10" // address length
+ "fc000001000200030004000500060007" // address
+ )};
s >> addr;
BOOST_CHECK(addr.IsValid());
BOOST_CHECK(addr.IsCJDNS());
@@ -538,49 +538,49 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
BOOST_REQUIRE(s.empty());
// Invalid CJDNS, wrong prefix.
- s << MakeSpan(ParseHex("06" // network type (CJDNS)
- "10" // address length
- "aa000001000200030004000500060007" // address
- ));
+ s << Span{ParseHex("06" // network type (CJDNS)
+ "10" // address length
+ "aa000001000200030004000500060007" // address
+ )};
s >> addr;
BOOST_CHECK(addr.IsCJDNS());
BOOST_CHECK(!addr.IsValid());
BOOST_REQUIRE(s.empty());
// Invalid CJDNS, with bogus length.
- s << MakeSpan(ParseHex("06" // network type (CJDNS)
- "01" // address length
- "00" // address
- ));
+ s << Span{ParseHex("06" // network type (CJDNS)
+ "01" // address length
+ "00" // address
+ )};
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("BIP155 CJDNS address with length 1 (should be 16)"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Unknown, with extreme length.
- s << MakeSpan(ParseHex("aa" // network type (unknown)
- "fe00000002" // address length (CompactSize's MAX_SIZE)
- "01020304050607" // address
- ));
+ s << Span{ParseHex("aa" // network type (unknown)
+ "fe00000002" // address length (CompactSize's MAX_SIZE)
+ "01020304050607" // address
+ )};
BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason("Address too long: 33554432 > 512"));
BOOST_REQUIRE(!s.empty()); // The stream is not consumed on invalid input.
s.clear();
// Unknown, with reasonable length.
- s << MakeSpan(ParseHex("aa" // network type (unknown)
- "04" // address length
- "01020304" // address
- ));
+ s << Span{ParseHex("aa" // network type (unknown)
+ "04" // address length
+ "01020304" // address
+ )};
s >> addr;
BOOST_CHECK(!addr.IsValid());
BOOST_REQUIRE(s.empty());
// Unknown, with zero length.
- s << MakeSpan(ParseHex("aa" // network type (unknown)
- "00" // address length
- "" // address
- ));
+ s << Span{ParseHex("aa" // network type (unknown)
+ "00" // address length
+ "" // address
+ )};
s >> addr;
BOOST_CHECK(!addr.IsValid());
BOOST_REQUIRE(s.empty());