Browse Source

Fix script test handling of empty scripts

Previously an empty script would evaluate to OP_0
0.10
Peter Todd 11 years ago
parent
commit
b41e594773
No known key found for this signature in database
GPG Key ID: 2481403DA5F091FB
  1. 10
      src/test/data/script_invalid.json
  2. 12
      src/test/data/script_valid.json
  3. 6
      src/test/script_tests.cpp

10
src/test/data/script_invalid.json

@ -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"],
["", "NOP DEPTH"],
["NOP", ""], ["NOP", ""],
["NOP", "DEPTH"],
["NOP","NOP"], ["NOP","NOP"],
["NOP","NOP DEPTH"],
["DEPTH", ""],
["0x4c01","0x01 NOP", "PUSHDATA1 with not enough bytes"], ["0x4c01","0x01 NOP", "PUSHDATA1 with not enough bytes"],
["0x4d0200ff","0x01 NOP", "PUSHDATA2 with not enough bytes"], ["0x4d0200ff","0x01 NOP", "PUSHDATA2 with not enough bytes"],

12
src/test/data/script_valid.json

@ -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"], ["0x01 0x0b", "11 EQUAL", "push 1 byte"],
["0x02 0x417a", "'Az' EQUAL"], ["0x02 0x417a", "'Az' EQUAL"],
["0x4b 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a", ["0x4b 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a",

6
src/test/script_tests.cpp

@ -63,7 +63,11 @@ ParseScript(string s)
BOOST_FOREACH(string w, words) 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()))) (starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
{ {
// Number // Number

Loading…
Cancel
Save