Changeset View
Changeset View
Standalone View
Standalone View
src/test/op_code.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | void test(const CScript& script, stack_t stack, uint32_t flags, stack_t expected) { | ||||
cout << "got output stack: " << endl; | cout << "got output stack: " << endl; | ||||
print(stack); | print(stack); | ||||
#endif | #endif | ||||
BOOST_CHECK_EQUAL(r, true); | BOOST_CHECK_EQUAL(r, true); | ||||
BOOST_CHECK_EQUAL(err, SCRIPT_ERR_OK); | BOOST_CHECK_EQUAL(err, SCRIPT_ERR_OK); | ||||
BOOST_CHECK_EQUAL(stack==expected, true); | BOOST_CHECK_EQUAL(stack==expected, true); | ||||
} | } | ||||
/// OP_AND, OP_OR | /// OP_AND, OP_OR, OP_XOR | ||||
void test_bitwiseop(const CScript& script, uint32_t flags) { | void test_bitwiseop(const CScript& script, uint32_t flags) { | ||||
//number of inputs | //number of inputs | ||||
test(script,stack_t(),flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | test(script,stack_t(),flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | ||||
test(script,stack_t(),flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | test(script,stack_t(),flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | ||||
test(script,stack_t{{0x01}},flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | test(script,stack_t{{0x01}},flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | ||||
//where len(x1) == 0 == len(x2) the output will be an empty array. | //where len(x1) == 0 == len(x2) the output will be an empty array. | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | void test_or(uint32_t flags) { | ||||
item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x3C); | item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x3C); | ||||
item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xDB); | item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xDB); | ||||
item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x3C | 0xDB); | item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x3C | 0xDB); | ||||
test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); | test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); | ||||
} | } | ||||
} | } | ||||
/// OP_XOR tests | /// OP_XOR | ||||
void test_xor(uint32_t flags) { | void test_xor(uint32_t flags) { | ||||
CScript script; | CScript script; | ||||
script << OP_XOR; | script << OP_XOR; | ||||
test_bitwiseop(script,flags); | test_bitwiseop(script,flags); | ||||
test(script,stack_t{{0x00},{0x00}},flags,stack_t{{0x00}}); | test(script,stack_t{{0x00},{0x00}},flags,stack_t{{0x00}}); | ||||
test(script,stack_t{{0x00},{0x01}},flags,stack_t{{0x01}}); | test(script,stack_t{{0x00},{0x01}},flags,stack_t{{0x01}}); | ||||
▲ Show 20 Lines • Show All 413 Lines • ▼ Show 20 Lines | namespace { | ||||
void test_num2bin_bin2num(uint32_t flags) { | void test_num2bin_bin2num(uint32_t flags) { | ||||
test_num2bin_bin2num(4,flags); //4 byte num2bin output | test_num2bin_bin2num(4,flags); //4 byte num2bin output | ||||
test_num2bin_bin2num(3,flags); //3 byte num2bin output | test_num2bin_bin2num(3,flags); //3 byte num2bin output | ||||
test_num2bin_bin2num(2,flags); //2 byte num2bin output | test_num2bin_bin2num(2,flags); //2 byte num2bin output | ||||
test_num2bin_bin2num(1,flags); //1 byte num2bin output | test_num2bin_bin2num(1,flags); //1 byte num2bin output | ||||
} | } | ||||
void test_disabled_opcode(opcodetype opcode, uint32_t flags) { | |||||
CScript script; | |||||
script << opcode; | |||||
test(script,stack_t{{}},flags,SCRIPT_ERR_DISABLED_OPCODE); | |||||
} | |||||
void test_disabled_opcodes_before_may18_fork(uint32_t flags) { | |||||
assert((flags&SCRIPT_ENABLE_OPCODES0)==0); | |||||
test_disabled_opcode(OP_CAT,flags); | |||||
test_disabled_opcode(OP_SPLIT,flags); | |||||
test_disabled_opcode(OP_AND,flags); | |||||
test_disabled_opcode(OP_OR,flags); | |||||
test_disabled_opcode(OP_XOR,flags); | |||||
test_disabled_opcode(OP_DIV,flags); | |||||
test_disabled_opcode(OP_MOD,flags); | |||||
test_disabled_opcode(OP_NUM2BIN,flags); | |||||
test_disabled_opcode(OP_BIN2NUM,flags); | |||||
test_disabled_opcode(OP_INVERT,flags); | |||||
test_disabled_opcode(OP_2MUL,flags); | |||||
test_disabled_opcode(OP_2DIV,flags); | |||||
test_disabled_opcode(OP_MUL,flags); | |||||
test_disabled_opcode(OP_LSHIFT,flags); | |||||
test_disabled_opcode(OP_RSHIFT,flags); | |||||
} | |||||
void test_disabled_opcodes_after_may18_fork(uint32_t flags) { | |||||
assert((flags&SCRIPT_ENABLE_OPCODES0)!=0); | |||||
test_disabled_opcode(OP_INVERT,flags); | |||||
test_disabled_opcode(OP_2MUL,flags); | |||||
test_disabled_opcode(OP_2DIV,flags); | |||||
test_disabled_opcode(OP_MUL,flags); | |||||
test_disabled_opcode(OP_LSHIFT,flags); | |||||
test_disabled_opcode(OP_RSHIFT,flags); | |||||
} | |||||
} | } | ||||
/// Entry points | /// Entry points | ||||
BOOST_AUTO_TEST_SUITE(op_code) | BOOST_AUTO_TEST_SUITE(op_code) | ||||
BOOST_AUTO_TEST_CASE(op_and) { | BOOST_AUTO_TEST_CASE(op_and) { | ||||
test_and(SCRIPT_ENABLE_OPCODES0); | test_and(SCRIPT_ENABLE_OPCODES0); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
BOOST_AUTO_TEST_CASE(num2bin_bin2num) { | BOOST_AUTO_TEST_CASE(num2bin_bin2num) { | ||||
test_num2bin_bin2num(SCRIPT_ENABLE_OPCODES0); | test_num2bin_bin2num(SCRIPT_ENABLE_OPCODES0); | ||||
test_num2bin_bin2num(STANDARD_SCRIPT_VERIFY_FLAGS | SCRIPT_ENABLE_OPCODES0 | SCRIPT_ENABLE_OPCODES0); | test_num2bin_bin2num(STANDARD_SCRIPT_VERIFY_FLAGS | SCRIPT_ENABLE_OPCODES0 | SCRIPT_ENABLE_OPCODES0); | ||||
test_num2bin_bin2num(STANDARD_NOT_MANDATORY_VERIFY_FLAGS | SCRIPT_ENABLE_OPCODES0); | test_num2bin_bin2num(STANDARD_NOT_MANDATORY_VERIFY_FLAGS | SCRIPT_ENABLE_OPCODES0); | ||||
test_num2bin_bin2num(STANDARD_LOCKTIME_VERIFY_FLAGS | SCRIPT_ENABLE_OPCODES0); | test_num2bin_bin2num(STANDARD_LOCKTIME_VERIFY_FLAGS | SCRIPT_ENABLE_OPCODES0); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(disabled_opcodes) { | |||||
test_disabled_opcodes_before_may18_fork(0); | |||||
test_disabled_opcodes_before_may18_fork(STANDARD_SCRIPT_VERIFY_FLAGS); | |||||
test_disabled_opcodes_before_may18_fork(STANDARD_NOT_MANDATORY_VERIFY_FLAGS); | |||||
test_disabled_opcodes_before_may18_fork(STANDARD_LOCKTIME_VERIFY_FLAGS); | |||||
test_disabled_opcodes_after_may18_fork(0|SCRIPT_ENABLE_OPCODES0); | |||||
test_disabled_opcodes_after_may18_fork(STANDARD_SCRIPT_VERIFY_FLAGS|SCRIPT_ENABLE_OPCODES0); | |||||
test_disabled_opcodes_after_may18_fork(STANDARD_NOT_MANDATORY_VERIFY_FLAGS|SCRIPT_ENABLE_OPCODES0); | |||||
test_disabled_opcodes_after_may18_fork(STANDARD_LOCKTIME_VERIFY_FLAGS|SCRIPT_ENABLE_OPCODES0); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() | ||||