@@ -1637,6 +1637,37 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_invalid_flags)
1637
1637
BOOST_CHECK_EQUAL (err, bitcoinconsensus_ERR_INVALID_FLAGS);
1638
1638
}
1639
1639
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
+
1640
1671
#endif // defined(HAVE_CONSENSUS_LIB)
1641
1672
1642
1673
static std::vector<unsigned int > AllConsensusFlags ()
@@ -1685,12 +1716,29 @@ static void AssetTest(const UniValue& test)
1685
1716
PrecomputedTransactionData txdata;
1686
1717
txdata.Init (tx, std::vector<CTxOut>(prevouts));
1687
1718
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
+
1688
1732
for (const auto flags : ALL_CONSENSUS_FLAGS) {
1689
1733
// "final": true tests are valid for all flags. Others are only valid with flags that are
1690
1734
// a subset of test_flags.
1691
1735
if (fin || ((flags & test_flags) == flags)) {
1692
1736
bool ret = VerifyScript (tx.vin [idx].scriptSig , prevouts[idx].scriptPubKey , &tx.vin [idx].scriptWitness , flags, txcheck, nullptr );
1693
1737
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
1694
1742
}
1695
1743
}
1696
1744
}
@@ -1702,11 +1750,28 @@ static void AssetTest(const UniValue& test)
1702
1750
PrecomputedTransactionData txdata;
1703
1751
txdata.Init (tx, std::vector<CTxOut>(prevouts));
1704
1752
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
+
1705
1766
for (const auto flags : ALL_CONSENSUS_FLAGS) {
1706
1767
// If a test is supposed to fail with test_flags, it should also fail with any superset thereof.
1707
1768
if ((flags & test_flags) == test_flags) {
1708
1769
bool ret = VerifyScript (tx.vin [idx].scriptSig , prevouts[idx].scriptPubKey , &tx.vin [idx].scriptWitness , flags, txcheck, nullptr );
1709
1770
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
1710
1775
}
1711
1776
}
1712
1777
}
0 commit comments