Skip to content

Commit

Permalink
Get rid of expect in script_tests as it's implied by scripterror
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Apr 5, 2016
1 parent 76da761 commit 009b503
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/test/script_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMu
return txSpend;
}

void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, bool expect, const std::string& message, int scriptError)
void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, const std::string& message, int scriptError)
{
bool expect = (scriptError == SCRIPT_ERR_OK);
ScriptError err;
CMutableTransaction tx = BuildSpendingTransaction(scriptSig, BuildCreditingTransaction(scriptPubKey));
CMutableTransaction tx2 = tx;
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, flags, MutableTransactionSignatureChecker(&tx, 0), &err) == expect, message);
BOOST_CHECK_MESSAGE(scriptError == -1 || err == scriptError, std::string(FormatScriptError(err)) + " where " + std::string(FormatScriptError((ScriptError_t)scriptError)) + " expected: " + message);
BOOST_CHECK_MESSAGE(err == scriptError, std::string(FormatScriptError(err)) + " where " + std::string(FormatScriptError((ScriptError_t)scriptError)) + " expected: " + message);
#if defined(HAVE_CONSENSUS_LIB)
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
stream << tx2;
Expand Down Expand Up @@ -349,11 +350,11 @@ class TestBuilder
return *this;
}

TestBuilder& Test(bool expect)
TestBuilder& Test()
{
TestBuilder copy = *this; // Make a copy so we can rollback the push.
DoPush();
DoTest(creditTx.vout[0].scriptPubKey, spendTx.vin[0].scriptSig, flags, expect, comment, expect ? SCRIPT_ERR_OK : scriptError);
DoTest(creditTx.vout[0].scriptPubKey, spendTx.vin[0].scriptSig, flags, comment, scriptError);
*this = copy;
return *this;
}
Expand Down Expand Up @@ -680,7 +681,7 @@ BOOST_AUTO_TEST_CASE(script_build)
std::string strBad;

BOOST_FOREACH(TestBuilder& test, good) {
test.Test(true);
test.Test();
std::string str = JSONPrettyPrint(test.GetJSON());
#ifndef UPDATE_JSON_TESTS
if (tests_good.count(str) == 0) {
Expand All @@ -690,7 +691,7 @@ BOOST_AUTO_TEST_CASE(script_build)
strGood += str + ",\n";
}
BOOST_FOREACH(TestBuilder& test, bad) {
test.Test(false);
test.Test();
std::string str = JSONPrettyPrint(test.GetJSON());
#ifndef UPDATE_JSON_TESTS
if (tests_bad.count(str) == 0) {
Expand Down Expand Up @@ -736,7 +737,7 @@ BOOST_AUTO_TEST_CASE(script_valid)
unsigned int scriptflags = ParseScriptFlags(test[2].get_str());
BOOST_CHECK_EQUAL(test[3].get_str(), "OK");

DoTest(scriptPubKey, scriptSig, scriptflags, true, strTest, SCRIPT_ERR_OK);
DoTest(scriptPubKey, scriptSig, scriptflags, strTest, SCRIPT_ERR_OK);
}
}

Expand All @@ -761,7 +762,7 @@ BOOST_AUTO_TEST_CASE(script_invalid)
unsigned int scriptflags = ParseScriptFlags(test[2].get_str());
int scriptError = ParseScriptError(test[3].get_str());

DoTest(scriptPubKey, scriptSig, scriptflags, false, strTest, scriptError);
DoTest(scriptPubKey, scriptSig, scriptflags, strTest, scriptError);
}
}

Expand Down

0 comments on commit 009b503

Please sign in to comment.