mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
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).
This commit is contained in:
parent
50bc017040
commit
9cb687351f
3 changed files with 12 additions and 3 deletions
|
@ -25,6 +25,8 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using namespace util::hex_literals;
|
||||
|
||||
// Very simple block filter index sync benchmark, only using coinbase outputs.
|
||||
static void BlockFilterIndexSync(benchmark::Bench& bench)
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <univalue.h>
|
||||
|
||||
using namespace util::hex_literals;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue