MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / DoTest

Method DoTest

src/test/script_tests.cpp:123–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121
122struct ScriptTest : BasicTestingSetup {
123void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScriptWitness& scriptWitness, script_verify_flags flags, const std::string& message, int scriptError, CAmount nValue = 0)
124{
125 bool expect = (scriptError == SCRIPT_ERR_OK);
126 if (flags & SCRIPT_VERIFY_CLEANSTACK) {
127 flags |= SCRIPT_VERIFY_P2SH;
128 flags |= SCRIPT_VERIFY_WITNESS;
129 }
130 ScriptError err;
131 const CTransaction txCredit{BuildCreditingTransaction(scriptPubKey, nValue)};
132 CMutableTransaction tx = BuildSpendingTransaction(scriptSig, scriptWitness, txCredit);
133 BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue, MissingDataBehavior::ASSERT_FAIL), &err) == expect, message);
134 BOOST_CHECK_MESSAGE(err == scriptError, FormatScriptError(err) + " where " + FormatScriptError((ScriptError_t)scriptError) + " expected: " + message);
135
136 // Verify that removing flags from a passing test or adding flags to a failing test does not change the result.
137 for (int i = 0; i < 256; ++i) {
138 script_verify_flags extra_flags = script_verify_flags::from_int(m_rng.randbits(MAX_SCRIPT_VERIFY_FLAGS_BITS));
139 script_verify_flags combined_flags{expect ? (flags & ~extra_flags) : (flags | extra_flags)};
140 // Weed out some invalid flag combinations.
141 if (combined_flags & SCRIPT_VERIFY_CLEANSTACK && ~combined_flags & (SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS)) continue;
142 if (combined_flags & SCRIPT_VERIFY_WITNESS && ~combined_flags & SCRIPT_VERIFY_P2SH) continue;
143 BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, combined_flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue, MissingDataBehavior::ASSERT_FAIL), &err) == expect, message + strprintf(" (with flags %x)", combined_flags.as_int()));
144 }
145}
146}; // struct ScriptTest
147
148void static NegateSignatureS(std::vector<unsigned char>& vchSig) {

Callers 1

TestBuilderClass · 0.45

Calls 6

BuildSpendingTransactionFunction · 0.85
VerifyScriptFunction · 0.85
FormatScriptErrorFunction · 0.85
randbitsMethod · 0.80
as_intMethod · 0.80

Tested by

no test coverage detected