diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-10-08 09:12:24 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-10-08 09:12:39 +0200 |
commit | ad9cd64d3b0dd4528b37f939bcb2c9205b44db65 (patch) | |
tree | 44fa26fa7a7cd3e7b04907a2c2ff7fa0d806f9f8 /src/test/script_tests.cpp | |
parent | fb5fa86bb412c2de59b3e2df4e354cd5ca67993d (diff) | |
parent | 2c930d932bdd4e1306f60dbb89f60c9a0149468b (diff) | |
download | bitcoin-ad9cd64d3b0dd4528b37f939bcb2c9205b44db65.tar.xz |
Merge pull request #5055
2c930d9 Prettify JSON tests and minimize diffs (Pieter Wuille)
Diffstat (limited to 'src/test/script_tests.cpp')
-rw-r--r-- | src/test/script_tests.cpp | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 6ed3e03f53..424eea11f5 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -34,6 +34,9 @@ using namespace std; using namespace json_spirit; using namespace boost::algorithm; +// Uncomment if you want to output updated JSON tests. +// #define UPDATE_JSON_TESTS + static const unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; unsigned int ParseScriptFlags(string strFlags); @@ -239,14 +242,14 @@ public: return *this; } - operator std::string() + Array GetJSON() const { - DoPush(); - return "[\"" + - FormatScript(spendTx.vin[0].scriptSig) + "\", \"" + - FormatScript(creditTx.vout[0].scriptPubKey) + "\", \"" + - FormatScriptFlags(flags) + "\", \"" + - comment + "\"],\n"; + Array array; + array.push_back(FormatScript(spendTx.vin[0].scriptSig)); + array.push_back(FormatScript(creditTx.vout[0].scriptPubKey)); + array.push_back(FormatScriptFlags(flags)); + array.push_back(comment); + return array; } std::string GetComment() @@ -377,18 +380,30 @@ BOOST_AUTO_TEST_CASE(script_build) BOOST_FOREACH(TestBuilder& test, good) { test.Test(true); - BOOST_CHECK_MESSAGE(tests_good.count(test.GetComment()) > 0, "Missing auto script_valid test: " + test.GetComment()); - BOOST_CHECK_MESSAGE(ParseScript(tests_good[test.GetComment()][1].get_str()) == test.GetScriptPubKey(), "ScriptPubKey mismatch in auto script_valid test: " + test.GetComment()); - strGood += test; + if (tests_good.count(test.GetComment()) == 0) { +#ifndef UPDATE_JSON_TESTS + BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + test.GetComment()); +#endif + strGood += write_string(Value(test.GetJSON()), true) + ",\n"; + } else { + BOOST_CHECK_MESSAGE(ParseScript(tests_good[test.GetComment()][1].get_str()) == test.GetScriptPubKey(), "ScriptPubKey mismatch in auto script_valid test: " + test.GetComment()); + strGood += write_string(Value(tests_good[test.GetComment()]), true) + ",\n"; + } } BOOST_FOREACH(TestBuilder& test, bad) { test.Test(false); - BOOST_CHECK_MESSAGE(tests_bad.count(test.GetComment()) > 0, "Missing auto script_invalid test: " + test.GetComment()); - BOOST_CHECK_MESSAGE(ParseScript(tests_bad[test.GetComment()][1].get_str()) == test.GetScriptPubKey(), "ScriptPubKey mismatch in auto script_invalid test: " + test.GetComment()); - strBad += test; + if (tests_bad.count(test.GetComment()) == 0) { +#ifndef UPDATE_JSON_TESTS + BOOST_CHECK_MESSAGE(false, "Missing auto script_invalid test: " + test.GetComment()); +#endif + strBad += write_string(Value(test.GetJSON()), true) + ",\n"; + } else { + BOOST_CHECK_MESSAGE(ParseScript(tests_bad[test.GetComment()][1].get_str()) == test.GetScriptPubKey(), "ScriptPubKey mismatch in auto script_invalid test: " + test.GetComment()); + strBad += write_string(Value(tests_bad[test.GetComment()]), true) + ",\n"; + } } -#if 0 +#ifdef UPDATE_JSON_TESTS FILE* valid = fopen("script_valid.json.gen", "w"); fputs(strGood.c_str(), valid); fclose(valid); |