| 167 | } |
| 168 | |
| 169 | void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScriptWitness& scriptWitness, int flags, const std::string& message, int scriptError, CAmount nValue = 0) |
| 170 | { |
| 171 | bool expect = (scriptError == SCRIPT_ERR_OK); |
| 172 | if (flags & SCRIPT_VERIFY_CLEANSTACK) { |
| 173 | flags |= SCRIPT_VERIFY_P2SH; |
| 174 | flags |= SCRIPT_VERIFY_WITNESS; |
| 175 | } |
| 176 | ScriptError err; |
| 177 | CMutableTransaction txCredit = BuildCreditingTransaction(scriptPubKey, nValue); |
| 178 | CMutableTransaction tx = BuildSpendingTransaction(scriptSig, scriptWitness, txCredit); |
| 179 | CMutableTransaction tx2 = tx; |
| 180 | BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message); |
| 181 | BOOST_CHECK_MESSAGE(err == scriptError, std::string(FormatScriptError(err)) + " where " + std::string(FormatScriptError((ScriptError_t)scriptError)) + " expected: " + message); |
| 182 | |
| 183 | #if defined(HAVE_CONSENSUS_LIB) |
| 184 | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); |
| 185 | stream << tx2; |
| 186 | int libconsensus_flags = flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL; |
| 187 | if (libconsensus_flags == flags) { |
| 188 | if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS) { |
| 189 | BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), txCredit.vout[0].nValue, (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect, message); |
| 190 | } else { |
| 191 | BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), 0, (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect, message); |
| 192 | BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect,message); |
| 193 | } |
| 194 | } |
| 195 | #endif |
| 196 | } |
| 197 | |
| 198 | void static NegateSignatureS(std::vector<unsigned char>& vchSig) { |
| 199 | // Parse the signature. |
no test coverage detected