Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkdatasig_tests.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | 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, 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_MAGNETIC_OPCODES, original_stack, | ||||
expected); | script, 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, 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_MAGNETIC_OPCODES, original_stack, | ||||
expected); | script, expected); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(checkdatasig_test) { | BOOST_AUTO_TEST_CASE(checkdatasig_test) { | ||||
// Empty stack. | // Empty stack. | ||||
CheckErrorForAllFlags({}, CScript() << OP_CHECKDATASIG, | CheckErrorForAllFlags({}, CScript() << OP_CHECKDATASIG, | ||||
SCRIPT_ERR_INVALID_STACK_OPERATION); | SCRIPT_ERR_INVALID_STACK_OPERATION); | ||||
CheckErrorForAllFlags({{0x00}}, CScript() << OP_CHECKDATASIG, | CheckErrorForAllFlags({{0x00}}, CScript() << OP_CHECKDATASIG, | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | const valtype highSSig{ | ||||
0x02, 0x21, 0x00, 0xab, 0x1e, 0x3d, 0xa7, 0x3d, 0x67, 0xe3, 0x20, 0x45, | 0x02, 0x21, 0x00, 0xab, 0x1e, 0x3d, 0xa7, 0x3d, 0x67, 0xe3, 0x20, 0x45, | ||||
0xa2, 0x0e, 0x0b, 0x99, 0x9e, 0x04, 0x99, 0x78, 0xea, 0x8d, 0x6e, 0xe5, | 0xa2, 0x0e, 0x0b, 0x99, 0x9e, 0x04, 0x99, 0x78, 0xea, 0x8d, 0x6e, 0xe5, | ||||
0x48, 0x0d, 0x48, 0x5f, 0xcf, 0x2c, 0xe0, 0xd0, 0x3b, 0x2e, 0xf0}; | 0x48, 0x0d, 0x48, 0x5f, 0xcf, 0x2c, 0xe0, 0xd0, 0x3b, 0x2e, 0xf0}; | ||||
// If we add many more flags, this loop can get too expensive, but we can | // If we add many more flags, this loop can get too expensive, but we can | ||||
// rewrite in the future to randomly pick a set of flags to evaluate. | // rewrite in the future to randomly pick a set of flags to evaluate. | ||||
for (uint32_t flags = 0; flags < (1U << 17); flags++) { | for (uint32_t flags = 0; flags < (1U << 17); flags++) { | ||||
// Make sure we activate the opcodes. | // Make sure we activate the opcodes. | ||||
flags |= SCRIPT_ENABLE_CHECKDATASIG; | flags |= SCRIPT_ENABLE_MAGNETIC_OPCODES; | ||||
if (flags & SCRIPT_VERIFY_STRICTENC) { | if (flags & SCRIPT_VERIFY_STRICTENC) { | ||||
// When strict encoding is enforced, hybrid key are invalid. | // When strict encoding is enforced, hybrid key are invalid. | ||||
CheckError(flags, {{}, message, pubkeyH}, script, | CheckError(flags, {{}, message, pubkeyH}, script, | ||||
SCRIPT_ERR_PUBKEYTYPE); | SCRIPT_ERR_PUBKEYTYPE); | ||||
CheckError(flags, {{}, message, pubkeyH}, scriptverify, | CheckError(flags, {{}, message, pubkeyH}, scriptverify, | ||||
SCRIPT_ERR_PUBKEYTYPE); | SCRIPT_ERR_PUBKEYTYPE); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |