aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHodlinator <172445034+hodlinator@users.noreply.github.com>2024-08-27 21:01:13 +0200
committerHodlinator <172445034+hodlinator@users.noreply.github.com>2024-08-28 19:11:59 +0200
commit9cb687351f7ff50d19b5c5997ed69cfdab75bbf2 (patch)
treef8a95f7c451d8a316f6fb2770885cc959d081a23 /src/test
parent50bc017040ae300c795e3709233b80619db24518 (diff)
downloadbitcoin-9cb687351f7ff50d19b5c5997ed69cfdab75bbf2.tar.xz
refactor: Prepare for ParseHex -> ""_hex scripted-diff
- Adds using namespace. - Extracts ToScript helper function from ScriptFromHex, to be used heavily in the next commit. - Changes ScriptFromHex from using ParseHex to TryParseHex, now asserting the string is valid. - Use even number of hex digits in comment (and apply replacement from next commit to only touch line once).
Diffstat (limited to 'src/test')
-rw-r--r--src/test/script_standard_tests.cpp1
-rw-r--r--src/test/script_tests.cpp12
2 files changed, 10 insertions, 3 deletions
diff --git a/src/test/script_standard_tests.cpp b/src/test/script_standard_tests.cpp
index 6befd9ba85..d06118946f 100644
--- a/src/test/script_standard_tests.cpp
+++ b/src/test/script_standard_tests.cpp
@@ -16,6 +16,7 @@
#include <univalue.h>
+using namespace util::hex_literals;
BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index a1267802b4..e141624b76 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -1356,10 +1356,16 @@ BOOST_AUTO_TEST_CASE(script_GetScriptAsm)
BOOST_CHECK_EQUAL(derSig + "83 " + pubKey, ScriptToAsmStr(CScript() << ToByteVector(ParseHex(derSig + "83")) << vchPubKey));
}
+template <typename T>
+CScript ToScript(const T& byte_container)
+{
+ auto span{MakeUCharSpan(byte_container)};
+ return {span.begin(), span.end()};
+}
+
static CScript ScriptFromHex(const std::string& str)
{
- std::vector<unsigned char> data = ParseHex(str);
- return CScript(data.begin(), data.end());
+ return ToScript(*Assert(TryParseHex(str)));
}
BOOST_AUTO_TEST_CASE(script_FindAndDelete)
@@ -1393,7 +1399,7 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
BOOST_CHECK(s == expect);
- s = ScriptFromHex("0302ff030302ff03"); // PUSH 0x2ff03 PUSH 0x2ff03
+ s = ToScript("0302ff030302ff03"_hex); // PUSH 0x02ff03 PUSH 0x02ff03
d = ScriptFromHex("0302ff03");
expect = CScript();
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);