Changeset View
Changeset View
Standalone View
Standalone View
src/test/op_code.cpp
Show First 20 Lines • Show All 298 Lines • ▼ Show 20 Lines | void test_mod(uint32_t flags) { | ||||
//-56488123%321 = -148 | //-56488123%321 = -148 | ||||
//-56488123%3 = -1 | //-56488123%3 = -1 | ||||
//-56488123%564881230 = -56488123 | //-56488123%564881230 = -56488123 | ||||
test(script,stack_t{{0xbb,0xf0,0x5d,0x83},{0x41,0x01}},flags,stack_t{{0x94,0x80}}); | test(script,stack_t{{0xbb,0xf0,0x5d,0x83},{0x41,0x01}},flags,stack_t{{0x94,0x80}}); | ||||
test(script,stack_t{{0xbb,0xf0,0x5d,0x83},{0x03}},flags,stack_t{{0x81}}); | test(script,stack_t{{0xbb,0xf0,0x5d,0x83},{0x03}},flags,stack_t{{0x81}}); | ||||
test(script,stack_t{{0xbb,0xf0,0x5d,0x83},{0x4e,0x67,0xab,0x21}},flags,stack_t{{0xbb,0xf0,0x5d,0x83}}); | test(script,stack_t{{0xbb,0xf0,0x5d,0x83},{0x4e,0x67,0xab,0x21}},flags,stack_t{{0xbb,0xf0,0x5d,0x83}}); | ||||
} | } | ||||
/// OP_CAT | |||||
void test_cat(uint32_t flags) { | |||||
CScript script; | |||||
script << OP_CAT; | |||||
//two inputs required | |||||
test(script,stack_t(),flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | |||||
test(script,stack_t{{0x00}},flags,SCRIPT_ERR_INVALID_STACK_OPERATION); | |||||
//stack item with maximum length | |||||
item maxlength_item(MAX_SCRIPT_ELEMENT_SIZE, 0x00); | |||||
//Concatenation producing illegal sized output | |||||
{ | |||||
stack_t input_stack; | |||||
input_stack.push_back(maxlength_item); | |||||
item i; | |||||
i.push_back(0x00); | |||||
input_stack.push_back(i); | |||||
test(script,input_stack,flags,SCRIPT_ERR_PUSH_SIZE); | |||||
} | |||||
//Concatenation of a max-sized item with empty is legal | |||||
{ | |||||
stack_t input_stack; | |||||
input_stack.push_back(maxlength_item); | |||||
input_stack.push_back(item()); //empty item | |||||
test(script,input_stack,flags,stack_t{maxlength_item}); | |||||
} | |||||
{ | |||||
stack_t input_stack; | |||||
input_stack.push_back(item()); //empty item | |||||
input_stack.push_back(maxlength_item); | |||||
test(script,input_stack,flags,stack_t{maxlength_item}); | |||||
} | |||||
//Concatenation of a zero length operand | |||||
test(script,stack_t{{0x01},{}},flags,stack_t{{0x01}}); | |||||
test(script,stack_t{{},{0x01}},flags,stack_t{{0x01}}); | |||||
//Concatenation of two empty operands results in empty item | |||||
test(script,stack_t{{},{}},flags,stack_t{{}}); | |||||
// concatenating two operands generates the correct result | |||||
test(script,stack_t{{0x00},{0x00}},flags,stack_t{{0x00,0x00}}); | |||||
test(script,stack_t{{0x01},{0x02}},flags,stack_t{{0x01,0x02}}); | |||||
test(script,stack_t{{0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a},{0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14}},flags,stack_t{{0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14}}); | |||||
} | |||||
} | } | ||||
/// 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(0); | test_and(0); | ||||
Show All 25 Lines | |||||
BOOST_AUTO_TEST_CASE(op_mod) { | BOOST_AUTO_TEST_CASE(op_mod) { | ||||
test_mod(0); | test_mod(0); | ||||
test_mod(STANDARD_SCRIPT_VERIFY_FLAGS); | test_mod(STANDARD_SCRIPT_VERIFY_FLAGS); | ||||
test_mod(STANDARD_NOT_MANDATORY_VERIFY_FLAGS); | test_mod(STANDARD_NOT_MANDATORY_VERIFY_FLAGS); | ||||
test_mod(STANDARD_LOCKTIME_VERIFY_FLAGS); | test_mod(STANDARD_LOCKTIME_VERIFY_FLAGS); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(op_cat) { | |||||
test_cat(0); | |||||
test_cat(STANDARD_SCRIPT_VERIFY_FLAGS); | |||||
test_cat(STANDARD_NOT_MANDATORY_VERIFY_FLAGS); | |||||
test_cat(STANDARD_LOCKTIME_VERIFY_FLAGS); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() | ||||