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

Function CheckTxScripts

src/test/transaction_tests.cpp:87–114  ·  view source on GitHub ↗

* Check that the input scripts of a transaction are valid/invalid as expected. */

Source from the content-addressed store, hash-verified

85* Check that the input scripts of a transaction are valid/invalid as expected.
86*/
87bool CheckTxScripts(const CTransaction& tx, const std::map<COutPoint, CScript>& map_prevout_scriptPubKeys,
88 const std::map<COutPoint, int64_t>& map_prevout_values, script_verify_flags flags,
89 const PrecomputedTransactionData& txdata, const std::string& strTest, bool expect_valid)
90{
91 bool tx_valid = true;
92 ScriptError err = expect_valid ? SCRIPT_ERR_UNKNOWN_ERROR : SCRIPT_ERR_OK;
93 for (unsigned int i = 0; i < tx.vin.size() && tx_valid; ++i) {
94 const CTxIn input = tx.vin[i];
95 const CAmount amount = map_prevout_values.contains(input.prevout) ? map_prevout_values.at(input.prevout) : 0;
96 try {
97 tx_valid = VerifyScript(input.scriptSig, map_prevout_scriptPubKeys.at(input.prevout),
98 &input.scriptWitness, flags, TransactionSignatureChecker(&tx, i, amount, txdata, MissingDataBehavior::ASSERT_FAIL), &err);
99 } catch (...) {
100 BOOST_ERROR("Bad test: " << strTest);
101 return true; // The test format is bad and an error is thrown. Return true to silence further error.
102 }
103 if (expect_valid) {
104 BOOST_CHECK_MESSAGE(tx_valid, strTest);
105 BOOST_CHECK_MESSAGE((err == SCRIPT_ERR_OK), ScriptErrorString(err));
106 err = SCRIPT_ERR_UNKNOWN_ERROR;
107 }
108 }
109 if (!expect_valid) {
110 BOOST_CHECK_MESSAGE(!tx_valid, strTest);
111 BOOST_CHECK_MESSAGE((err != SCRIPT_ERR_OK), ScriptErrorString(err));
112 }
113 return (tx_valid == expect_valid);
114}
115
116/*
117 * Trim or fill flags to make the combination valid:

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 5

VerifyScriptFunction · 0.85
ScriptErrorStringFunction · 0.85
sizeMethod · 0.45
containsMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected