aboutsummaryrefslogtreecommitdiff
path: root/src/test/script_tests.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-10-07 02:22:47 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-10-07 09:41:33 +0200
commit2c930d932bdd4e1306f60dbb89f60c9a0149468b (patch)
tree2e70eecb5213675fa2bdcb27fa97e2677e5fa4c2 /src/test/script_tests.cpp
parenta2a5fe3b727bcf5f87b91f5b625c98e132fd3d22 (diff)
downloadbitcoin-2c930d932bdd4e1306f60dbb89f60c9a0149468b.tar.xz
Prettify JSON tests and minimize diffs
Diffstat (limited to 'src/test/script_tests.cpp')
-rw-r--r--src/test/script_tests.cpp43
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);