Line data Source code
1 : // Copyright (c) 2021 The Bitcoin Core developers
2 : // Distributed under the MIT software license, see the accompanying
3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 :
5 : #include <core_io.h>
6 : #include <script/script.h>
7 : #include <util/strencodings.h>
8 : #include <test/util/setup_common.h>
9 :
10 : #include <boost/test/unit_test.hpp>
11 :
12 146 : BOOST_AUTO_TEST_SUITE(script_parse_tests)
13 148 : BOOST_AUTO_TEST_CASE(parse_script)
14 : {
15 1 : const std::vector<std::pair<std::string,std::string>> IN_OUT{
16 : // {IN: script string , OUT: hex string }
17 1 : {"", ""},
18 1 : {"0", "00"},
19 1 : {"1", "51"},
20 1 : {"2", "52"},
21 1 : {"3", "53"},
22 1 : {"4", "54"},
23 1 : {"5", "55"},
24 1 : {"6", "56"},
25 1 : {"7", "57"},
26 1 : {"8", "58"},
27 1 : {"9", "59"},
28 1 : {"10", "5a"},
29 1 : {"11", "5b"},
30 1 : {"12", "5c"},
31 1 : {"13", "5d"},
32 1 : {"14", "5e"},
33 1 : {"15", "5f"},
34 1 : {"16", "60"},
35 1 : {"17", "0111"},
36 1 : {"-9", "0189"},
37 1 : {"0x17", "17"},
38 1 : {"'17'", "023137"},
39 1 : {"ELSE", "67"},
40 1 : {"NOP10", "b9"},
41 : };
42 1 : std::string all_in;
43 1 : std::string all_out;
44 97 : for (const auto& [in, out] : IN_OUT) {
45 24 : BOOST_CHECK_EQUAL(HexStr(ParseScript(in)), out);
46 24 : all_in += " " + in + " ";
47 24 : all_out += out;
48 : }
49 1 : BOOST_CHECK_EQUAL(HexStr(ParseScript(all_in)), all_out);
50 :
51 1 : BOOST_CHECK_EXCEPTION(ParseScript("11111111111111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF"));
52 1 : BOOST_CHECK_EXCEPTION(ParseScript("11111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF"));
53 1 : BOOST_CHECK_EXCEPTION(ParseScript("OP_CHECKSIGADD"), std::runtime_error, HasReason("script parse error: unknown opcode"));
54 4 : }
55 146 : BOOST_AUTO_TEST_SUITE_END()
|