Skip to content

Commit

Permalink
txscript: add/group bitwise logic, comparison & rotation op code tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnldd committed Jul 17, 2018
1 parent 65bd3ce commit 6a968b5
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions txscript/data/script_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,51 @@
["'abcdefghijklmnopqrstuvwxyz'", "SIZE 26 EQUAL", "NONE", "OK"],
["42", "SIZE 1 EQUALVERIFY 42 EQUAL", "NONE", "OK", "SIZE does not consume argument"],

["BITWISE LOGIC opcode tests"],

["INVERT test coverage"],
["1", "INVERT -2 EQUAL", "NONE", "OK"],
["0", "INVERT -1 EQUAL", "NONE", "OK"],
["", "INVERT 1", "NONE", "ERR_INVALID_STACK_OPERATION", "INVERT requires an input parameter"],
["'z'{2049}", "INVERT 1", "NONE", "ERR_PUSH_SIZE", "Exceed max parameter size"],

["ADD test coverage"],
["1 0", "ADD 1 EQUAL", "NONE", "OK"],
["1 1", "ADD 2 EQUAL", "NONE", "OK"],
["'z'{2049} 0", "ADD 1", "NONE", "ERR_PUSH_SIZE", "Exceed max parameter size"],
["1", "ADD 1", "NONE", "ERR_INVALID_STACK_OPERATION", "ADD requires two operands"],

["OR test coverage"],
["1 0", "OR 1 EQUAL", "NONE", "OK"],
["1 1", "OR 1 EQUAL", "NONE", "OK"],
["'z'{2049} 0", "OR 1", "NONE", "ERR_PUSH_SIZE", "Exceed max parameter size"],
["1", "OR 1", "NONE", "ERR_INVALID_STACK_OPERATION", "OR requires two operands"],

["XOR test coverage"],
["1 0", "XOR 1 EQUAL", "NONE", "OK"],
["1 1", "XOR 0 EQUAL", "NONE", "OK"],
["'z'{2049} 0", "XOR 1", "NONE", "ERR_PUSH_SIZE", "Exceed max parameter size"],
["1", "XOR 1", "NONE", "ERR_INVALID_STACK_OPERATION", "OR requires two operands"],

["BITWISE COMPARISON opcode tests"],

["EQUAL test coverage"],
["", "EQUAL 1", "NONE", "ERR_INVALID_STACK_OPERATION", "EQUAL must error when there are no stack items"],
["0", "EQUAL 1", "NONE", "ERR_INVALID_STACK_OPERATION", "EQUAL must error when there are not 2 stack items"],
["0 1","EQUAL", "NONE", "ERR_EVAL_FALSE"],
["1 1 ADD", "0 EQUAL", "NONE", "ERR_EVAL_FALSE"],
["11 1 ADD 12 SUB", "11 EQUAL", "NONE", "ERR_EVAL_FALSE"],

["0x52", "0x5f ADD 0x60 EQUAL", "NONE", "ERR_EVAL_FALSE", "0x51 through 0x60 push 1 through 16 onto stack"],
["EQUALVERIFY test coverage"],
["", "EQUALVERIFY 1", "NONE", "ERR_INVALID_STACK_OPERATION", "Empty stack"],
["'z'{2}", "EQUALVERIFY 1", "NONE", "ERR_INVALID_STACK_OPERATION", "EQUALVERIFY requires two operands"],
["'z'{2} 'z'{3}","EQUALVERIFY", "NONE", "ERR_EQUAL_VERIFY"],
["'z'{2} 'z'{2}","EQUALVERIFY 1", "NONE", "OK"],
["'z'{2049} 'z'{2}","EQUALVERIFY 1", "NONE", "ERR_PUSH_SIZE", "Exceed max allowed parameter size"],

["BITWISE ROTATION opcode tests"],

["Right bit rotation related test coverage"],
["ROTR test coverage"],
["-2147483647 1", "ROTR -1073741824 EQUAL", "NONE", "OK", "ROTR 0x80000001 >>> 1"],
["-2147483647 2", "ROTR 1610612736 EQUAL", "NONE", "OK", "ROTR 0x80000001 >>> 2"],
["-2147483647 3", "ROTR 805306368 EQUAL", "NONE", "OK", "ROTR 0x80000001 >>> 3"],
Expand Down Expand Up @@ -834,7 +874,7 @@
["2147483648 1", "ROTR 1073741824 EQUAL", "NONE", "ERR_OUT_OF_RANGE", "ROTR must fail with input value >4 bytes"],
["1 2147483648", "ROTR TRUE", "NONE", "ERR_OUT_OF_RANGE", "ROTR must fail with rotation count >4 bytes"],

["Left bit rotation related test coverage"],
["ROTL test coverage"],
["-2147483647 1", "ROTL 3 EQUAL", "NONE", "OK", "ROTL 0x80000001 <<< 1"],
["-2147483647 2", "ROTL 6 EQUAL", "NONE", "OK", "ROTL 0x80000001 <<< 2"],
["-2147483647 3", "ROTL 12 EQUAL", "NONE", "OK", "ROTL 0x80000001 <<< 3"],
Expand Down Expand Up @@ -878,6 +918,9 @@
["2147483648 1", "ROTL 1 EQUAL", "NONE", "ERR_OUT_OF_RANGE", "ROTL must fail with input value >4 bytes"],
["1 2147483648", "ROTL TRUE", "NONE", "ERR_OUT_OF_RANGE", "ROTL must fail with rotation count >4 bytes"],


["0x52", "0x5f ADD 0x60 EQUAL", "NONE", "ERR_EVAL_FALSE", "0x51 through 0x60 push 1 through 16 onto stack"],

["1 2 0 IF AND ELSE 1 ENDIF", "NOP", "NONE", "OK"],
["1 2 0 IF OR ELSE 1 ENDIF", "NOP", "NONE", "OK"],
["1 2 0 IF XOR ELSE 1 ENDIF", "NOP", "NONE", "OK"],
Expand Down Expand Up @@ -2321,12 +2364,6 @@

["NOP", "SIZE 1", "NONE", "ERR_INVALID_STACK_OPERATION"],

["", "EQUAL NOT", "NONE", "ERR_INVALID_STACK_OPERATION", "EQUAL must error when there are no stack items"],
["0", "EQUAL NOT", "NONE", "ERR_INVALID_STACK_OPERATION", "EQUAL must error when there are not 2 stack items"],
["0 1","EQUAL", "NONE", "ERR_EVAL_FALSE"],
["1 1 ADD", "0 EQUAL", "NONE", "ERR_EVAL_FALSE"],
["11 1 ADD 12 SUB", "11 EQUAL", "NONE", "ERR_EVAL_FALSE"],

["2147483648 0 ADD", "NOP", "NONE", "ERR_OUT_OF_RANGE", "Arithmetic operands must be in range [-2^31...2^31] "],
["-2147483648 0 ADD", "NOP", "NONE", "ERR_OUT_OF_RANGE", "Arithmetic operands must be in range [-2^31...2^31] "],
["2147483647 DUP ADD", "4294967294 NUMEQUAL", "NONE", "ERR_OUT_OF_RANGE", "NUMEQUAL must be in numeric range"],
Expand Down

0 comments on commit 6a968b5

Please sign in to comment.