Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkdatasig_tests.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
* General utility functions to check for script passing/failing. | * General utility functions to check for script passing/failing. | ||||
*/ | */ | ||||
static void CheckTestResultForAllFlags(const stacktype &original_stack, | static void CheckTestResultForAllFlags(const stacktype &original_stack, | ||||
const CScript &script, | const CScript &script, | ||||
const stacktype &expected) { | const stacktype &expected) { | ||||
for (uint32_t flags : flagset) { | for (uint32_t flags : flagset) { | ||||
// Make sure that we get a bad opcode when the activation flag is not | // Make sure that we get a bad opcode when the activation flag is not | ||||
// passed. | // passed. | ||||
CheckError(flags, original_stack, script, SCRIPT_ERR_BAD_OPCODE); | CheckError(flags & ~SCRIPT_ENABLE_CHECKDATASIG, original_stack, script, | ||||
SCRIPT_ERR_BAD_OPCODE); | |||||
// The script execute as expected if the opcodes are activated. | // The script execute as expected if the opcodes are activated. | ||||
CheckPass(flags | SCRIPT_ENABLE_CHECKDATASIG, original_stack, script, | CheckPass(flags | SCRIPT_ENABLE_CHECKDATASIG, original_stack, script, | ||||
expected); | expected); | ||||
} | } | ||||
} | } | ||||
static void CheckErrorForAllFlags(const stacktype &original_stack, | static void CheckErrorForAllFlags(const stacktype &original_stack, | ||||
const CScript &script, ScriptError expected) { | const CScript &script, ScriptError expected) { | ||||
for (uint32_t flags : flagset) { | for (uint32_t flags : flagset) { | ||||
// Make sure that we get a bad opcode when the activation flag is not | // Make sure that we get a bad opcode when the activation flag is not | ||||
// passed. | // passed. | ||||
CheckError(flags, original_stack, script, SCRIPT_ERR_BAD_OPCODE); | CheckError(flags & ~SCRIPT_ENABLE_CHECKDATASIG, original_stack, script, | ||||
SCRIPT_ERR_BAD_OPCODE); | |||||
// The script generates the proper error if the opcodes are activated. | // The script generates the proper error if the opcodes are activated. | ||||
CheckError(flags | SCRIPT_ENABLE_CHECKDATASIG, original_stack, script, | CheckError(flags | SCRIPT_ENABLE_CHECKDATASIG, original_stack, script, | ||||
expected); | expected); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(checkdatasig_test) { | BOOST_AUTO_TEST_CASE(checkdatasig_test) { | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | for (int i = 0; i < 4096; i++) { | ||||
// If we do not check, then it is accepted. | // If we do not check, then it is accepted. | ||||
CheckPass(flags, {nondersig, message, pubkeyC}, script, {}); | CheckPass(flags, {nondersig, message, pubkeyC}, script, {}); | ||||
CheckError(flags, {nondersig, message, pubkeyC}, scriptverify, | CheckError(flags, {nondersig, message, pubkeyC}, scriptverify, | ||||
SCRIPT_ERR_CHECKDATASIGVERIFY); | SCRIPT_ERR_CHECKDATASIGVERIFY); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(checkdatasig_inclusion_in_standard_and_mandatory_flags) { | |||||
BOOST_CHECK(!(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_ENABLE_CHECKDATASIG)); | |||||
BOOST_CHECK(!(MANDATORY_SCRIPT_VERIFY_FLAGS & SCRIPT_ENABLE_CHECKDATASIG)); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |