diff --git a/src/test/monolith_opcodes_tests.cpp b/src/test/monolith_opcodes_tests.cpp --- a/src/test/monolith_opcodes_tests.cpp +++ b/src/test/monolith_opcodes_tests.cpp @@ -19,20 +19,24 @@ std::array flagset{ {0, STANDARD_SCRIPT_VERIFY_FLAGS, MANDATORY_SCRIPT_VERIFY_FLAGS}}; +static void CheckTestResult(uint32_t flags, const stacktype &original_stack, + const CScript &script, const stacktype &expected) { + BaseSignatureChecker sigchecker; + ScriptError err = SCRIPT_ERR_OK; + stacktype stack{original_stack}; + bool r = EvalScript(stack, script, flags, sigchecker, &err); + BOOST_CHECK(r); + BOOST_CHECK(stack == expected); +} + /** * General utility functions to check for script passing/failing. */ static void CheckTestResultForAllFlags(const stacktype &original_stack, const CScript &script, const stacktype &expected) { - BaseSignatureChecker sigchecker; - for (uint32_t flags : flagset) { - ScriptError err = SCRIPT_ERR_OK; - stacktype stack{original_stack}; - bool r = EvalScript(stack, script, flags, sigchecker, &err); - BOOST_CHECK(r); - BOOST_CHECK(stack == expected); + CheckTestResult(flags, original_stack, script, expected); } } @@ -627,6 +631,14 @@ CheckNum2BinError({{}, {0x09, 0x02}}, SCRIPT_ERR_PUSH_SIZE); + // NUM2BIN can't take negative sizes, for which it throws an error + // "Push value size limit exceeded" + CheckNum2BinError({{}, {0x81}}, SCRIPT_ERR_PUSH_SIZE); + // ... except for negative zero of course (without minimaldata flag) + CheckTestResult(0, {{0x00, 0x80}, {0x80}}, CScript() << OP_NUM2BIN, {{}}); + CheckTestResult(0, {{0x00, 0x80}, {0x00, 0x80}}, CScript() << OP_NUM2BIN, + {{}}); + // Check that the requested encoding is possible. CheckNum2BinError({{0xab, 0xcd, 0xef, 0x80}, {0x03}}, SCRIPT_ERR_IMPOSSIBLE_ENCODING);