Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkdatasig_tests.cpp
Show All 12 Lines | |||||
#include <array> | #include <array> | ||||
#include <bitset> | #include <bitset> | ||||
typedef std::vector<uint8_t> valtype; | typedef std::vector<uint8_t> valtype; | ||||
typedef std::vector<valtype> stacktype; | typedef std::vector<valtype> stacktype; | ||||
BOOST_FIXTURE_TEST_SUITE(checkdatasig_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(checkdatasig_tests, BasicTestingSetup) | ||||
std::array<uint32_t, 3> flagset{ | std::array<uint32_t, 3> flagset{{SCRIPT_ENABLE_CHECKDATASIG, | ||||
{0, STANDARD_SCRIPT_VERIFY_FLAGS, MANDATORY_SCRIPT_VERIFY_FLAGS}}; | STANDARD_SCRIPT_VERIFY_FLAGS, | ||||
MANDATORY_SCRIPT_VERIFY_FLAGS}}; | |||||
deadalnix: This very clearly doesn't check the same thing anymore. | |||||
MengerianAuthorUnsubmitted Done Inline ActionsI changed the test to subtract SCRIPT_ENABLE_CHECKDATASIG from flags during the tests, rather than adding it. So it ends up passing the same flags values into the test (assuming SCRIPT_ENABLE_CHECKDATASIG is included in STANDARD_SCRIPT_VERIFY_FLAGS and MANDATORY_SCRIPT_VERIFY_FLAGS). If we want CHECKDATASIG in STANDARD_SCRIPT_VERIFY_FLAGS only, and not in MANDATORY_SCRIPT_VERIFY_FLAGS, then I will have to re-jig the test in some other way. Mengerian: I changed the test to subtract SCRIPT_ENABLE_CHECKDATASIG from flags during the tests, rather… | |||||
const uint8_t vchPrivkey[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | const uint8_t vchPrivkey[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; | ||||
struct KeyData { | struct KeyData { | ||||
CKey privkey, privkeyC; | CKey privkey, privkeyC; | ||||
CPubKey pubkey, pubkeyC, pubkeyH; | CPubKey pubkey, pubkeyC, pubkeyH; | ||||
Show All 32 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, 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, original_stack, script, expected); | ||||
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 159 Lines • Show Last 20 Lines |
This very clearly doesn't check the same thing anymore.