Lots more Script unit test cases.

This commit is contained in:
Gavin Andresen 2012-05-24 17:32:09 -04:00
parent f04017f702
commit 6b8a17119e
3 changed files with 228 additions and 8 deletions

View File

@ -3,6 +3,110 @@
["", "NOP"],
["NOP", ""],
["NOP","NOP"],
["0x4c01","0x01 NOP", "PUSHDATA1 with not enough bytes"],
["0x4d0200ff","0x01 NOP", "PUSHDATA2 with not enough bytes"],
["0x4e03000000ffff","0x01 NOP", "PUSHDATA4 with not enough bytes"],
["1", "IF 0x50 ENDIF 1", "0x50 is reserved"],
["0x52", "0x5f ADD 0x60 EQUAL", "0x51 through 0x60 push 1 through 16 onto stack"],
["0","NOP"],
["1", "IF VER ELSE 1 ENDIF", "VER non-functional"],
["0", "IF VERIF ELSE 1 ENDIF", "VERIF illegal everywhere"],
["0", "IF VERNOTIF ELSE 1 ENDIF", "VERNOT illegal everywhere"],
["1 IF", "1 ENDIF", "IF/ENDIF can't span scriptSig/scriptPubKey"],
["1 IF 0 ENDIF", "1 ENDIF"],
["1 ELSE 0 ENDIF", "1"],
["0 NOTIF", "123"],
["0", "DUP IF ENDIF"],
["0", "IF 1 ENDIF"],
["0", "DUP IF ELSE ENDIF"],
["0", "IF 1 ELSE ENDIF"],
["0", "NOTIF ELSE 1 ENDIF"],
["0 1", "IF IF 1 ELSE 0 ENDIF ENDIF"],
["0 0", "IF IF 1 ELSE 0 ENDIF ENDIF"],
["1 0", "IF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["0 1", "IF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["0 0", "NOTIF IF 1 ELSE 0 ENDIF ENDIF"],
["0 1", "NOTIF IF 1 ELSE 0 ENDIF ENDIF"],
["1 1", "NOTIF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["0 0", "NOTIF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["1", "RETURN"],
["1", "DUP IF RETURN ENDIF"],
["0", "VERIFY 1"],
["1", "VERIFY"],
["1", "VERIFY 0"],
["1 TOALTSTACK", "FROMALTSTACK 1", "alt stack not shared between sig/pubkey"],
["IFDUP", "DEPTH 0 EQUAL"],
["DROP", "DEPTH 0 EQUAL"],
["DUP", "DEPTH 0 EQUAL"],
["1", "DUP 1 ADD 2 EQUALVERIFY 0 EQUAL"],
["NOP", "NIP"],
["NOP", "1 NIP"],
["NOP", "1 0 NIP"],
["NOP", "OVER 1"],
["1", "OVER"],
["0 1", "OVER DEPTH 3 EQUALVERIFY"],
["19 20 21", "PICK 19 EQUALVERIFY DEPTH 2 EQUAL"],
["NOP", "0 PICK"],
["1", "-1 PICK"],
["19 20 21", "0 PICK 20 EQUALVERIFY DEPTH 3 EQUAL"],
["19 20 21", "1 PICK 21 EQUALVERIFY DEPTH 3 EQUAL"],
["19 20 21", "2 PICK 22 EQUALVERIFY DEPTH 3 EQUAL"],
["NOP", "0 ROLL"],
["1", "-1 ROLL"],
["19 20 21", "0 ROLL 20 EQUALVERIFY DEPTH 2 EQUAL"],
["19 20 21", "1 ROLL 21 EQUALVERIFY DEPTH 2 EQUAL"],
["19 20 21", "2 ROLL 22 EQUALVERIFY DEPTH 2 EQUAL"],
["NOP", "ROT 1"],
["NOP", "1 ROT 1"],
["NOP", "1 2 ROT 1"],
["NOP", "0 1 2 ROT"],
["NOP", "SWAP 1"],
["1", "SWAP 1"],
["0 1", "SWAP 1 EQUALVERIFY"],
["NOP", "TUCK 1"],
["1", "TUCK 1"],
["1 0", "TUCK DEPTH 3 EQUALVERIFY SWAP 2DROP"],
["NOP", "2DUP 1"],
["1", "2DUP 1"],
["NOP", "3DUP 1"],
["1", "3DUP 1"],
["1 2", "3DUP 1"],
["NOP", "2OVER 1"],
["1", "2 3 2OVER 1"],
["NOP", "2SWAP 1"],
["1", "2 3 2SWAP 1"],
["'a' 'b'", "CAT", "CAT disabled"],
["'a' 'b' 0", "IF CAT ELSE 1 ENDIF", "CAT disabled"],
["'abc' 1 1", "SUBSTR", "SUBSTR disabled"],
["'abc' 1 1 0", "IF SUBSTR ELSE 1 ENDIF", "SUBSTR disabled"],
["'abc' 2 0", "IF LEFT ELSE 1 ENDIF", "LEFT disabled"],
["'abc' 2 0", "IF RIGHT ELSE 1 ENDIF", "RIGHT disabled"],
["NOP", "SIZE 1"],
["'abc'", "IF INVERT ELSE 1 ENDIF", "INVERT disabled"],
["1 2 0 IF AND ELSE 1 ENDIF", "NOP", "AND disabled"],
["1 2 0 IF OR ELSE 1 ENDIF", "NOP", "OR disabled"],
["1 2 0 IF XOR ELSE 1 ENDIF", "NOP", "XOR disabled"],
["2 0 IF 2MUL ELSE 1 ENDIF", "NOP", "2MUL disabled"],
["2 0 IF 2DIV ELSE 1 ENDIF", "NOP", "2DIV disabled"],
["2 2 0 IF MUL ELSE 1 ENDIF", "NOP", "MUL disabled"],
["2 2 0 IF DIV ELSE 1 ENDIF", "NOP", "DIV disabled"],
["2 2 0 IF MOD ELSE 1 ENDIF", "NOP", "MOD disabled"],
["2 2 0 IF LSHIFT ELSE 1 ENDIF", "NOP", "LSHIFT disabled"],
["2 2 0 IF RSHIFT ELSE 1 ENDIF", "NOP", "RSHIFT disabled"],
["0 1","EQUAL"],
["1 1 ADD", "0 EQUAL"],
["11 1 ADD 12 SUB", "11 EQUAL"],
@ -24,6 +128,19 @@
["'NOP_1_to_10' NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10","'NOP_1_to_11' EQUAL"],
["0x50","1", "opcode 0x50 is reserved"],
["1", "IF 0xba ELSE 1 ENDIF", "opcodes above NOP10 invalid"],
["1", "IF 0xc0 ELSE 1 ENDIF"],
["1", "IF 0xd1 ELSE 1 ENDIF"],
["1", "IF 0xee ELSE 1 ENDIF"],
["1", "IF 0xfd ELSE 1 ENDIF"],
["1", "IF 0xff ELSE 1 ENDIF"],
["NOP", "RIPEMD160"],
["NOP", "SHA1"],
["NOP", "SHA256"],
["NOP", "HASH160"],
["NOP", "HASH256"],
["NOP1","NOP10"]
]

View File

@ -1,17 +1,91 @@
[
["0x4c0107","7 EQUAL", "0x4c is OP_PUSHDATA1"],
["0x4d010008","8 EQUAL", "0x4d is OP_PUSHDATA2"],
["0x4e0100000009","9 EQUAL", "0x4e is OP_PUSHDATA4"],
["0x01 0x0b", "11 EQUAL", "push 1 byte"],
["0x02 0x417a", "'Az' EQUAL"],
["0x4b 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a",
"'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' EQUAL", "push 75 bytes"],
["0x4c 0x01 0x07","7 EQUAL", "0x4c is OP_PUSHDATA1"],
["0x4d 0x0100 0x08","8 EQUAL", "0x4d is OP_PUSHDATA2"],
["0x4e 0x01000000 0x09","9 EQUAL", "0x4e is OP_PUSHDATA4"],
["0x4c 0x00","0 EQUAL"],
["0x4d 0x0000","0 EQUAL"],
["0x4e 0x00000000","0 EQUAL"],
["0x4f 1000 ADD","999 EQUAL"],
["0", "IF 0x50 ENDIF 1", "0x50 is reserved (ok if not executed)"],
["0x51", "0x5f ADD 0x60 EQUAL", "0x51 through 0x60 push 1 through 16 onto stack"],
["1","NOP"],
["0", "IF VER ELSE 1 ENDIF", "VER non-functional (ok if not executed)"],
["0", "IF RESERVED1 RESERVED2 ELSE 1 ENDIF", "RESERVED ok in un-executed IF"],
["1", "DUP IF ENDIF"],
["1", "IF 1 ENDIF"],
["1", "DUP IF ELSE ENDIF"],
["1", "IF 1 ELSE ENDIF"],
["0", "IF ELSE 1 ENDIF"],
["1 1", "IF IF 1 ELSE 0 ENDIF ENDIF"],
["1 0", "IF IF 1 ELSE 0 ENDIF ENDIF"],
["1 1", "IF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["0 0", "IF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["1 0", "NOTIF IF 1 ELSE 0 ENDIF ENDIF"],
["1 1", "NOTIF IF 1 ELSE 0 ENDIF ENDIF"],
["1 0", "NOTIF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["0 1", "NOTIF IF 1 ELSE 0 ENDIF ELSE IF 0 ELSE 1 ENDIF ENDIF"],
["1 1", "VERIFY"],
["10 0 11 TOALTSTACK DROP FROMALTSTACK", "ADD 21 EQUAL"],
["'gavin_was_here' TOALTSTACK 11 FROMALTSTACK", "'gavin_was_here' EQUALVERIFY 11 EQUAL"],
["0 IFDUP", "DEPTH 1 EQUALVERIFY 0 EQUAL"],
["1 IFDUP", "DEPTH 2 EQUALVERIFY 1 EQUALVERIFY 1 EQUAL"],
["0 DROP", "DEPTH 0 EQUAL"],
["0", "DUP 1 ADD 1 EQUALVERIFY 0 EQUAL"],
["0 1", "NIP"],
["1 0", "OVER DEPTH 3 EQUALVERIFY"],
["22 21 20", "0 PICK 20 EQUALVERIFY DEPTH 3 EQUAL"],
["22 21 20", "1 PICK 21 EQUALVERIFY DEPTH 3 EQUAL"],
["22 21 20", "2 PICK 22 EQUALVERIFY DEPTH 3 EQUAL"],
["22 21 20", "0 ROLL 20 EQUALVERIFY DEPTH 2 EQUAL"],
["22 21 20", "1 ROLL 21 EQUALVERIFY DEPTH 2 EQUAL"],
["22 21 20", "2 ROLL 22 EQUALVERIFY DEPTH 2 EQUAL"],
["22 21 20", "ROT 22 EQUAL"],
["22 21 20", "ROT ROT 21 EQUAL"],
["22 21 20", "ROT ROT ROT 20 EQUAL"],
["1 0", "SWAP 1 EQUALVERIFY 0 EQUAL"],
["0 1", "TUCK DEPTH 3 EQUALVERIFY SWAP 2DROP"],
["13 14", "2DUP ROT EQUALVERIFY EQUAL"],
["-1 0 1 2", "3DUP DEPTH 7 EQUALVERIFY ADD ADD 3 EQUALVERIFY 2DROP 0 EQUALVERIFY"],
["1 2 3 5", "2OVER ADD ADD 8 EQUALVERIFY ADD ADD 6 EQUAL"],
["1 3 5 7", "2SWAP ADD 4 EQUALVERIFY ADD 12 EQUAL"],
["0", "SIZE 0 EQUAL"],
["1", "SIZE 1 EQUAL"],
["127", "SIZE 1 EQUAL"],
["128", "SIZE 2 EQUAL"],
["32767", "SIZE 2 EQUAL"],
["32768", "SIZE 3 EQUAL"],
["8388607", "SIZE 3 EQUAL"],
["8388608", "SIZE 4 EQUAL"],
["2147483647", "SIZE 4 EQUAL"],
["2147483648", "SIZE 5 EQUAL"],
["-1", "SIZE 1 EQUAL"],
["-127", "SIZE 1 EQUAL"],
["-128", "SIZE 2 EQUAL"],
["-32767", "SIZE 2 EQUAL"],
["-32768", "SIZE 3 EQUAL"],
["-8388607", "SIZE 3 EQUAL"],
["-8388608", "SIZE 4 EQUAL"],
["-2147483647", "SIZE 4 EQUAL"],
["-2147483648", "SIZE 5 EQUAL"],
["'abcdefghijklmnopqrstuvwxyz'", "SIZE 26 EQUAL"],
["0x4c00","0 EQUAL"],
["0x4d0000","0 EQUAL"],
["0x4e00000000","0 EQUAL"],
["2 -2 ADD", "0 EQUAL"],
["2147483647 -2147483647 ADD", "0 EQUAL"],
["-1 -1 ADD", "-2 EQUAL"],
["1","NOP"],
["0 0","EQUAL"],
["1 1 ADD", "2 EQUAL"],
["1 1ADD", "2 EQUAL"],
@ -81,8 +155,34 @@
["2147483647 DUP ADD", "4294967294 EQUAL", ">32 bit EQUAL is valid"],
["2147483647 NEGATE DUP ADD", "-4294967294 EQUAL"],
["''", "RIPEMD160 0x14 0x9c1185a5c5e9fc54612808977ee8f548b2258d31 EQUAL"],
["'a'", "RIPEMD160 0x14 0x0bdc9d2d256b3ee9daae347be6f4dc835a467ffe EQUAL"],
["'abcdefghijklmnopqrstuvwxyz'", "RIPEMD160 0x14 0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc EQUAL"],
["''", "SHA1 0x14 0xda39a3ee5e6b4b0d3255bfef95601890afd80709 EQUAL"],
["'a'", "SHA1 0x14 0x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 EQUAL"],
["'abcdefghijklmnopqrstuvwxyz'", "SHA1 0x14 0x32d10c7b8cf96570ca04ce37f2a19d84240d3a89 EQUAL"],
["''", "SHA256 0x20 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 EQUAL"],
["'a'", "SHA256 0x20 0xca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb EQUAL"],
["'abcdefghijklmnopqrstuvwxyz'", "SHA256 0x20 0x71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73 EQUAL"],
["''", "DUP HASH160 SWAP SHA256 RIPEMD160 EQUAL"],
["''", "DUP HASH256 SWAP SHA256 SHA256 EQUAL"],
["''", "NOP HASH160 0x14 0xb472a266d0bd89c13706a4132ccfb16f7c3b9fcb EQUAL"],
["'a'", "HASH160 NOP 0x14 0x994355199e516ff76c4fa4aab39337b9d84cf12b EQUAL"],
["'abcdefghijklmnopqrstuvwxyz'", "HASH160 0x4c 0x14 0xc286a1af0947f58d1ad787385b1c2c4a976f9e71 EQUAL"],
["''", "HASH256 0x20 0x5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456 EQUAL"],
["'a'", "HASH256 0x20 0xbf5d3affb73efd2ec6c36ad3112dd933efed63c4e1cbffcfa88e2759c144f2d8 EQUAL"],
["'abcdefghijklmnopqrstuvwxyz'", "HASH256 0x4c 0x20 0xca139bc10c2f660da42666f72e89a225936fc60f193c161124a672050c434671 EQUAL"],
["1","NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10 1 EQUAL"],
["'NOP_1_to_10' NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10","'NOP_1_to_10' EQUAL"],
["0", "IF 0xba ELSE 1 ENDIF", "opcodes above NOP10 invalid if executed"],
["0", "IF 0xc0 ELSE 1 ENDIF"],
["0", "IF 0xd1 ELSE 1 ENDIF"],
["0", "IF 0xee ELSE 1 ENDIF"],
["0", "IF 0xfd ELSE 1 ENDIF"],
["0", "IF 0xff ELSE 1 ENDIF"],
["NOP","1"]
]

View File

@ -102,7 +102,10 @@ read_json(const std::string& filename)
Value v;
if (!read_stream(ifs, v))
{
BOOST_ERROR("Cound not find/open " << filename);
if (ifs.fail())
BOOST_ERROR("Cound not find/open " << filename);
else
BOOST_ERROR("JSON syntax error in " << filename);
return Array();
}
if (v.type() != array_type)