MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/transaction_tests.cpp:193–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup)
192
193BOOST_AUTO_TEST_CASE(tx_valid)
194{
195 BOOST_CHECK_MESSAGE(CheckMapFlagNames(), "mapFlagNames is missing a script verification flag");
196 // Read tests from test/data/tx_valid.json
197 UniValue tests = read_json(std::string(json_tests::tx_valid, json_tests::tx_valid + sizeof(json_tests::tx_valid)));
198
199 for (unsigned int idx = 0; idx < tests.size(); idx++) {
200 UniValue test = tests[idx];
201 std::string strTest = test.write();
202 if (test[0].isArray())
203 {
204 if (test.size() != 3 || !test[1].isStr() || !test[2].isStr())
205 {
206 BOOST_ERROR("Bad test: " << strTest);
207 continue;
208 }
209
210 std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
211 std::map<COutPoint, int64_t> mapprevOutValues;
212 UniValue inputs = test[0].get_array();
213 bool fValid = true;
214 for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
215 const UniValue& input = inputs[inpIdx];
216 if (!input.isArray()) {
217 fValid = false;
218 break;
219 }
220 UniValue vinput = input.get_array();
221 if (vinput.size() < 3 || vinput.size() > 4)
222 {
223 fValid = false;
224 break;
225 }
226 COutPoint outpoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].get_int())};
227 mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str());
228 if (vinput.size() >= 4)
229 {
230 mapprevOutValues[outpoint] = vinput[3].get_int64();
231 }
232 }
233 if (!fValid)
234 {
235 BOOST_ERROR("Bad test: " << strTest);
236 continue;
237 }
238
239 std::string transaction = test[1].get_str();
240 CDataStream stream(ParseHex(transaction), SER_NETWORK, PROTOCOL_VERSION);
241 CTransaction tx(deserialize, stream);
242
243 TxValidationState state;
244 BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
245 BOOST_CHECK(state.IsValid());
246
247 PrecomputedTransactionData txdata(tx);
248 unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
249
250 // Check that the test gives a valid combination of flags (otherwise VerifyScript will throw). Don't edit the flags.

Callers

nothing calls this directly

Calls 15

CheckMapFlagNamesFunction · 0.85
read_jsonFunction · 0.85
uint256SFunction · 0.85
ParseHexFunction · 0.85
CheckTransactionFunction · 0.85
FillFlagsFunction · 0.85
CheckTxScriptsFunction · 0.85
TrimFlagsFunction · 0.85
InsecureRandBitsFunction · 0.85
ExcludeIndividualFlagsFunction · 0.85
SetupDummyInputsFunction · 0.85
AreInputsStandardFunction · 0.85

Tested by

no test coverage detected