Skip to content

Commit 2dd6f80

Browse files
committed
Add a test that all flags are softforks
1 parent 2851b77 commit 2dd6f80

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/test/script_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
167167
CMutableTransaction tx2 = tx;
168168
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message);
169169
BOOST_CHECK_MESSAGE(err == scriptError, std::string(FormatScriptError(err)) + " where " + std::string(FormatScriptError((ScriptError_t)scriptError)) + " expected: " + message);
170+
171+
// Verify that removing flags from a passing test or adding flags to a failing test does not change the result.
172+
for (int i = 0; i < 16; ++i) {
173+
int extra_flags = InsecureRandBits(16);
174+
int combined_flags = expect ? (flags & ~extra_flags) : (flags | extra_flags);
175+
// Weed out some invalid flag combinations.
176+
if (combined_flags & SCRIPT_VERIFY_CLEANSTACK && ~combined_flags & (SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS)) continue;
177+
if (combined_flags & SCRIPT_VERIFY_WITNESS && ~combined_flags & SCRIPT_VERIFY_P2SH) continue;
178+
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, combined_flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message + strprintf(" (with flags %x)", combined_flags));
179+
}
180+
170181
#if defined(HAVE_CONSENSUS_LIB)
171182
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
172183
stream << tx2;

0 commit comments

Comments
 (0)