Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_tests.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | static ScriptErrorDesc script_errors[] = { | ||||
{ScriptError::ILLEGAL_FORKID, "ILLEGAL_FORKID"}, | {ScriptError::ILLEGAL_FORKID, "ILLEGAL_FORKID"}, | ||||
{ScriptError::MUST_USE_FORKID, "MISSING_FORKID"}, | {ScriptError::MUST_USE_FORKID, "MISSING_FORKID"}, | ||||
{ScriptError::DIV_BY_ZERO, "DIV_BY_ZERO"}, | {ScriptError::DIV_BY_ZERO, "DIV_BY_ZERO"}, | ||||
{ScriptError::MOD_BY_ZERO, "MOD_BY_ZERO"}, | {ScriptError::MOD_BY_ZERO, "MOD_BY_ZERO"}, | ||||
{ScriptError::INVALID_BITFIELD_SIZE, "BITFIELD_SIZE"}, | {ScriptError::INVALID_BITFIELD_SIZE, "BITFIELD_SIZE"}, | ||||
{ScriptError::INVALID_BIT_RANGE, "BIT_RANGE"}, | {ScriptError::INVALID_BIT_RANGE, "BIT_RANGE"}, | ||||
}; | }; | ||||
static const char *FormatScriptError(ScriptError err) { | static std::string FormatScriptError(ScriptError err) { | ||||
for (size_t i = 0; i < ARRAYLEN(script_errors); ++i) { | for (size_t i = 0; i < ARRAYLEN(script_errors); ++i) { | ||||
if (script_errors[i].err == err) { | if (script_errors[i].err == err) { | ||||
return script_errors[i].name; | return script_errors[i].name; | ||||
} | } | ||||
} | } | ||||
BOOST_ERROR("Unknown scripterror enumeration value, update script_errors " | BOOST_ERROR("Unknown scripterror enumeration value, update script_errors " | ||||
"in script_tests.cpp."); | "in script_tests.cpp."); | ||||
Show All 26 Lines | const CTransaction txCredit{ | ||||
BuildCreditingTransaction(scriptPubKey, nValue)}; | BuildCreditingTransaction(scriptPubKey, nValue)}; | ||||
CMutableTransaction tx = BuildSpendingTransaction(scriptSig, txCredit); | CMutableTransaction tx = BuildSpendingTransaction(scriptSig, txCredit); | ||||
CMutableTransaction tx2 = tx; | CMutableTransaction tx2 = tx; | ||||
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, flags, | BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, flags, | ||||
MutableTransactionSignatureChecker( | MutableTransactionSignatureChecker( | ||||
&tx, 0, txCredit.vout[0].nValue), | &tx, 0, txCredit.vout[0].nValue), | ||||
&err) == expect, | &err) == expect, | ||||
message); | message); | ||||
BOOST_CHECK_MESSAGE(err == scriptError, | BOOST_CHECK_MESSAGE(err == scriptError, FormatScriptError(err) + " where " + | ||||
std::string(FormatScriptError(err)) + " where " + | FormatScriptError(scriptError) + | ||||
std::string(FormatScriptError(scriptError)) + | |||||
" expected: " + message); | " expected: " + message); | ||||
// Verify that removing flags from a passing test or adding flags to a | // Verify that removing flags from a passing test or adding flags to a | ||||
// failing test does not change the result, except for some special flags. | // failing test does not change the result, except for some special flags. | ||||
for (int i = 0; i < 16; ++i) { | for (int i = 0; i < 16; ++i) { | ||||
uint32_t extra_flags = InsecureRandBits(32); | uint32_t extra_flags = InsecureRandBits(32); | ||||
// Some flags are not purely-restrictive and thus we can't assume | // Some flags are not purely-restrictive and thus we can't assume | ||||
// anything about what happens when they are flipped. Keep them as-is. | // anything about what happens when they are flipped. Keep them as-is. | ||||
extra_flags &= | extra_flags &= | ||||
▲ Show 20 Lines • Show All 3,206 Lines • Show Last 20 Lines |