From 9fb6c7c05660cd27227af77b5269af2b0a2e9662 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 19 Aug 2024 21:46:41 +0200 Subject: [PATCH] scripted-diff: Replace ParseHex("str") -> HexLiteral("str") Ideally all call sites should accept std::byte instead of uint8_t but those transformations are left to future PRs. -BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's/\bParseHex(\("[^"]*"\))/HexLiteral\1/g' $(git grep -l ParseHex -- :src ':(exclude)src/test/util_tests.cpp') sed -i --regexp-extended 's/\bParseHex(\("[^"]*"\))/HexLiteral\1/g' $(git grep -l ParseHex -- :src ':(exclude)src/test/util_tests.cpp') sed -i --regexp-extended 's/\bParseHex(<[^>]*>)(\("[^"]*"\))/HexLiteral\1\2/g' $(git grep -l ParseHex -- :src ':(exclude)src/test/util_tests.cpp') sed -i --regexp-extended 's/\bScriptFromHex(\("[^"]*"\))/ToScript(HexLiteral\1)/g' src/test/script_tests.cpp -END VERIFY SCRIPT- Co-Authored-By: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Co-Authored-By: Ryan Ofsky --- src/bench/index_blockfilter.cpp | 2 +- src/test/bloom_tests.cpp | 56 +++++++++++----------- src/test/coins_tests.cpp | 4 +- src/test/crypto_tests.cpp | 4 +- src/test/script_standard_tests.cpp | 6 +-- src/test/script_tests.cpp | 62 ++++++++++++------------- src/wallet/test/wallet_crypto_tests.cpp | 20 ++++---- 7 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/bench/index_blockfilter.cpp b/src/bench/index_blockfilter.cpp index 86e37fd82f0099..a634e5b0771a3a 100644 --- a/src/bench/index_blockfilter.cpp +++ b/src/bench/index_blockfilter.cpp @@ -20,7 +20,7 @@ static void BlockFilterIndexSync(benchmark::Bench& bench) // Create more blocks int CHAIN_SIZE = 600; - CPubKey pubkey{ParseHex("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")}; + CPubKey pubkey{HexLiteral("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")}; CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey)); std::vector noTxns; for (int i = 0; i < CHAIN_SIZE - 100; i++) { diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index b21fcaad02892c..46239e384d0143 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -30,17 +30,17 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize) { CBloomFilter filter(3, 0.01, 0, BLOOM_UPDATE_ALL); - BOOST_CHECK_MESSAGE( !filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter should be empty!"); - filter.insert(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")); - BOOST_CHECK_MESSAGE( filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter doesn't contain just-inserted object!"); + BOOST_CHECK_MESSAGE( !filter.contains(HexLiteral("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter should be empty!"); + filter.insert(HexLiteral("99108ad8ed9bb6274d3980bab5a85c048f0950c8")); + BOOST_CHECK_MESSAGE( filter.contains(HexLiteral("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter doesn't contain just-inserted object!"); // One bit different in first byte - BOOST_CHECK_MESSAGE(!filter.contains(ParseHex("19108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter contains something it shouldn't!"); + BOOST_CHECK_MESSAGE(!filter.contains(HexLiteral("19108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter contains something it shouldn't!"); - filter.insert(ParseHex("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")); - BOOST_CHECK_MESSAGE(filter.contains(ParseHex("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")), "Bloom filter doesn't contain just-inserted object (2)!"); + filter.insert(HexLiteral("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")); + BOOST_CHECK_MESSAGE(filter.contains(HexLiteral("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")), "Bloom filter doesn't contain just-inserted object (2)!"); - filter.insert(ParseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")); - BOOST_CHECK_MESSAGE(filter.contains(ParseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")), "Bloom filter doesn't contain just-inserted object (3)!"); + filter.insert(HexLiteral("b9300670b4c5366e95b2699e8b18bc75e5f729c5")); + BOOST_CHECK_MESSAGE(filter.contains(HexLiteral("b9300670b4c5366e95b2699e8b18bc75e5f729c5")), "Bloom filter doesn't contain just-inserted object (3)!"); DataStream stream{}; stream << filter; @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize) constexpr auto expected{HexLiteral("03614e9b050000000000000001")}; BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end()); - BOOST_CHECK_MESSAGE( filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter doesn't contain just-inserted object!"); + BOOST_CHECK_MESSAGE( filter.contains(HexLiteral("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter doesn't contain just-inserted object!"); } BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak) @@ -56,16 +56,16 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak) // Same test as bloom_create_insert_serialize, but we add a nTweak of 100 CBloomFilter filter(3, 0.01, 2147483649UL, BLOOM_UPDATE_ALL); - filter.insert(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")); - BOOST_CHECK_MESSAGE( filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter doesn't contain just-inserted object!"); + filter.insert(HexLiteral("99108ad8ed9bb6274d3980bab5a85c048f0950c8")); + BOOST_CHECK_MESSAGE( filter.contains(HexLiteral("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter doesn't contain just-inserted object!"); // One bit different in first byte - BOOST_CHECK_MESSAGE(!filter.contains(ParseHex("19108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter contains something it shouldn't!"); + BOOST_CHECK_MESSAGE(!filter.contains(HexLiteral("19108ad8ed9bb6274d3980bab5a85c048f0950c8")), "Bloom filter contains something it shouldn't!"); - filter.insert(ParseHex("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")); - BOOST_CHECK_MESSAGE(filter.contains(ParseHex("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")), "Bloom filter doesn't contain just-inserted object (2)!"); + filter.insert(HexLiteral("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")); + BOOST_CHECK_MESSAGE(filter.contains(HexLiteral("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")), "Bloom filter doesn't contain just-inserted object (2)!"); - filter.insert(ParseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")); - BOOST_CHECK_MESSAGE(filter.contains(ParseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")), "Bloom filter doesn't contain just-inserted object (3)!"); + filter.insert(HexLiteral("b9300670b4c5366e95b2699e8b18bc75e5f729c5")); + BOOST_CHECK_MESSAGE(filter.contains(HexLiteral("b9300670b4c5366e95b2699e8b18bc75e5f729c5")), "Bloom filter doesn't contain just-inserted object (3)!"); DataStream stream{}; stream << filter; @@ -113,24 +113,24 @@ BOOST_AUTO_TEST_CASE(bloom_match) filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); // byte-reversed tx hash - filter.insert(ParseHex("6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4")); + filter.insert(HexLiteral("6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4")); BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized tx hash"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); - filter.insert(ParseHex("30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a01")); + filter.insert(HexLiteral("30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a01")); BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input signature"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); - filter.insert(ParseHex("046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339")); + filter.insert(HexLiteral("046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339")); BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input pub key"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); - filter.insert(ParseHex("04943fdd508053c75000106d3bc6e2754dbcff19")); + filter.insert(HexLiteral("04943fdd508053c75000106d3bc6e2754dbcff19")); BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address"); BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(spendingTx), "Simple Bloom filter didn't add output"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); - filter.insert(ParseHex("a266436d2965547608b9e15d9032a7b9d64fa431")); + filter.insert(HexLiteral("a266436d2965547608b9e15d9032a7b9d64fa431")); BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(bloom_match) BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random tx hash"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); - filter.insert(ParseHex("0000006d2965547608b9e15d9032a7b9d64fa431")); + filter.insert(HexLiteral("0000006d2965547608b9e15d9032a7b9d64fa431")); BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random address"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(merkle_block_2) // Match an output from the second transaction (the pubkey for address 1DZTzaBHUDM7T3QvUKBz4qXMRpkg8jsfB5) // This should match the third transaction because it spends the output matched // It also matches the fourth transaction, which spends to the pubkey again - filter.insert(ParseHex("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af")); + filter.insert(HexLiteral("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af")); merkleBlock = CMerkleBlock(block, filter); BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); @@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(merkle_block_2_with_update_none) // Match an output from the second transaction (the pubkey for address 1DZTzaBHUDM7T3QvUKBz4qXMRpkg8jsfB5) // This should not match the third transaction though it spends the output matched // It will match the fourth transaction, which has another pay-to-pubkey output to the same address - filter.insert(ParseHex("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af")); + filter.insert(HexLiteral("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af")); merkleBlock = CMerkleBlock(block, filter); BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); @@ -412,9 +412,9 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_p2pubkey_only) CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_P2PUBKEY_ONLY); // Match the generation pubkey - filter.insert(ParseHex("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91")); + filter.insert(HexLiteral("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91")); // ...and the output address of the 4th transaction - filter.insert(ParseHex("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); + filter.insert(HexLiteral("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); CMerkleBlock merkleBlock(block, filter); BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); @@ -437,9 +437,9 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none) CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_NONE); // Match the generation pubkey - filter.insert(ParseHex("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91")); + filter.insert(HexLiteral("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a2252247d97a46a91")); // ...and the output address of the 4th transaction - filter.insert(ParseHex("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); + filter.insert(HexLiteral("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); CMerkleBlock merkleBlock(block, filter); BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index a2a4ea7a22fde8..0188fc5aae61e6 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -512,7 +512,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization) BOOST_CHECK_EQUAL(cc1.fCoinBase, false); BOOST_CHECK_EQUAL(cc1.nHeight, 203998U); BOOST_CHECK_EQUAL(cc1.out.nValue, CAmount{60000000000}); - BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160(ParseHex("816115944e077fe7c803cfa57f29b36bf87c1d35")))))); + BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160(HexLiteral("816115944e077fe7c803cfa57f29b36bf87c1d35")))))); // Good example DataStream ss2{HexLiteral("8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4")}; @@ -521,7 +521,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization) BOOST_CHECK_EQUAL(cc2.fCoinBase, true); BOOST_CHECK_EQUAL(cc2.nHeight, 120891U); BOOST_CHECK_EQUAL(cc2.out.nValue, 110397); - BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160(ParseHex("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4")))))); + BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160(HexLiteral("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4")))))); // Smallest possible example DataStream ss3{HexLiteral("000006")}; diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp index f92fe847400c0d..9f715900ffe6e4 100644 --- a/src/test/crypto_tests.cpp +++ b/src/test/crypto_tests.cpp @@ -824,7 +824,7 @@ BOOST_AUTO_TEST_CASE(chacha20_testvector) BOOST_AUTO_TEST_CASE(chacha20_midblock) { - auto key = ParseHex("0000000000000000000000000000000000000000000000000000000000000000"); + auto key = HexLiteral("0000000000000000000000000000000000000000000000000000000000000000"); ChaCha20 c20{key}; // get one block of keystream std::byte block[64]; @@ -920,7 +920,7 @@ BOOST_AUTO_TEST_CASE(poly1305_testvector) { // mac of the macs of messages of length 0 to 256, where the key and messages have all // their values set to the length. - auto total_key = ParseHex("01020304050607fffefdfcfbfaf9ffffffffffffffffffffffffffff00000000"); + auto total_key = HexLiteral("01020304050607fffefdfcfbfaf9ffffffffffffffffffffffffffff00000000"); Poly1305 total_ctx(total_key); for (unsigned i = 0; i < 256; ++i) { std::vector key(32, std::byte{uint8_t(i)}); diff --git a/src/test/script_standard_tests.cpp b/src/test/script_standard_tests.cpp index be7066942b94c2..3816a6574460a6 100644 --- a/src/test/script_standard_tests.cpp +++ b/src/test/script_standard_tests.cpp @@ -389,9 +389,9 @@ BOOST_AUTO_TEST_CASE(script_standard_taproot_builder) BOOST_CHECK_EQUAL(TaprootBuilder::ValidDepths({128,128,127,126,125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}), true); BOOST_CHECK_EQUAL(TaprootBuilder::ValidDepths({129,129,128,127,126,125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}), false); - XOnlyPubKey key_inner{ParseHex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")}; - XOnlyPubKey key_1{ParseHex("c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5")}; - XOnlyPubKey key_2{ParseHex("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9")}; + XOnlyPubKey key_inner{HexLiteral("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")}; + XOnlyPubKey key_1{HexLiteral("c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5")}; + XOnlyPubKey key_2{HexLiteral("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9")}; CScript script_1 = CScript() << ToByteVector(key_1) << OP_CHECKSIG; CScript script_2 = CScript() << ToByteVector(key_2) << OP_CHECKSIG; constexpr uint256 hash_3{"31fe7061656bea2a36aa60a2f7ef940578049273746935d296426dc0afd86b68"}; diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index e82ba38fa8507d..8cdf59170afea3 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -1268,7 +1268,7 @@ BOOST_AUTO_TEST_CASE(sign_invalid_miniscript) // Create a Taproot output which contains a leaf in which a non-32 bytes push is used where a public key is expected // by the Miniscript parser. This offending Script was found by the RPC fuzzer. - const auto invalid_pubkey{ParseHex("173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292")}; + const auto invalid_pubkey{HexLiteral("173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292")}; TaprootBuilder builder; builder.Add(0, {invalid_pubkey}, 0xc0); builder.Finalize(XOnlyPubKey::NUMS_H); @@ -1391,60 +1391,60 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete) BOOST_CHECK_EQUAL(FindAndDelete(s, d), 4); BOOST_CHECK(s == expect); - s = ScriptFromHex("0302ff03"); // PUSH 0x02ff03 onto stack - d = ScriptFromHex("0302ff03"); + s = ToScript(HexLiteral("0302ff03")); // PUSH 0x02ff03 onto stack + d = ToScript(HexLiteral("0302ff03")); expect = CScript(); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1); BOOST_CHECK(s == expect); - s = ScriptFromHex("0302ff030302ff03"); // PUSH 0x02ff03 PUSH 0x02ff03 - d = ScriptFromHex("0302ff03"); + s = ToScript(HexLiteral("0302ff030302ff03")); // PUSH 0x02ff03 PUSH 0x02ff03 + d = ToScript(HexLiteral("0302ff03")); expect = CScript(); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2); BOOST_CHECK(s == expect); - s = ScriptFromHex("0302ff030302ff03"); - d = ScriptFromHex("02"); + s = ToScript(HexLiteral("0302ff030302ff03")); + d = ToScript(HexLiteral("02")); expect = s; // FindAndDelete matches entire opcodes BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0); BOOST_CHECK(s == expect); - s = ScriptFromHex("0302ff030302ff03"); - d = ScriptFromHex("ff"); + s = ToScript(HexLiteral("0302ff030302ff03")); + d = ToScript(HexLiteral("ff")); expect = s; BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0); BOOST_CHECK(s == expect); // This is an odd edge case: strip of the push-three-bytes // prefix, leaving 02ff03 which is push-two-bytes: - s = ScriptFromHex("0302ff030302ff03"); - d = ScriptFromHex("03"); + s = ToScript(HexLiteral("0302ff030302ff03")); + d = ToScript(HexLiteral("03")); expect = CScript() << Vec(HexLiteral("ff03")) << Vec(HexLiteral("ff03")); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2); BOOST_CHECK(s == expect); // Byte sequence that spans multiple opcodes: - s = ScriptFromHex("02feed5169"); // PUSH(0xfeed) OP_1 OP_VERIFY - d = ScriptFromHex("feed51"); + s = ToScript(HexLiteral("02feed5169")); // PUSH(0xfeed) OP_1 OP_VERIFY + d = ToScript(HexLiteral("feed51")); expect = s; BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0); // doesn't match 'inside' opcodes BOOST_CHECK(s == expect); - s = ScriptFromHex("02feed5169"); // PUSH(0xfeed) OP_1 OP_VERIFY - d = ScriptFromHex("02feed51"); - expect = ScriptFromHex("69"); + s = ToScript(HexLiteral("02feed5169")); // PUSH(0xfeed) OP_1 OP_VERIFY + d = ToScript(HexLiteral("02feed51")); + expect = ToScript(HexLiteral("69")); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1); BOOST_CHECK(s == expect); - s = ScriptFromHex("516902feed5169"); - d = ScriptFromHex("feed51"); + s = ToScript(HexLiteral("516902feed5169")); + d = ToScript(HexLiteral("feed51")); expect = s; BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0); BOOST_CHECK(s == expect); - s = ScriptFromHex("516902feed5169"); - d = ScriptFromHex("02feed51"); - expect = ScriptFromHex("516969"); + s = ToScript(HexLiteral("516902feed5169")); + d = ToScript(HexLiteral("02feed51")); + expect = ToScript(HexLiteral("516969")); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1); BOOST_CHECK(s == expect); @@ -1462,15 +1462,15 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete) // Another weird edge case: // End with invalid push (not enough data)... - s = ScriptFromHex("0003feed"); - d = ScriptFromHex("03feed"); // ... can remove the invalid push - expect = ScriptFromHex("00"); + s = ToScript(HexLiteral("0003feed")); + d = ToScript(HexLiteral("03feed")); // ... can remove the invalid push + expect = ToScript(HexLiteral("00")); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1); BOOST_CHECK(s == expect); - s = ScriptFromHex("0003feed"); - d = ScriptFromHex("00"); - expect = ScriptFromHex("03feed"); + s = ToScript(HexLiteral("0003feed")); + d = ToScript(HexLiteral("00")); + expect = ToScript(HexLiteral("03feed")); BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1); BOOST_CHECK(s == expect); } @@ -1479,13 +1479,13 @@ BOOST_AUTO_TEST_CASE(script_HasValidOps) { // Exercise the HasValidOps functionality CScript script; - script = ScriptFromHex("76a9141234567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac"); // Normal script + script = ToScript(HexLiteral("76a9141234567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac")); // Normal script BOOST_CHECK(script.HasValidOps()); - script = ScriptFromHex("76a914ff34567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac"); + script = ToScript(HexLiteral("76a914ff34567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac")); BOOST_CHECK(script.HasValidOps()); - script = ScriptFromHex("ff88ac"); // Script with OP_INVALIDOPCODE explicit + script = ToScript(HexLiteral("ff88ac")); // Script with OP_INVALIDOPCODE explicit BOOST_CHECK(!script.HasValidOps()); - script = ScriptFromHex("88acc0"); // Script with undefined opcode + script = ToScript(HexLiteral("88acc0")); // Script with undefined opcode BOOST_CHECK(!script.HasValidOps()); } diff --git a/src/wallet/test/wallet_crypto_tests.cpp b/src/wallet/test/wallet_crypto_tests.cpp index 416bedc0327fff..c8f711112d9234 100644 --- a/src/wallet/test/wallet_crypto_tests.cpp +++ b/src/wallet/test/wallet_crypto_tests.cpp @@ -75,9 +75,9 @@ static void TestEncrypt(const CCrypter& crypt, const std::span("0000deadbeef0000"), "test", 25000, + HexLiteral("fc7aba077ad5f4c3a0988d8daa4810d0d4a0e3bcb53af662998898f33df0556a"), + HexLiteral("cf2f2691526dd1aa220896fb8bf7c369")); std::string hash(GetRandHash().ToString()); std::vector vchSalt(8); @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(encrypt) { constexpr std::array salt{HexLiteral("0000deadbeef0000")}; CCrypter crypt; crypt.SetKeyFromPassphrase("passphrase", salt, 25000, 0); - TestCrypter::TestEncrypt(crypt, ParseHex("22bcade09ac03ff6386914359cfe885cfeb5f77ff0d670f102f619687453b29d")); + TestCrypter::TestEncrypt(crypt, HexLiteral("22bcade09ac03ff6386914359cfe885cfeb5f77ff0d670f102f619687453b29d")); for (int i = 0; i != 100; i++) { @@ -108,12 +108,12 @@ BOOST_AUTO_TEST_CASE(decrypt) { crypt.SetKeyFromPassphrase("passphrase", salt, 25000, 0); // Some corner cases the came up while testing - TestCrypter::TestDecrypt(crypt,ParseHex("795643ce39d736088367822cdc50535ec6f103715e3e48f4f3b1a60a08ef59ca")); - TestCrypter::TestDecrypt(crypt,ParseHex("de096f4a8f9bd97db012aa9d90d74de8cdea779c3ee8bc7633d8b5d6da703486")); - TestCrypter::TestDecrypt(crypt,ParseHex("32d0a8974e3afd9c6c3ebf4d66aa4e6419f8c173de25947f98cf8b7ace49449c")); - TestCrypter::TestDecrypt(crypt,ParseHex("e7c055cca2faa78cb9ac22c9357a90b4778ded9b2cc220a14cea49f931e596ea")); - TestCrypter::TestDecrypt(crypt,ParseHex("b88efddd668a6801d19516d6830da4ae9811988ccbaf40df8fbb72f3f4d335fd")); - TestCrypter::TestDecrypt(crypt,ParseHex("8cae76aa6a43694e961ebcb28c8ca8f8540b84153d72865e8561ddd93fa7bfa9")); + TestCrypter::TestDecrypt(crypt,HexLiteral("795643ce39d736088367822cdc50535ec6f103715e3e48f4f3b1a60a08ef59ca")); + TestCrypter::TestDecrypt(crypt,HexLiteral("de096f4a8f9bd97db012aa9d90d74de8cdea779c3ee8bc7633d8b5d6da703486")); + TestCrypter::TestDecrypt(crypt,HexLiteral("32d0a8974e3afd9c6c3ebf4d66aa4e6419f8c173de25947f98cf8b7ace49449c")); + TestCrypter::TestDecrypt(crypt,HexLiteral("e7c055cca2faa78cb9ac22c9357a90b4778ded9b2cc220a14cea49f931e596ea")); + TestCrypter::TestDecrypt(crypt,HexLiteral("b88efddd668a6801d19516d6830da4ae9811988ccbaf40df8fbb72f3f4d335fd")); + TestCrypter::TestDecrypt(crypt,HexLiteral("8cae76aa6a43694e961ebcb28c8ca8f8540b84153d72865e8561ddd93fa7bfa9")); for (int i = 0; i != 100; i++) {