aboutsummaryrefslogtreecommitdiff
path: root/src/test/script_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/script_tests.cpp')
-rw-r--r--src/test/script_tests.cpp43
1 files changed, 15 insertions, 28 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index b24f15d892..079cc49f60 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;
@@ -32,8 +34,12 @@ ParseScript(string s)
if (mapOpNames.size() == 0)
{
- for (int op = OP_NOP; op <= OP_NOP10; op++)
+ for (int op = 0; op <= OP_NOP10; op++)
{
+ // Allow OP_RESERVED to get into mapOpNames
+ if (op < OP_NOP && op != OP_RESERVED)
+ continue;
+
const char* name = GetOpName((opcodetype)op);
if (strcmp(name, "OP_UNKNOWN") == 0)
continue;
@@ -72,7 +78,7 @@ ParseScript(string s)
}
else if (mapOpNames.count(w))
{
- // opcode, e.g. OP_ADD or OP_1:
+ // opcode, e.g. OP_ADD or ADD:
result << mapOpNames[w];
}
else
@@ -86,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();
}
@@ -126,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)
{
@@ -150,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)
{