diff options
Diffstat (limited to 'src/test/script_tests.cpp')
-rw-r--r-- | src/test/script_tests.cpp | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index c1f6f178db..32be914414 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -14,12 +14,14 @@ #include "main.h" #include "wallet.h" +#include "data/script_invalid.json.h" +#include "data/script_valid.json.h" using namespace std; using namespace json_spirit; using namespace boost::algorithm; -extern uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); +extern uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); static const unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; @@ -90,34 +92,15 @@ ParseScript(string s) } Array -read_json(const std::string& filename) +read_json(const std::string& jsondata) { - namespace fs = boost::filesystem; - fs::path testFile = fs::current_path() / "test" / "data" / filename; - -#ifdef TEST_DATA_DIR - if (!fs::exists(testFile)) - { - testFile = fs::path(BOOST_PP_STRINGIZE(TEST_DATA_DIR)) / filename; - } -#endif - - ifstream ifs(testFile.string().c_str(), ifstream::in); Value v; - if (!read_stream(ifs, v)) - { - if (ifs.fail()) - BOOST_ERROR("Cound not find/open " << filename); - else - BOOST_ERROR("JSON syntax error in " << filename); - return Array(); - } - if (v.type() != array_type) + + if (!read_string(jsondata, v) || v.type() != array_type) { - BOOST_ERROR(filename << " does not contain a json array"); + BOOST_ERROR("Parse error."); return Array(); } - return v.get_array(); } @@ -130,7 +113,7 @@ BOOST_AUTO_TEST_CASE(script_valid) // Inner arrays are [ "scriptSig", "scriptPubKey" ] // ... where scriptSig and scriptPubKey are stringified // scripts. - Array tests = read_json("script_valid.json"); + Array tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); BOOST_FOREACH(Value& tv, tests) { @@ -154,7 +137,7 @@ BOOST_AUTO_TEST_CASE(script_valid) BOOST_AUTO_TEST_CASE(script_invalid) { // Scripts that should evaluate as invalid - Array tests = read_json("script_invalid.json"); + Array tests = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid))); BOOST_FOREACH(Value& tv, tests) { |