| 1717 | static const std::vector<unsigned int> ALL_CONSENSUS_FLAGS = AllConsensusFlags(); |
| 1718 | |
| 1719 | static void AssetTest(const UniValue& test) |
| 1720 | { |
| 1721 | BOOST_CHECK(test.isObject()); |
| 1722 | |
| 1723 | CMutableTransaction mtx = TxFromHex(test["tx"].get_str()); |
| 1724 | const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]); |
| 1725 | BOOST_CHECK(prevouts.size() == mtx.vin.size()); |
| 1726 | mtx.witness.vtxinwit.resize(mtx.vin.size()); |
| 1727 | size_t idx = test["index"].get_int64(); |
| 1728 | uint32_t test_flags{ParseScriptFlags(test["flags"].get_str())}; |
| 1729 | bool fin = test.exists("final") && test["final"].get_bool(); |
| 1730 | // ELEMENTS: feature_taproot.py --dumptests outputs this field |
| 1731 | uint256 hash_genesis_block = test.exists("hash_genesis_block") ? uint256S(test["hash_genesis_block"].get_str()) : uint256{}; |
| 1732 | |
| 1733 | if (test.exists("success")) { |
| 1734 | mtx.vin[idx].scriptSig = ScriptFromHex(test["success"]["scriptSig"].get_str()); |
| 1735 | mtx.witness.vtxinwit[idx].scriptWitness = ScriptWitnessFromJSON(test["success"]["witness"]); |
| 1736 | CTransaction tx(mtx); |
| 1737 | PrecomputedTransactionData txdata(hash_genesis_block); |
| 1738 | txdata.Init(tx, std::vector<CTxOut>(prevouts)); |
| 1739 | CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata); |
| 1740 | for (const auto flags : ALL_CONSENSUS_FLAGS) { |
| 1741 | // "final": true tests are valid for all flags. Others are only valid with flags that are |
| 1742 | // a subset of test_flags. |
| 1743 | if (fin || ((flags & test_flags) == flags)) { |
| 1744 | ScriptError serror; |
| 1745 | bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.witness.vtxinwit[idx].scriptWitness, flags, txcheck, &serror); |
| 1746 | BOOST_CHECK(ret); |
| 1747 | BOOST_CHECK_EQUAL(serror, SCRIPT_ERR_OK); |
| 1748 | } |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | if (test.exists("failure")) { |
| 1753 | mtx.vin[idx].scriptSig = ScriptFromHex(test["failure"]["scriptSig"].get_str()); |
| 1754 | mtx.witness.vtxinwit[idx].scriptWitness = ScriptWitnessFromJSON(test["failure"]["witness"]); |
| 1755 | CTransaction tx(mtx); |
| 1756 | PrecomputedTransactionData txdata(hash_genesis_block); |
| 1757 | txdata.Init(tx, std::vector<CTxOut>(prevouts)); |
| 1758 | CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata); |
| 1759 | |
| 1760 | std::optional<ScriptError> expected_error; |
| 1761 | if (test["failure"].exists("error")) { |
| 1762 | expected_error = ParseScriptError(test["failure"]["error"].get_str()); |
| 1763 | } |
| 1764 | |
| 1765 | for (const auto flags : ALL_CONSENSUS_FLAGS) { |
| 1766 | // If a test is supposed to fail with test_flags, it should also fail with any superset thereof. |
| 1767 | if ((flags & test_flags) == test_flags) { |
| 1768 | ScriptError serror; |
| 1769 | bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.witness.vtxinwit[idx].scriptWitness, flags, txcheck, &serror); |
| 1770 | BOOST_CHECK(!ret); |
| 1771 | |
| 1772 | if (expected_error) { |
| 1773 | BOOST_CHECK_EQUAL(serror, *expected_error); |
| 1774 | } |
| 1775 | } |
| 1776 | } |
no test coverage detected