Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_tests.cpp
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | 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, | ||||
std::string(FormatScriptError(err)) + " where " + | std::string(FormatScriptError(err)) + " where " + | ||||
std::string(FormatScriptError(scriptError)) + | std::string(FormatScriptError(scriptError)) + | ||||
" expected: " + message); | " expected: " + message); | ||||
// 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. | |||||
for (int i = 0; i < 16; ++i) { | |||||
uint32_t extra_flags = InsecureRandBits(32); | |||||
// Some flags are not purely-restrictive and thus we can't assume | |||||
// anything about what happens when they are flipped. Keep them as-is. | |||||
extra_flags &= | |||||
~(SCRIPT_ENABLE_SIGHASH_FORKID | SCRIPT_ENABLE_REPLAY_PROTECTION | | |||||
SCRIPT_ENABLE_SCHNORR_MULTISIG); | |||||
uint32_t combined_flags = | |||||
expect ? (flags & ~extra_flags) : (flags | extra_flags); | |||||
// Weed out invalid flag combinations. | |||||
if (combined_flags & SCRIPT_VERIFY_CLEANSTACK) { | |||||
combined_flags |= SCRIPT_VERIFY_P2SH; | |||||
} | |||||
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, | |||||
combined_flags, | |||||
MutableTransactionSignatureChecker( | |||||
&tx, 0, txCredit.vout[0].nValue), | |||||
&err) == expect, | |||||
message + strprintf(" (with %s flags %08x)", | |||||
expect ? "removed" : "added", | |||||
combined_flags ^ flags)); | |||||
} | |||||
#if defined(HAVE_CONSENSUS_LIB) | #if defined(HAVE_CONSENSUS_LIB) | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << tx2; | stream << tx2; | ||||
uint32_t libconsensus_flags = | uint32_t libconsensus_flags = | ||||
flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL; | flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL; | ||||
if (libconsensus_flags == flags) { | if (libconsensus_flags == flags) { | ||||
if (flags & bitcoinconsensus_SCRIPT_ENABLE_SIGHASH_FORKID) { | if (flags & bitcoinconsensus_SCRIPT_ENABLE_SIGHASH_FORKID) { | ||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount( | BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount( | ||||
▲ Show 20 Lines • Show All 2,873 Lines • Show Last 20 Lines |