Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2021-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <core_io.h>6#include <script/script.h>7#include <util/strencodings.h>8#include <test/util/common.h>10#include <boost/test/unit_test.hpp>12BOOST_AUTO_TEST_SUITE(script_parse_tests)13BOOST_AUTO_TEST_CASE(parse_script)14{15const std::vector<std::pair<std::string,std::string>> IN_OUT{16// {IN: script string , OUT: hex string }17{"", ""},18{"0", "00"},19{"1", "51"},20{"2", "52"},21{"3", "53"},22{"4", "54"},23{"5", "55"},24{"6", "56"},25{"7", "57"},26{"8", "58"},27{"9", "59"},28{"10", "5a"},29{"11", "5b"},30{"12", "5c"},31{"13", "5d"},32{"14", "5e"},33{"15", "5f"},34{"16", "60"},35{"17", "0111"},36{"-9", "0189"},37{"0x17", "17"},38{"'17'", "023137"},39{"ELSE", "67"},40{"NOP10", "b9"},41};42std::string all_in;43std::string all_out;44for (const auto& [in, out] : IN_OUT) {45BOOST_CHECK_EQUAL(HexStr(ParseScript(in)), out);46all_in += " " + in + " ";47all_out += out;48}49BOOST_CHECK_EQUAL(HexStr(ParseScript(all_in)), all_out);51BOOST_CHECK_EXCEPTION(ParseScript("11111111111111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF"));52BOOST_CHECK_EXCEPTION(ParseScript("11111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF"));53BOOST_CHECK_EXCEPTION(ParseScript("OP_CHECKSIGADD"), std::runtime_error, HasReason("script parse error: unknown opcode"));54}55BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.