Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkdatasig_tests.cpp
Show All 13 Lines | |||||
#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{ | ||||
{0, STANDARD_SCRIPT_VERIFY_FLAGS, MANDATORY_SCRIPT_VERIFY_FLAGS}}; | {0, STANDARD_SCRIPT_VERIFY_FLAGS ^ SCRIPT_ENABLE_CHECKDATASIG, | ||||
deadalnix: It's probably better to do `& ~SCRIPT_ENABLE_CHECKDATASIG`
But more appropriately, just leave… | |||||
MANDATORY_SCRIPT_VERIFY_FLAGS}}; | |||||
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 35 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_CHECKDATASIG, original_stack, script, | ||||
deadalnixUnsubmitted Not Done Inline ActionsThis expect the flag to be present, so it sets it. deadalnix: This expect the flag to be present, so it sets it. | |||||
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, original_stack, script, SCRIPT_ERR_BAD_OPCODE); | ||||
deadalnixUnsubmitted Not Done Inline ActionsThis expects the flag to be absent, which happens to work due to the test cases provided, but this is actually where the problem is. This test should not assume anything particular about the input that it is given - or, if so, it should check for it in a design by contract fashion ( https://en.wikipedia.org/wiki/Design_by_contract ) deadalnix: This expects the flag to be absent, which happens to work due to the test cases provided, but… | |||||
// 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 163 Lines • Show Last 20 Lines |
It's probably better to do & ~SCRIPT_ENABLE_CHECKDATASIG
But more appropriately, just leave it standard and do the setting/clearing in the test.