test: construct transaction_tests test_Get inputs/outputs declaratively
What changed, and why it matters
This commit is a minor cleanup of a unit test file in Bitcoin Core. It replaces verbose, field-by-field construction of test transaction inputs and outputs with shorter declarative constructor calls. The behavior of the test is intentionally unchanged: the second transaction output remains default-constructed, just as it was before when it was created by resize(2) but never assigned. There is no change to production code, network behavior, or wallet handling.
No security action needed. This is a non-functional test refactor. Reviewers can treat it as normal code-quality review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In src/test/transaction_tests.cpp, the test_Get test case now builds t1.vin and t1.vout using initializer lists of CTxIn/COutPoint and CTxOut objects instead of resizing vectors and assigning fields individually. The previous code left t1.vout[1] uninitialized (nValue = -1); the new code explicitly creates a default-constructed CTxOut, preserving the same test state. The diff is purely a refactor of test setup code.
Changed components
src/test/transaction_tests.cppInspect captured patch +9 / −13
### src/test/transaction_tests.cpp
@@ -399,19 +399,15 @@ BOOST_AUTO_TEST_CASE(test_Get)
SetupDummyInputs(keystore, coins, {11*CENT, 50*CENT, 21*CENT, 22*CENT});
CMutableTransaction t1;
- t1.vin.resize(3);
- t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
- t1.vin[0].prevout.n = 1;
- t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
- t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
- t1.vin[1].prevout.n = 0;
- t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
- t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
- t1.vin[2].prevout.n = 1;
- t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
- t1.vout.resize(2);
- t1.vout[0].nValue = 90*CENT;
- t1.vout[0].scriptPubKey << OP_1;
+ t1.vin = {
+ CTxIn{COutPoint{dummyTransactions[0].GetHash(), 1}, CScript{} << std::vector<unsigned char>(65, 0)},
+ CTxIn{COutPoint{dummyTransactions[1].GetHash(), 0}, CScript{} << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4)},
+ CTxIn{COutPoint{dummyTransactions[1].GetHash(), 1}, CScript{} << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4)},
+ };
+ t1.vout = {
+ CTxOut{90 * CENT, CScript{} << OP_1},
+ CTxOut{},
+ };
BOOST_CHECK(ValidateInputsStandardness(CTransaction(t1), coins).IsValid());
}Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.