Index: src/test/data/script_tests.json =================================================================== --- src/test/data/script_tests.json +++ src/test/data/script_tests.json @@ -826,7 +826,6 @@ ["2 0 IF 2MUL ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "2MUL disabled"], ["2 0 IF 2DIV ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "2DIV disabled"], ["2 2 0 IF MUL ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "MUL disabled"], -["2 2 0 IF DIV ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "DIV disabled"], ["2 2 0 IF MOD ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "MOD disabled"], ["2 2 0 IF LSHIFT ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "LSHIFT disabled"], ["2 2 0 IF RSHIFT ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "RSHIFT disabled"], @@ -843,7 +842,6 @@ ["'abcdef' NOT", "0 EQUAL", "P2SH,STRICTENC", "UNKNOWN_ERROR", "NOT is an arithmetic operand"], ["2 DUP MUL", "4 EQUAL", "P2SH,STRICTENC", "DISABLED_OPCODE", "disabled"], -["2 DUP DIV", "1 EQUAL", "P2SH,STRICTENC", "DISABLED_OPCODE", "disabled"], ["2 2MUL", "4 EQUAL", "P2SH,STRICTENC", "DISABLED_OPCODE", "disabled"], ["2 2DIV", "1 EQUAL", "P2SH,STRICTENC", "DISABLED_OPCODE", "disabled"], ["7 3 MOD", "1 EQUAL", "P2SH,STRICTENC", "DISABLED_OPCODE", "disabled"], Index: src/test/op_code.cpp =================================================================== --- src/test/op_code.cpp +++ src/test/op_code.cpp @@ -2,9 +2,9 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "script/script.h" -#include "script/interpreter.h" #include "policy/policy.h" +#include "script/interpreter.h" +#include "script/script.h" #include #include @@ -15,193 +15,308 @@ #endif //-------------------------- -//uncomment the following line to see debug output +// uncomment the following line to see debug output //#define VERBOSE //-------------------------- #ifdef VERBOSE -#include -#include #include "core_io.h" +#include +#include #endif namespace { - typedef vector item; - typedef vector stack_t; - - #ifdef VERBOSE - void print(const item& i) { - if (i.empty()) cout << "empty"; - for (auto& s:i) cout << hex << setw(2) << setfill('0') << (int) s << " "; - cout << endl; - } - void print(const stack_t& i) { - for (auto& s:i) print(s); - cout << endl; - } - #endif - - /// Deepest sole function for testing expected errors - /// Invokes the interpreter. - void test(const CScript& script, stack_t stack, uint32_t flags, const ScriptError se) { - #ifdef VERBOSE - cout << "--------------" << endl; - cout << "Checking script \"" << FormatScript(script) << "\" flags " << flags << endl; - cout << "with input stack: " << endl; - print(stack); - cout << "expected error: " << se << endl; - #endif - ScriptError err=SCRIPT_ERR_OK; - BaseSignatureChecker sigchecker; - bool r=EvalScript(stack, script, flags, sigchecker, &err); - BOOST_CHECK_EQUAL(r, false); - #ifdef VERBOSE - cout << "got error: " << err << " vs " << se << endl; - #endif - BOOST_CHECK_EQUAL(err==se, true); - } +typedef vector item; +typedef vector stack_t; - /// Deepest sole function for testing expected returning stacks - /// Invokes the interpreter. - void test(const CScript& script, stack_t stack, uint32_t flags, stack_t expected) { - #ifdef VERBOSE - cout << "--------------" << endl; - cout << "Checking script \"" << FormatScript(script) << "\" flags " << flags << endl; - cout << "with input stack: " << endl; - print(stack); - cout << "expected output stack: " << endl; - print(expected); - #endif - ScriptError err; - BaseSignatureChecker sigchecker; - bool r=EvalScript(stack, script, flags, sigchecker, &err); - #ifdef VERBOSE - cout << "got output stack: " << endl; - print(stack); - #endif - BOOST_CHECK_EQUAL(r, true); - BOOST_CHECK_EQUAL(err, SCRIPT_ERR_OK); - BOOST_CHECK_EQUAL(stack==expected, true); +#ifdef VERBOSE +void print(const item &i) { + if (i.empty()) cout << "empty"; + for (auto &s : i) + cout << hex << setw(2) << setfill('0') << (int)s << " "; + cout << endl; +} +void print(const stack_t &i) { + for (auto &s : i) + print(s); + cout << endl; +} +#endif + +/// Deepest sole function for testing expected errors +/// Invokes the interpreter. +void test(const CScript &script, stack_t stack, uint32_t flags, + const ScriptError se) { +#ifdef VERBOSE + cout << "--------------" << endl; + cout << "Checking script \"" << FormatScript(script) << "\" flags " << flags + << endl; + cout << "with input stack: " << endl; + print(stack); + cout << "expected error: " << se << endl; +#endif + ScriptError err = SCRIPT_ERR_OK; + BaseSignatureChecker sigchecker; + bool r = EvalScript(stack, script, flags, sigchecker, &err); + BOOST_CHECK_EQUAL(r, false); +#ifdef VERBOSE + cout << "got error: " << err << " vs " << se << endl; +#endif + BOOST_CHECK_EQUAL(err == se, true); +} + +/// Deepest sole function for testing expected returning stacks +/// Invokes the interpreter. +void test(const CScript &script, stack_t stack, uint32_t flags, + stack_t expected) { +#ifdef VERBOSE + cout << "--------------" << endl; + cout << "Checking script \"" << FormatScript(script) << "\" flags " << flags + << endl; + cout << "with input stack: " << endl; + print(stack); + cout << "expected output stack: " << endl; + print(expected); +#endif + ScriptError err; + BaseSignatureChecker sigchecker; + bool r = EvalScript(stack, script, flags, sigchecker, &err); +#ifdef VERBOSE + cout << "got output stack: " << endl; + print(stack); +#endif + BOOST_CHECK_EQUAL(r, true); + BOOST_CHECK_EQUAL(err, SCRIPT_ERR_OK); + BOOST_CHECK_EQUAL(stack == expected, true); +} + +/// OP_AND, OP_OR + +void test_bitwiseop(const CScript &script, uint32_t flags) { + // 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{{0x01}}, flags, SCRIPT_ERR_INVALID_STACK_OPERATION); + + // where len(x1) == 0 == len(x2) the output will be an empty array. + test(script, stack_t{{}, {}}, flags, stack_t{{}}); + + // operation fails when length of operands not equal + test(script, stack_t{{0x01}, {}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{0x01, 0x01}, {}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{}, {0x01}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{}, {0x01, 0x01}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{0x01}, {0x01, 0x01}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{0x01, 0x01}, {0x01, 0x01, 0x01}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{0x01, 0x01}, {0x01}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); + test(script, stack_t{{0x01, 0x01, 0x01}, {0x01, 0x01}}, flags, + SCRIPT_ERR_INVALID_BITWISE_OPERATION); +} + +/// OP_AND + +void test_and(uint32_t flags) { + CScript script; + script << OP_AND; + test_bitwiseop(script, flags); + test(script, stack_t{{0x00}, {0x00}}, flags, stack_t{{0x00}}); + test(script, stack_t{{0x00}, {0x01}}, flags, stack_t{{0x00}}); + test(script, stack_t{{0x01}, {0x00}}, flags, stack_t{{0x00}}); + test(script, stack_t{{0x01}, {0x01}}, flags, stack_t{{0x01}}); + + test(script, stack_t{{0x00, 0x00}, {0x00, 0x00}}, flags, + stack_t{{0x00, 0x00}}); + test(script, stack_t{{0x00, 0x00}, {0x01, 0x00}}, flags, + stack_t{{0x00, 0x00}}); + test(script, stack_t{{0x01, 0x00}, {0x00, 0x00}}, flags, + stack_t{{0x00, 0x00}}); + test(script, stack_t{{0x01, 0x00}, {0x01, 0x00}}, flags, + stack_t{{0x01, 0x00}}); + + { + item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE, 0x01); + item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE, 0xF0); + item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE, 0x01 & 0xF0); + test(script, stack_t{maxlenbin1, maxlenbin2}, flags, + stack_t{maxlenbin3}); } - /// OP_AND, OP_OR - - void test_bitwiseop(const CScript& script, uint32_t flags) { - //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{{0x01}},flags,SCRIPT_ERR_INVALID_STACK_OPERATION); - - //where len(x1) == 0 == len(x2) the output will be an empty array. - test(script,stack_t{{},{}},flags,stack_t{{}}); - - //operation fails when length of operands not equal - test(script,stack_t{{0x01},{}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{0x01,0x01},{}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{},{0x01}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{},{0x01,0x01}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{0x01},{0x01,0x01}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{0x01,0x01},{0x01,0x01,0x01}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{0x01,0x01},{0x01}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); - test(script,stack_t{{0x01,0x01,0x01},{0x01,0x01}},flags,SCRIPT_ERR_INVALID_BITWISE_OPERATION); + { + item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE, 0x3C); + item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE, 0xDB); + item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE, 0x3C & 0xDB); + test(script, stack_t{maxlenbin1, maxlenbin2}, flags, + stack_t{maxlenbin3}); } +} - /// OP_AND - - void test_and(uint32_t flags) { - CScript script; - script << OP_AND; - test_bitwiseop(script,flags); - test(script,stack_t{{0x00},{0x00}},flags,stack_t{{0x00}}); - test(script,stack_t{{0x00},{0x01}},flags,stack_t{{0x00}}); - test(script,stack_t{{0x01},{0x00}},flags,stack_t{{0x00}}); - test(script,stack_t{{0x01},{0x01}},flags,stack_t{{0x01}}); - - test(script,stack_t{{0x00,0x00},{0x00,0x00}},flags,stack_t{{0x00,0x00}}); - test(script,stack_t{{0x00,0x00},{0x01,0x00}},flags,stack_t{{0x00,0x00}}); - test(script,stack_t{{0x01,0x00},{0x00,0x00}},flags,stack_t{{0x00,0x00}}); - test(script,stack_t{{0x01,0x00},{0x01,0x00}},flags,stack_t{{0x01,0x00}}); - - { - item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x01); - item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xF0); - item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x01 & 0xF0); - test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); - } - - { - item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x3C); - item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xDB); - item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x3C & 0xDB); - test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); - } +/// OP_OR + +void test_or(uint32_t flags) { + CScript script; + script << OP_OR; + test_bitwiseop(script, flags); + + test(script, stack_t{{0x00}, {0x00}}, flags, stack_t{{0x00}}); + test(script, stack_t{{0x00}, {0x01}}, flags, stack_t{{0x01}}); + test(script, stack_t{{0x01}, {0x00}}, flags, stack_t{{0x01}}); + test(script, stack_t{{0x01}, {0x01}}, flags, stack_t{{0x01}}); + + test(script, stack_t{{0x00, 0x00}, {0x00, 0x00}}, flags, + stack_t{{0x00, 0x00}}); + test(script, stack_t{{0x00, 0x00}, {0x01, 0x00}}, flags, + stack_t{{0x01, 0x00}}); + test(script, stack_t{{0x01, 0x00}, {0x00, 0x00}}, flags, + stack_t{{0x01, 0x00}}); + test(script, stack_t{{0x01, 0x00}, {0x01, 0x00}}, flags, + stack_t{{0x01, 0x00}}); + + { + item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE, 0x01); + item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE, 0xF0); + item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE, 0x01 | 0xF0); + test(script, stack_t{maxlenbin1, maxlenbin2}, flags, + stack_t{maxlenbin3}); } - /// OP_OR - - void test_or(uint32_t flags) { - CScript script; - script << OP_OR; - test_bitwiseop(script,flags); - - test(script,stack_t{{0x00},{0x00}},flags,stack_t{{0x00}}); - test(script,stack_t{{0x00},{0x01}},flags,stack_t{{0x01}}); - test(script,stack_t{{0x01},{0x00}},flags,stack_t{{0x01}}); - test(script,stack_t{{0x01},{0x01}},flags,stack_t{{0x01}}); - - test(script,stack_t{{0x00,0x00},{0x00,0x00}},flags,stack_t{{0x00,0x00}}); - test(script,stack_t{{0x00,0x00},{0x01,0x00}},flags,stack_t{{0x01,0x00}}); - test(script,stack_t{{0x01,0x00},{0x00,0x00}},flags,stack_t{{0x01,0x00}}); - test(script,stack_t{{0x01,0x00},{0x01,0x00}},flags,stack_t{{0x01,0x00}}); - - { - item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x01); - item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xF0); - item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x01 | 0xF0); - test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); - } - - { - item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x3C); - item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xDB); - item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x3C | 0xDB); - test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); - } + { + item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE, 0x3C); + item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE, 0xDB); + item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE, 0x3C | 0xDB); + test(script, stack_t{maxlenbin1, maxlenbin2}, flags, + stack_t{maxlenbin3}); + } +} +/// OP_XOR tests + +void test_xor(uint32_t flags) { + CScript script; + script << OP_XOR; + test_bitwiseop(script, flags); + + test(script, stack_t{{0x00}, {0x00}}, flags, stack_t{{0x00}}); + test(script, stack_t{{0x00}, {0x01}}, flags, stack_t{{0x01}}); + test(script, stack_t{{0x01}, {0x00}}, flags, stack_t{{0x01}}); + test(script, stack_t{{0x01}, {0x01}}, flags, stack_t{{0x00}}); + + test(script, stack_t{{0x00, 0x00}, {0x00, 0x00}}, flags, + stack_t{{0x00, 0x00}}); + test(script, stack_t{{0x00, 0x00}, {0x01, 0x00}}, flags, + stack_t{{0x01, 0x00}}); + test(script, stack_t{{0x01, 0x00}, {0x00, 0x00}}, flags, + stack_t{{0x01, 0x00}}); + test(script, stack_t{{0x01, 0x00}, {0x01, 0x00}}, flags, + stack_t{{0x00, 0x00}}); + + { + item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE, 0x01); + item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE, 0xF0); + item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE, 0x01 ^ 0xF0); + test(script, stack_t{maxlenbin1, maxlenbin2}, flags, + stack_t{maxlenbin3}); } - /// OP_XOR tests - - void test_xor(uint32_t flags) { - CScript script; - script << OP_XOR; - test_bitwiseop(script,flags); - - test(script,stack_t{{0x00},{0x00}},flags,stack_t{{0x00}}); - test(script,stack_t{{0x00},{0x01}},flags,stack_t{{0x01}}); - test(script,stack_t{{0x01},{0x00}},flags,stack_t{{0x01}}); - test(script,stack_t{{0x01},{0x01}},flags,stack_t{{0x00}}); - - test(script,stack_t{{0x00,0x00},{0x00,0x00}},flags,stack_t{{0x00,0x00}}); - test(script,stack_t{{0x00,0x00},{0x01,0x00}},flags,stack_t{{0x01,0x00}}); - test(script,stack_t{{0x01,0x00},{0x00,0x00}},flags,stack_t{{0x01,0x00}}); - test(script,stack_t{{0x01,0x00},{0x01,0x00}},flags,stack_t{{0x00,0x00}}); - - { - item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x01); - item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xF0); - item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x01 ^ 0xF0); - test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); - } - - { - item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE,0x3C); - item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE,0xDB); - item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE,0x3C ^ 0xDB); - test(script,stack_t{maxlenbin1,maxlenbin2},flags,stack_t{maxlenbin3}); - } + { + item maxlenbin1(MAX_SCRIPT_ELEMENT_SIZE, 0x3C); + item maxlenbin2(MAX_SCRIPT_ELEMENT_SIZE, 0xDB); + item maxlenbin3(MAX_SCRIPT_ELEMENT_SIZE, 0x3C ^ 0xDB); + test(script, stack_t{maxlenbin1, maxlenbin2}, flags, + stack_t{maxlenbin3}); } +} +/// OP_DIV tests + +void test_div(uint32_t flags) { + CScript script; + script << OP_DIV; + + test(script, stack_t(), flags, SCRIPT_ERR_INVALID_STACK_OPERATION); + test(script, stack_t{{}}, flags, SCRIPT_ERR_INVALID_STACK_OPERATION); + + // test not valid numbers + test(script, stack_t{{0x01, 0x02, 0x03, 0x04, 0x05}, + {0x01, 0x02, 0x03, 0x04, 0x05}}, + flags, SCRIPT_ERR_UNKNOWN_ERROR); + test(script, stack_t{{0x01, 0x02, 0x03, 0x04, 0x05}, {0x01}}, flags, + SCRIPT_ERR_UNKNOWN_ERROR); + test(script, stack_t{{0x01, 0x05}, {0x01, 0x02, 0x03, 0x04, 0x05}}, flags, + SCRIPT_ERR_UNKNOWN_ERROR); + // b == 0 ; b is equal to any type of zero + test(script, stack_t{{0x01, 0x05}, {}}, flags, SCRIPT_ERR_DIV_BY_ZERO); + test(script, stack_t{{}, {}}, flags, SCRIPT_ERR_DIV_BY_ZERO); + if (flags & SCRIPT_VERIFY_MINIMALDATA) { + test(script, stack_t{{}, {0x00}}, flags, + SCRIPT_ERR_UNKNOWN_ERROR); // not minimal encoding + test(script, stack_t{{}, {0x00, 0x00}}, flags, + SCRIPT_ERR_UNKNOWN_ERROR); + } else { + test(script, stack_t{{}, {0x00}}, flags, SCRIPT_ERR_DIV_BY_ZERO); + test(script, stack_t{{}, {0x00, 0x00}}, flags, SCRIPT_ERR_DIV_BY_ZERO); + } + // 185377af/85f41b01 =-4 + // 185377af/00001b01 =E69D + test(script, stack_t{{0xaf, 0x77, 0x53, 0x18}, {0x01, 0x1b, 0xf4, 0x85}}, + flags, stack_t{{0x84}}); + test(script, stack_t{{0xaf, 0x77, 0x53, 0x18}, {0x01, 0x1b}}, flags, + stack_t{{0x9D, 0xE6, 0x00}}); + // 15/4 =3 + // 15/-4 =-3 + //-15/4 =-3 + //-15/-4 =3 + test(script, stack_t{{0x0f}, {0x04}}, flags, stack_t{{0x03}}); + test(script, stack_t{{0x0f}, {0x84}}, flags, stack_t{{0x83}}); + test(script, stack_t{{0x8f}, {0x04}}, flags, stack_t{{0x83}}); + test(script, stack_t{{0x8f}, {0x84}}, flags, stack_t{{0x03}}); + // 15000/4 =3750 + // 15000/-4 =-3750 + //-15000/4 =-3750 + //-15000/-4 =3750 + test(script, stack_t{{0x98, 0x3a}, {0x04}}, flags, stack_t{{0xa6, 0x0e}}); + test(script, stack_t{{0x98, 0x3a}, {0x84}}, flags, stack_t{{0xa6, 0x8e}}); + test(script, stack_t{{0x98, 0xba}, {0x04}}, flags, stack_t{{0xa6, 0x8e}}); + test(script, stack_t{{0x98, 0xba}, {0x84}}, flags, stack_t{{0xa6, 0x0e}}); + // 15000/4000 =3 + // 15000/-4000 =-3 + //-15000/4000 =-3 + //-15000/-4000 =3 + test(script, stack_t{{0x98, 0x3a}, {0xa0, 0x0f}}, flags, stack_t{{0x03}}); + test(script, stack_t{{0x98, 0x3a}, {0xa0, 0x8f}}, flags, stack_t{{0x83}}); + test(script, stack_t{{0x98, 0xba}, {0xa0, 0x0f}}, flags, stack_t{{0x83}}); + test(script, stack_t{{0x98, 0xba}, {0xa0, 0x8f}}, flags, stack_t{{0x03}}); + // 15000000/4000 =3750 + // 15000000/-4000 =-3750 + //-15000000/4000 =-3750 + //-15000000/-4000 =3750 + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x00}, {0xa0, 0x0f}}, flags, + stack_t{{0xa6, 0x0e}}); + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x00}, {0xa0, 0x8f}}, flags, + stack_t{{0xa6, 0x8e}}); + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x80}, {0xa0, 0x0f}}, flags, + stack_t{{0xa6, 0x8e}}); + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x80}, {0xa0, 0x8f}}, flags, + stack_t{{0xa6, 0x0e}}); + // 15000000/4 =3750000 + // 15000000/-4 =-3750000 + //-15000000/4 =-3750000 + //-15000000/-4 =3750000 + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x00}, {0x04}}, flags, + stack_t{{0x70, 0x38, 0x39}}); + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x00}, {0x84}}, flags, + stack_t{{0x70, 0x38, 0xb9}}); + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x80}, {0x04}}, flags, + stack_t{{0x70, 0x38, 0xb9}}); + test(script, stack_t{{0xc0, 0xe1, 0xe4, 0x80}, {0x84}}, flags, + stack_t{{0x70, 0x38, 0x39}}); +} } /// Entry points @@ -229,5 +344,11 @@ test_xor(STANDARD_LOCKTIME_VERIFY_FLAGS); } -BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_CASE(op_div) { + test_div(0); + test_div(STANDARD_SCRIPT_VERIFY_FLAGS); + test_div(STANDARD_NOT_MANDATORY_VERIFY_FLAGS); + test_div(STANDARD_LOCKTIME_VERIFY_FLAGS); +} +BOOST_AUTO_TEST_SUITE_END()