From 15982a8b69ec6ab3c3a6bf71fc6a9b681d3ff541 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Wed, 20 Aug 2014 15:15:16 -0400 Subject: Convert tree to using univalue. Eliminate all json_spirit uses. --- src/test/script_tests.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/test/script_tests.cpp') diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index c0614cca4..b4cab3245 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -26,9 +26,7 @@ #include #include -#include "json/json_spirit_reader_template.h" -#include "json/json_spirit_utils.h" -#include "json/json_spirit_writer_template.h" +#include "json_spirit_wrapper.h" using namespace std; using namespace json_spirit; @@ -46,7 +44,7 @@ read_json(const std::string& jsondata) { Value v; - if (!read_string(jsondata, v) || v.type() != array_type) + if (!v.read(jsondata) || !v.isArray()) { BOOST_ERROR("Parse error."); return Array(); @@ -636,10 +634,9 @@ BOOST_AUTO_TEST_CASE(script_valid) // scripts. Array tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); - BOOST_FOREACH(Value& tv, tests) - { - Array test = tv.get_array(); - string strTest = write_string(tv, false); + for (unsigned int idx = 0; idx < tests.size(); idx++) { + Array test = tests[idx]; + string strTest = test.write(); if (test.size() < 3) // Allow size > 3; extra stuff ignored (useful for comments) { if (test.size() != 1) { @@ -662,11 +659,10 @@ BOOST_AUTO_TEST_CASE(script_invalid) // Scripts that should evaluate as invalid Array tests = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); - BOOST_FOREACH(Value& tv, tests) - { - Array test = tv.get_array(); - string strTest = write_string(tv, false); - if (test.size() < 3) // Allow size > 3; extra stuff ignored (useful for comments) + for (unsigned int idx = 0; idx < tests.size(); idx++) { + Array test = tests[idx]; + string strTest = test.write(); + if (test.size() < 3) // Allow size > 2; extra stuff ignored (useful for comments) { if (test.size() != 1) { BOOST_ERROR("Bad test: " << strTest); -- cgit v1.2.3 From 53b4671a9de75f7c8e2903d510cf88867c3f6b97 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sun, 10 May 2015 13:35:44 +0200 Subject: extend conversion to UniValue --- src/test/script_tests.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/test/script_tests.cpp') diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index b4cab3245..989b35b9e 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -583,11 +583,13 @@ BOOST_AUTO_TEST_CASE(script_build) Array json_good = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); Array json_bad = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); - BOOST_FOREACH(Value& tv, json_good) { - tests_good.insert(write_string(Value(tv.get_array()), true)); + for (unsigned int idx = 0; idx < json_good.size(); idx++) { + const Value& tv = json_good[idx]; + tests_good.insert(tv.get_array().write()); } - BOOST_FOREACH(Value& tv, json_bad) { - tests_bad.insert(write_string(Value(tv.get_array()), true)); + for (unsigned int idx = 0; idx < json_bad.size(); idx++) { + const Value& tv = json_bad[idx]; + tests_bad.insert(tv.get_array().write()); } } @@ -596,7 +598,7 @@ BOOST_AUTO_TEST_CASE(script_build) BOOST_FOREACH(TestBuilder& test, good) { test.Test(true); - std::string str = write_string(Value(test.GetJSON()), true); + std::string str = test.GetJSON().write(); #ifndef UPDATE_JSON_TESTS if (tests_good.count(str) == 0) { BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + test.GetComment()); @@ -606,7 +608,7 @@ BOOST_AUTO_TEST_CASE(script_build) } BOOST_FOREACH(TestBuilder& test, bad) { test.Test(false); - std::string str = write_string(Value(test.GetJSON()), true); + std::string str = test.GetJSON().write(); #ifndef UPDATE_JSON_TESTS if (tests_bad.count(str) == 0) { BOOST_CHECK_MESSAGE(false, "Missing auto script_invalid test: " + test.GetComment()); -- cgit v1.2.3 From 6c7bee062437acbc078533fdcf8e53794031bf99 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sun, 10 May 2015 14:48:35 +0200 Subject: expicit set UniValue type to avoid empty values --- src/test/script_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/script_tests.cpp') diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 989b35b9e..80e5ac6b3 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -296,7 +296,7 @@ public: Array GetJSON() { DoPush(); - Array array; + UniValue array(UniValue::VARR); array.push_back(FormatScript(spendTx.vin[0].scriptSig)); array.push_back(FormatScript(creditTx.vout[0].scriptPubKey)); array.push_back(FormatScriptFlags(flags)); -- cgit v1.2.3 From 3df0411ad9fd75fb27af53e44835d41f5480fe3f Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 13 May 2015 21:29:19 +0200 Subject: remove JSON Spirit UniValue wrapper --- src/test/script_tests.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/test/script_tests.cpp') diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 80e5ac6b3..af11c0c9d 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -293,7 +293,7 @@ public: return *this; } - Array GetJSON() + UniValue GetJSON() { DoPush(); UniValue array(UniValue::VARR); @@ -580,8 +580,8 @@ BOOST_AUTO_TEST_CASE(script_build) std::set tests_bad; { - Array json_good = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); - Array json_bad = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); + UniValue json_good = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); + UniValue json_bad = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); for (unsigned int idx = 0; idx < json_good.size(); idx++) { const Value& tv = json_good[idx]; @@ -634,10 +634,10 @@ BOOST_AUTO_TEST_CASE(script_valid) // Inner arrays are [ "scriptSig", "scriptPubKey", "flags" ] // ... where scriptSig and scriptPubKey are stringified // scripts. - Array tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); + UniValue tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - Array test = tests[idx]; + UniValue test = tests[idx]; string strTest = test.write(); if (test.size() < 3) // Allow size > 3; extra stuff ignored (useful for comments) { @@ -659,10 +659,10 @@ BOOST_AUTO_TEST_CASE(script_valid) BOOST_AUTO_TEST_CASE(script_invalid) { // Scripts that should evaluate as invalid - Array tests = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); + UniValue tests = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - Array test = tests[idx]; + UniValue test = tests[idx]; string strTest = test.write(); if (test.size() < 3) // Allow size > 2; extra stuff ignored (useful for comments) { -- cgit v1.2.3 From 9a8897f4ac992741e153d88b54bd2cde877c713d Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Mon, 18 May 2015 14:02:18 +0200 Subject: Remove JSON Spirit wrapper, remove JSON Spirit leftovers - implement find_value() function for UniValue - replace all Array/Value/Object types with UniValues, remove JSON Spirit to UniValue wrapper - remove JSON Spirit sources --- src/test/script_tests.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/test/script_tests.cpp') diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index af11c0c9d..373342569 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -26,10 +26,10 @@ #include #include -#include "json_spirit_wrapper.h" + +#include "univalue/univalue.h" using namespace std; -using namespace json_spirit; // Uncomment if you want to output updated JSON tests. // #define UPDATE_JSON_TESTS @@ -39,15 +39,15 @@ static const unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; unsigned int ParseScriptFlags(string strFlags); string FormatScriptFlags(unsigned int flags); -Array +UniValue read_json(const std::string& jsondata) { - Value v; + UniValue v; if (!v.read(jsondata) || !v.isArray()) { BOOST_ERROR("Parse error."); - return Array(); + return UniValue(UniValue::VARR); } return v.get_array(); } @@ -584,11 +584,11 @@ BOOST_AUTO_TEST_CASE(script_build) UniValue json_bad = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); for (unsigned int idx = 0; idx < json_good.size(); idx++) { - const Value& tv = json_good[idx]; + const UniValue& tv = json_good[idx]; tests_good.insert(tv.get_array().write()); } for (unsigned int idx = 0; idx < json_bad.size(); idx++) { - const Value& tv = json_bad[idx]; + const UniValue& tv = json_bad[idx]; tests_bad.insert(tv.get_array().write()); } } -- cgit v1.2.3