diff options
author | Pieter Wuille <pieter@wuille.net> | 2021-11-01 16:32:53 -0400 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2021-11-29 17:58:53 -0500 |
commit | 568dd2f83900a11a4dbba1250722791a135bf0a9 (patch) | |
tree | b9091ef5f60075570c9f0e0c487282450e152ec0 /src/test | |
parent | 383d350bd5107bfe00e3b90a00cab9a3c1397c72 (diff) | |
download | bitcoin-568dd2f83900a11a4dbba1250722791a135bf0a9.tar.xz |
Replace MakeSpan helper with Span deduction guide
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/crypto_tests.cpp | 4 | ||||
-rw-r--r-- | src/test/net_tests.cpp | 140 | ||||
-rw-r--r-- | src/test/script_tests.cpp | 4 |
3 files changed, 74 insertions, 74 deletions
diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp index 1483bd3cb3..dfea73e87b 100644 --- a/src/test/crypto_tests.cpp +++ b/src/test/crypto_tests.cpp @@ -770,8 +770,8 @@ static void TestSHA3_256(const std::string& input, const std::string& output) int s1 = InsecureRandRange(in_bytes.size() + 1); int s2 = InsecureRandRange(in_bytes.size() + 1 - s1); int s3 = in_bytes.size() - s1 - s2; - sha.Write(MakeSpan(in_bytes).first(s1)).Write(MakeSpan(in_bytes).subspan(s1, s2)); - sha.Write(MakeSpan(in_bytes).last(s3)).Finalize(out); + sha.Write(Span{in_bytes}.first(s1)).Write(Span{in_bytes}.subspan(s1, s2)); + sha.Write(Span{in_bytes}.last(s3)).Finalize(out); BOOST_CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out)); } diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 29938d4ede..f8fa26d907 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()); diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index a89eab68e9..73c3a63c08 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -284,7 +284,7 @@ public: CScript scriptPubKey = script; if (wm == WitnessMode::PKH) { uint160 hash; - CHash160().Write(MakeSpan(script).subspan(1)).Finalize(hash); + CHash160().Write(Span{script}.subspan(1)).Finalize(hash); script = CScript() << OP_DUP << OP_HASH160 << ToByteVector(hash) << OP_EQUALVERIFY << OP_CHECKSIG; scriptPubKey = CScript() << witnessversion << ToByteVector(hash); } else if (wm == WitnessMode::SH) { @@ -1812,7 +1812,7 @@ BOOST_AUTO_TEST_CASE(bip341_keypath_test_vectors) BOOST_CHECK_EQUAL(HexStr(sighash), input["intermediary"]["sigHash"].get_str()); // To verify the sigmsg, hash the expected sigmsg, and compare it with the (expected) sighash. - BOOST_CHECK_EQUAL(HexStr((CHashWriter(HASHER_TAPSIGHASH) << MakeSpan(ParseHex(input["intermediary"]["sigMsg"].get_str()))).GetSHA256()), input["intermediary"]["sigHash"].get_str()); + BOOST_CHECK_EQUAL(HexStr((CHashWriter(HASHER_TAPSIGHASH) << Span{ParseHex(input["intermediary"]["sigMsg"].get_str())}).GetSHA256()), input["intermediary"]["sigHash"].get_str()); } } |