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

Function Test

src/test/fuzz/script_assets_test_minimizer.cpp:146–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146void Test(const std::string& str)
147{
148 UniValue test;
149 if (!test.read(str) || !test.isObject()) throw std::runtime_error("Non-object test input");
150
151 CMutableTransaction tx = TxFromHex(test["tx"].get_str());
152 const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]);
153 if (prevouts.size() != tx.vin.size()) throw std::runtime_error("Incorrect number of prevouts");
154 size_t idx = test["index"].getInt<int64_t>();
155 if (idx >= tx.vin.size()) throw std::runtime_error("Invalid index");
156 script_verify_flags test_flags = ParseScriptFlags(test["flags"].get_str());
157 bool final = test.exists("final") && test["final"].get_bool();
158
159 if (test.exists("success")) {
160 tx.vin[idx].scriptSig = ScriptFromHex(test["success"]["scriptSig"].get_str());
161 tx.vin[idx].scriptWitness = ScriptWitnessFromJSON(test["success"]["witness"]);
162 PrecomputedTransactionData txdata;
163 txdata.Init(tx, std::vector<CTxOut>(prevouts));
164 MutableTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, txdata, MissingDataBehavior::ASSERT_FAIL);
165 for (const auto flags : ALL_FLAGS) {
166 // "final": true tests are valid for all flags. Others are only valid with flags that are
167 // a subset of test_flags.
168 if (final || ((flags & test_flags) == flags)) {
169 (void)VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr);
170 }
171 }
172 }
173
174 if (test.exists("failure")) {
175 tx.vin[idx].scriptSig = ScriptFromHex(test["failure"]["scriptSig"].get_str());
176 tx.vin[idx].scriptWitness = ScriptWitnessFromJSON(test["failure"]["witness"]);
177 PrecomputedTransactionData txdata;
178 txdata.Init(tx, std::vector<CTxOut>(prevouts));
179 MutableTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, txdata, MissingDataBehavior::ASSERT_FAIL);
180 for (const auto flags : ALL_FLAGS) {
181 // If a test is supposed to fail with test_flags, it should also fail with any superset thereof.
182 if ((flags & test_flags) == test_flags) {
183 (void)VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr);
184 }
185 }
186 }
187}
188
189void test_init() {}
190

Callers 3

TestMethod · 0.50
BOOST_AUTO_TEST_CASEFunction · 0.50

Calls 12

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
readMethod · 0.45
sizeMethod · 0.45
existsMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected