* Check that the input scripts of a transaction are valid/invalid as expected. */
| 114 | * Check that the input scripts of a transaction are valid/invalid as expected. |
| 115 | */ |
| 116 | bool CheckTxScripts(const CTransaction& tx, const std::map<COutPoint, CScript>& map_prevout_scriptPubKeys, |
| 117 | const std::map<COutPoint, int64_t>& map_prevout_values, unsigned int flags, |
| 118 | const PrecomputedTransactionData& txdata, const std::string& strTest, bool expect_valid) |
| 119 | { |
| 120 | bool tx_valid = true; |
| 121 | ScriptError err = expect_valid ? SCRIPT_ERR_UNKNOWN_ERROR : SCRIPT_ERR_OK; |
| 122 | for (unsigned int i = 0; i < tx.vin.size() && tx_valid; ++i) { |
| 123 | const CTxIn input = tx.vin[i]; |
| 124 | const CAmount amount = map_prevout_values.count(input.prevout) ? map_prevout_values.at(input.prevout) : 0; |
| 125 | try { |
| 126 | const CScriptWitness *pScriptWitness = ((tx.witness.vtxinwit.size() > i) ? &tx.witness.vtxinwit[i].scriptWitness : nullptr); |
| 127 | flags &= ~SCRIPT_NO_SIGHASH_BYTE; // ELEMENTS: ensure that our random flag-setting doesn't cause the sighash byte to be misinterpreted |
| 128 | tx_valid = VerifyScript(input.scriptSig, map_prevout_scriptPubKeys.at(input.prevout), |
| 129 | pScriptWitness, flags, TransactionSignatureChecker(&tx, i, amount, txdata, MissingDataBehavior::ASSERT_FAIL), &err); |
| 130 | } catch (...) { |
| 131 | BOOST_ERROR("Bad test: " << strTest); |
| 132 | return true; // The test format is bad and an error is thrown. Return true to silence further error. |
| 133 | } |
| 134 | if (expect_valid) { |
| 135 | BOOST_CHECK_MESSAGE(tx_valid, strTest); |
| 136 | BOOST_CHECK_MESSAGE((err == SCRIPT_ERR_OK), ScriptErrorString(err)); |
| 137 | err = SCRIPT_ERR_UNKNOWN_ERROR; |
| 138 | } |
| 139 | } |
| 140 | if (!expect_valid) { |
| 141 | BOOST_CHECK_MESSAGE(!tx_valid, strTest); |
| 142 | BOOST_CHECK_MESSAGE((err != SCRIPT_ERR_OK), ScriptErrorString(err)); |
| 143 | } |
| 144 | return (tx_valid == expect_valid); |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Trim or fill flags to make the combination valid: |
no test coverage detected