Merge pull request #4876

6022b5d Make script_{valid,invalid}.json validation flags configurable (Pieter Wuille)
pull/4719/head
Pieter Wuille 10 years ago
commit b9307d2f55
No known key found for this signature in database
GPG Key ID: 8F653255C87992E0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -35,6 +35,8 @@ using namespace boost::algorithm;
static const unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC; static const unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
unsigned int ParseScriptFlags(string strFlags);
Array Array
read_json(const std::string& jsondata) read_json(const std::string& jsondata)
{ {
@ -54,7 +56,7 @@ BOOST_AUTO_TEST_CASE(script_valid)
{ {
// Read tests from test/data/script_valid.json // Read tests from test/data/script_valid.json
// Format is an array of arrays // Format is an array of arrays
// Inner arrays are [ "scriptSig", "scriptPubKey" ] // Inner arrays are [ "scriptSig", "scriptPubKey", "flags" ]
// ... where scriptSig and scriptPubKey are stringified // ... where scriptSig and scriptPubKey are stringified
// scripts. // scripts.
Array tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid))); Array tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid)));
@ -63,7 +65,7 @@ BOOST_AUTO_TEST_CASE(script_valid)
{ {
Array test = tv.get_array(); Array test = tv.get_array();
string strTest = write_string(tv, false); string strTest = write_string(tv, false);
if (test.size() < 2) // Allow size > 2; extra stuff ignored (useful for comments) if (test.size() < 3) // Allow size > 3; extra stuff ignored (useful for comments)
{ {
BOOST_ERROR("Bad test: " << strTest); BOOST_ERROR("Bad test: " << strTest);
continue; continue;
@ -72,9 +74,10 @@ BOOST_AUTO_TEST_CASE(script_valid)
CScript scriptSig = ParseScript(scriptSigString); CScript scriptSig = ParseScript(scriptSigString);
string scriptPubKeyString = test[1].get_str(); string scriptPubKeyString = test[1].get_str();
CScript scriptPubKey = ParseScript(scriptPubKeyString); CScript scriptPubKey = ParseScript(scriptPubKeyString);
unsigned int scriptflags = ParseScriptFlags(test[2].get_str());
CTransaction tx; CTransaction tx;
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, tx, 0, flags, SIGHASH_NONE), strTest); BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, tx, 0, scriptflags, SIGHASH_NONE), strTest);
} }
} }
@ -96,9 +99,10 @@ BOOST_AUTO_TEST_CASE(script_invalid)
CScript scriptSig = ParseScript(scriptSigString); CScript scriptSig = ParseScript(scriptSigString);
string scriptPubKeyString = test[1].get_str(); string scriptPubKeyString = test[1].get_str();
CScript scriptPubKey = ParseScript(scriptPubKeyString); CScript scriptPubKey = ParseScript(scriptPubKeyString);
unsigned int scriptflags = ParseScriptFlags(test[2].get_str());
CTransaction tx; CTransaction tx;
BOOST_CHECK_MESSAGE(!VerifyScript(scriptSig, scriptPubKey, tx, 0, flags, SIGHASH_NONE), strTest); BOOST_CHECK_MESSAGE(!VerifyScript(scriptSig, scriptPubKey, tx, 0, scriptflags, SIGHASH_NONE), strTest);
} }
} }

@ -26,7 +26,7 @@ using namespace boost::algorithm;
// In script_tests.cpp // In script_tests.cpp
extern Array read_json(const std::string& jsondata); extern Array read_json(const std::string& jsondata);
unsigned int ParseFlags(string strFlags){ unsigned int ParseScriptFlags(string strFlags){
unsigned int flags = 0; unsigned int flags = 0;
vector<string> words; vector<string> words;
split(words, strFlags, is_any_of(",")); split(words, strFlags, is_any_of(","));
@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
break; break;
} }
unsigned int verify_flags = ParseFlags(test[2].get_str()); unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
BOOST_CHECK_MESSAGE(VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout], BOOST_CHECK_MESSAGE(VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
tx, i, verify_flags, 0), tx, i, verify_flags, 0),
strTest); strTest);
@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
break; break;
} }
unsigned int verify_flags = ParseFlags(test[2].get_str()); unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
fValid = VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout], fValid = VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
tx, i, verify_flags, 0); tx, i, verify_flags, 0);
} }

Loading…
Cancel
Save