@@ -1637,6 +1637,37 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_invalid_flags)
16371637 BOOST_CHECK_EQUAL (err, bitcoinconsensus_ERR_INVALID_FLAGS);
16381638}
16391639
1640+ /* Test bitcoinconsensus_verify_script returns spent outputs required err */
1641+ BOOST_AUTO_TEST_CASE (bitcoinconsensus_verify_script_spent_outputs_required_err)
1642+ {
1643+ unsigned int libconsensus_flags{bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT};
1644+ const int nIn{0 };
1645+
1646+ CScript scriptPubKey;
1647+ CScript scriptSig;
1648+ CScriptWitness wit;
1649+
1650+ scriptPubKey << OP_EQUAL;
1651+ CTransaction creditTx{BuildCreditingTransaction (scriptPubKey, 1 )};
1652+ CTransaction spendTx{BuildSpendingTransaction (scriptSig, wit, creditTx)};
1653+
1654+ CDataStream stream (SER_NETWORK, PROTOCOL_VERSION);
1655+ stream << spendTx;
1656+
1657+ bitcoinconsensus_error err;
1658+ int result{bitcoinconsensus_verify_script_with_spent_outputs (scriptPubKey.data (), scriptPubKey.size (), creditTx.vout [0 ].nValue , UCharCast (stream.data ()), stream.size (), nullptr , 0 , nIn, libconsensus_flags, &err)};
1659+ BOOST_CHECK_EQUAL (result, 0 );
1660+ BOOST_CHECK_EQUAL (err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
1661+
1662+ result = bitcoinconsensus_verify_script_with_amount (scriptPubKey.data (), scriptPubKey.size (), creditTx.vout [0 ].nValue , UCharCast (stream.data ()), stream.size (), nIn, libconsensus_flags, &err);
1663+ BOOST_CHECK_EQUAL (result, 0 );
1664+ BOOST_CHECK_EQUAL (err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
1665+
1666+ result = bitcoinconsensus_verify_script (scriptPubKey.data (), scriptPubKey.size (), UCharCast (stream.data ()), stream.size (), nIn, libconsensus_flags, &err);
1667+ BOOST_CHECK_EQUAL (result, 0 );
1668+ BOOST_CHECK_EQUAL (err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
1669+ }
1670+
16401671#endif // defined(HAVE_CONSENSUS_LIB)
16411672
16421673static std::vector<unsigned int > AllConsensusFlags ()
@@ -1685,12 +1716,29 @@ static void AssetTest(const UniValue& test)
16851716 PrecomputedTransactionData txdata;
16861717 txdata.Init (tx, std::vector<CTxOut>(prevouts));
16871718 CachingTransactionSignatureChecker txcheck (&tx, idx, prevouts[idx].nValue , true , txdata);
1719+
1720+ #if defined(HAVE_CONSENSUS_LIB)
1721+ CDataStream stream (SER_NETWORK, PROTOCOL_VERSION);
1722+ stream << tx;
1723+ std::vector<UTXO> utxos;
1724+ utxos.resize (prevouts.size ());
1725+ for (size_t i = 0 ; i < prevouts.size (); i++) {
1726+ utxos[i].scriptPubKey = prevouts[i].scriptPubKey .data ();
1727+ utxos[i].scriptPubKeySize = prevouts[i].scriptPubKey .size ();
1728+ utxos[i].value = prevouts[i].nValue ;
1729+ }
1730+ #endif
1731+
16881732 for (const auto flags : ALL_CONSENSUS_FLAGS) {
16891733 // "final": true tests are valid for all flags. Others are only valid with flags that are
16901734 // a subset of test_flags.
16911735 if (fin || ((flags & test_flags) == flags)) {
16921736 bool ret = VerifyScript (tx.vin [idx].scriptSig , prevouts[idx].scriptPubKey , &tx.vin [idx].scriptWitness , flags, txcheck, nullptr );
16931737 BOOST_CHECK (ret);
1738+ #if defined(HAVE_CONSENSUS_LIB)
1739+ int lib_ret = bitcoinconsensus_verify_script_with_spent_outputs (prevouts[idx].scriptPubKey .data (), prevouts[idx].scriptPubKey .size (), prevouts[idx].nValue , UCharCast (stream.data ()), stream.size (), utxos.data (), utxos.size (), idx, flags, nullptr );
1740+ BOOST_CHECK (lib_ret == 1 );
1741+ #endif
16941742 }
16951743 }
16961744 }
@@ -1702,11 +1750,28 @@ static void AssetTest(const UniValue& test)
17021750 PrecomputedTransactionData txdata;
17031751 txdata.Init (tx, std::vector<CTxOut>(prevouts));
17041752 CachingTransactionSignatureChecker txcheck (&tx, idx, prevouts[idx].nValue , true , txdata);
1753+
1754+ #if defined(HAVE_CONSENSUS_LIB)
1755+ CDataStream stream (SER_NETWORK, PROTOCOL_VERSION);
1756+ stream << tx;
1757+ std::vector<UTXO> utxos;
1758+ utxos.resize (prevouts.size ());
1759+ for (size_t i = 0 ; i < prevouts.size (); i++) {
1760+ utxos[i].scriptPubKey = prevouts[i].scriptPubKey .data ();
1761+ utxos[i].scriptPubKeySize = prevouts[i].scriptPubKey .size ();
1762+ utxos[i].value = prevouts[i].nValue ;
1763+ }
1764+ #endif
1765+
17051766 for (const auto flags : ALL_CONSENSUS_FLAGS) {
17061767 // If a test is supposed to fail with test_flags, it should also fail with any superset thereof.
17071768 if ((flags & test_flags) == test_flags) {
17081769 bool ret = VerifyScript (tx.vin [idx].scriptSig , prevouts[idx].scriptPubKey , &tx.vin [idx].scriptWitness , flags, txcheck, nullptr );
17091770 BOOST_CHECK (!ret);
1771+ #if defined(HAVE_CONSENSUS_LIB)
1772+ int lib_ret = bitcoinconsensus_verify_script_with_spent_outputs (prevouts[idx].scriptPubKey .data (), prevouts[idx].scriptPubKey .size (), prevouts[idx].nValue , UCharCast (stream.data ()), stream.size (), utxos.data (), utxos.size (), idx, flags, nullptr );
1773+ BOOST_CHECK (lib_ret == 0 );
1774+ #endif
17101775 }
17111776 }
17121777 }
0 commit comments