It isn’t strictly needed, because replacing the test-only ScriptFromHex
wasn’t a direct goal of this pull
It represents indirect use of ParseHex
with string literals.
It is incomplete, because it adds a bit of compile-time checking for the new paths using ToScript
, but leaves the checking out completely for the remaining ScriptFromHex
paths. It would be better to add the check data = *Assert(TryParseHex(str))
to ScriptFromHex
instead and drop this function.
Will add your suggestion to ScriptFromHex
. :+1:
It seems inconsistent and harder to read when there are two functions doing the exact same thing (turn hex into a script) in the same test case. (Are we going to duplicate every test-only helper just because there is a compile-time and a run-time checked function to to the same?)
They are not the same function (I know they were initially named very similarly though). With some adjustment one can be partially implemented using the other:
0template <typename T>
1CScript ToScript(const T& container)
2{
3 return {container.data(), container.data() + container.size()};
4}
5
6static CScript ScriptFromHex(const std::string& str)
7{
8 return ToScript(ParseHex(str));
9}
It makes the test more verbose
This is in part due to your suggestion of std::byte
defaults. Once that is fixed I don’t think…
0s = ToScript(HexLiteral("0302ff030302ff03"));
…will be too bad.
It makes the diff larger and review take longer
This is part of why we have scripted diffs, right?
Whereas the benefits are limited, because tests are deterministically executed, and this test runs faster than it compiles, so any errors are found similarly fast by the developer introducing them.
It’s down to “what can at low cost run at compile time, should”.
That said, I am open to not touching ScriptFromHex
-usages if you insist again (no need to motivate this time, just write :-1: ). Thank you for your patience.