Skip to content

Commit

Permalink
Fix script test handling of empty scripts
Browse files Browse the repository at this point in the history
Previously an empty script would evaluate to OP_0
  • Loading branch information
petertodd committed Mar 13, 2014
1 parent ca0b8ac commit b41e594
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/test/data/script_invalid.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
[
["", "DEPTH", "Test the test: we should have an empty stack after scriptSig evaluation"],
[" ", "DEPTH", "and multiple spaces should not change that."],
[" ", "DEPTH"],
[" ", "DEPTH"],

["", ""],
["", "NOP"],
["", "NOP DEPTH"],
["NOP", ""],
["NOP", "DEPTH"],
["NOP","NOP"],
["NOP","NOP DEPTH"],

["DEPTH", ""],

["0x4c01","0x01 NOP", "PUSHDATA1 with not enough bytes"],
["0x4d0200ff","0x01 NOP", "PUSHDATA2 with not enough bytes"],
Expand Down
12 changes: 12 additions & 0 deletions src/test/data/script_valid.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
[
["", "DEPTH 0 EQUAL", "Test the test: we should have an empty stack after scriptSig evaluation"],
[" ", "DEPTH 0 EQUAL", "and multiple spaces should not change that."],
[" ", "DEPTH 0 EQUAL"],
[" ", "DEPTH 0 EQUAL"],
["1 2", "2 EQUALVERIFY 1 EQUAL", "Similarly whitespace around and between symbols"],
["1 2", "2 EQUALVERIFY 1 EQUAL"],
[" 1 2", "2 EQUALVERIFY 1 EQUAL"],
["1 2 ", "2 EQUALVERIFY 1 EQUAL"],
[" 1 2 ", "2 EQUALVERIFY 1 EQUAL"],

["1", ""],

["0x01 0x0b", "11 EQUAL", "push 1 byte"],
["0x02 0x417a", "'Az' EQUAL"],
["0x4b 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a",
Expand Down
6 changes: 5 additions & 1 deletion src/test/script_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ ParseScript(string s)

BOOST_FOREACH(string w, words)
{
if (all(w, is_digit()) ||
if (w.size() == 0)
{
// Empty string, ignore. (boost::split given '' will return one word)
}
else if (all(w, is_digit()) ||
(starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
{
// Number
Expand Down

0 comments on commit b41e594

Please sign in to comment.