Merge bitcoin/bitcoin#36750: test: construct multisig_tests inputs/outputs declaratively
What changed, and why it matters
This is a test-only code cleanup in Bitcoin Core. It changes how fake transactions are built inside unit tests, making the test code more readable without altering the actual transactions being tested. There is no effect on the live Bitcoin network or wallet software.
No security action needed; this is a routine test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors src/test/multisig_tests.cpp to construct CTxOut/CTxIn/COutPoint objects declaratively instead of resizing vectors and assigning fields one by one. The resulting transaction shapes are identical: funding outputs still have nValue=-1 and spending outputs still have nValue=1, and prevout indices still match the loop counter. The loop counter type is changed from int to uint32_t to match COutPoint::n. No consensus, P2P, wallet, or RPC code is touched.
Changed components
src/test/multisig_tests.cppInspect captured patch +24 / −20
### src/test/multisig_tests.cpp
@@ -57,19 +57,21 @@ BOOST_AUTO_TEST_CASE(multisig_verify)
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
CMutableTransaction txFrom; // Funding transaction
- txFrom.vout.resize(3);
- txFrom.vout[0].scriptPubKey = a_and_b;
- txFrom.vout[1].scriptPubKey = a_or_b;
- txFrom.vout[2].scriptPubKey = escrow;
+ txFrom.vout = {
+ CTxOut{-1, a_and_b},
+ CTxOut{-1, a_or_b},
+ CTxOut{-1, escrow},
+ };
CMutableTransaction txTo[3]; // Spending transaction
- for (int i = 0; i < 3; i++)
+ for (uint32_t i = 0; i < 3; i++)
{
- txTo[i].vin.resize(1);
- txTo[i].vout.resize(1);
- txTo[i].vin[0].prevout.n = i;
- txTo[i].vin[0].prevout.hash = txFrom.GetHash();
- txTo[i].vout[0].nValue = 1;
+ txTo[i].vin = {
+ CTxIn{COutPoint{txFrom.GetHash(), i}},
+ };
+ txTo[i].vout = {
+ CTxOut{1, CScript{}},
+ };
}
std::vector<CKey> keys;
@@ -202,19 +204,21 @@ BOOST_AUTO_TEST_CASE(multisig_Sign)
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
CMutableTransaction txFrom; // Funding transaction
- txFrom.vout.resize(3);
- txFrom.vout[0].scriptPubKey = a_and_b;
- txFrom.vout[1].scriptPubKey = a_or_b;
- txFrom.vout[2].scriptPubKey = escrow;
+ txFrom.vout = {
+ CTxOut{-1, a_and_b},
+ CTxOut{-1, a_or_b},
+ CTxOut{-1, escrow},
+ };
CMutableTransaction txTo[3]; // Spending transaction
- for (int i = 0; i < 3; i++)
+ for (uint32_t i = 0; i < 3; i++)
{
- txTo[i].vin.resize(1);
- txTo[i].vout.resize(1);
- txTo[i].vin[0].prevout.n = i;
- txTo[i].vin[0].prevout.hash = txFrom.GetHash();
- txTo[i].vout[0].nValue = 1;
+ txTo[i].vin = {
+ CTxIn{COutPoint{txFrom.GetHash(), i}},
+ };
+ txTo[i].vout = {
+ CTxOut{1, CScript{}},
+ };
}
for (int i = 0; i < 3; i++)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.