MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / AssetTest

Function AssetTest

src/test/script_assets_tests.cpp:102–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100static const std::vector<script_verify_flags> ALL_CONSENSUS_FLAGS = AllConsensusFlags();
101
102static 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
149BOOST_AUTO_TEST_CASE(script_assets_test)
150{

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 11

VerifyScriptFunction · 0.85
isObjectMethod · 0.80
get_boolMethod · 0.80
TxFromHexFunction · 0.70
TxOutsFromJSONFunction · 0.70
ParseScriptFlagsFunction · 0.70
ScriptFromHexFunction · 0.70
ScriptWitnessFromJSONFunction · 0.70
sizeMethod · 0.45
existsMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected