| 100 | static const std::vector<script_verify_flags> ALL_CONSENSUS_FLAGS = AllConsensusFlags(); |
| 101 | |
| 102 | static void AssetTest(const UniValue& test, SignatureCache& signature_cache) |
| 103 | { |
| 104 | BOOST_CHECK(test.isObject()); |
| 105 | |
| 106 | CMutableTransaction mtx = TxFromHex(test["tx"].get_str()); |
| 107 | const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]); |
| 108 | BOOST_CHECK(prevouts.size() == mtx.vin.size()); |
| 109 | size_t idx = test["index"].getInt<int64_t>(); |
| 110 | script_verify_flags test_flags{ParseScriptFlags(test["flags"].get_str())}; |
| 111 | bool fin = test.exists("final") && test["final"].get_bool(); |
| 112 | |
| 113 | if (test.exists("success")) { |
| 114 | mtx.vin[idx].scriptSig = ScriptFromHex(test["success"]["scriptSig"].get_str()); |
| 115 | mtx.vin[idx].scriptWitness = ScriptWitnessFromJSON(test["success"]["witness"]); |
| 116 | CTransaction tx(mtx); |
| 117 | PrecomputedTransactionData txdata; |
| 118 | txdata.Init(tx, std::vector<CTxOut>(prevouts)); |
| 119 | CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, signature_cache, txdata); |
| 120 | |
| 121 | for (const auto flags : ALL_CONSENSUS_FLAGS) { |
| 122 | // "final": true tests are valid for all flags. Others are only valid with flags that are |
| 123 | // a subset of test_flags. |
| 124 | if (fin || ((flags & test_flags) == flags)) { |
| 125 | bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr); |
| 126 | BOOST_CHECK(ret); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if (test.exists("failure")) { |
| 132 | mtx.vin[idx].scriptSig = ScriptFromHex(test["failure"]["scriptSig"].get_str()); |
| 133 | mtx.vin[idx].scriptWitness = ScriptWitnessFromJSON(test["failure"]["witness"]); |
| 134 | CTransaction tx(mtx); |
| 135 | PrecomputedTransactionData txdata; |
| 136 | txdata.Init(tx, std::vector<CTxOut>(prevouts)); |
| 137 | CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, signature_cache, txdata); |
| 138 | |
| 139 | for (const auto flags : ALL_CONSENSUS_FLAGS) { |
| 140 | // If a test is supposed to fail with test_flags, it should also fail with any superset thereof. |
| 141 | if ((flags & test_flags) == test_flags) { |
| 142 | bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr); |
| 143 | BOOST_CHECK(!ret); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(script_assets_test) |
| 150 | { |
no test coverage detected