diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2016-04-05 15:45:10 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-04-05 15:46:16 +0200 |
commit | 76da7613517d05aca31c2cee42b5ebf3d5c54974 (patch) | |
tree | 81c60233d55d7dc958408e6f57572180262af5b6 /src/test/script_tests.cpp | |
parent | 269281b7cc56e728fa64803fc7509ab3a0ce1805 (diff) |
Make script_error a mandatory 4th field for script_tests
Diffstat (limited to 'src/test/script_tests.cpp')
-rw-r--r-- | src/test/script_tests.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 4ecb56de84..006d8aa644 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -263,7 +263,7 @@ private: } public: - TestBuilder(const CScript& redeemScript, const std::string& comment_, int flags_, bool P2SH = false) : scriptPubKey(redeemScript), havePush(false), comment(comment_), flags(flags_), scriptError(-1) + TestBuilder(const CScript& redeemScript, const std::string& comment_, int flags_, bool P2SH = false) : scriptPubKey(redeemScript), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK) { if (P2SH) { creditTx = BuildCreditingTransaction(CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL); @@ -365,9 +365,8 @@ public: array.push_back(FormatScript(spendTx.vin[0].scriptSig)); array.push_back(FormatScript(creditTx.vout[0].scriptPubKey)); array.push_back(FormatScriptFlags(flags)); + array.push_back(FormatScriptError((ScriptError_t)scriptError)); array.push_back(comment); - if (scriptError != -1) - array.push_back(FormatScriptError((ScriptError_t)scriptError)); return array; } @@ -715,7 +714,7 @@ BOOST_AUTO_TEST_CASE(script_valid) { // Read tests from test/data/script_valid.json // Format is an array of arrays - // Inner arrays are [ "scriptSig", "scriptPubKey", "flags" ] + // Inner arrays are [ "scriptSig", "scriptPubKey", "flags", "expected_scripterror" ] // ... where scriptSig and scriptPubKey are stringified // scripts. UniValue tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); @@ -735,6 +734,7 @@ BOOST_AUTO_TEST_CASE(script_valid) string scriptPubKeyString = test[1].get_str(); CScript scriptPubKey = ParseScript(scriptPubKeyString); unsigned int scriptflags = ParseScriptFlags(test[2].get_str()); + BOOST_CHECK_EQUAL(test[3].get_str(), "OK"); DoTest(scriptPubKey, scriptSig, scriptflags, true, strTest, SCRIPT_ERR_OK); } @@ -747,7 +747,7 @@ BOOST_AUTO_TEST_CASE(script_invalid) for (unsigned int idx = 0; idx < tests.size(); idx++) { UniValue test = tests[idx]; string strTest = test.write(); - if (test.size() < 3) // Allow size > 2; extra stuff ignored (useful for comments) + if (test.size() < 4) // Allow size > 2; extra stuff ignored (useful for comments) { if (test.size() != 1) { BOOST_ERROR("Bad test: " << strTest); @@ -759,10 +759,7 @@ BOOST_AUTO_TEST_CASE(script_invalid) string scriptPubKeyString = test[1].get_str(); CScript scriptPubKey = ParseScript(scriptPubKeyString); unsigned int scriptflags = ParseScriptFlags(test[2].get_str()); - int scriptError = -1; // Expected script error is optional, and follows comment - if (test.size() >= 5 && test[4].get_str() != "") { - scriptError = ParseScriptError(test[4].get_str()); - } + int scriptError = ParseScriptError(test[3].get_str()); DoTest(scriptPubKey, scriptSig, scriptflags, false, strTest, scriptError); } |