Merge bitcoin/bitcoin#36888: test: construct `coinselection_tests` output declaratively
What changed, and why it matters
This is a minor cleanup inside a single test file. It changes how a fake transaction output is built in a unit test so the empty script is written explicitly rather than created implicitly by resizing a list. The actual test behavior and the transactions being simulated are unchanged. There is no security issue.
No action required. This is a safe test-only refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies src/wallet/test/coinselection_tests.cpp only. In MakeCoin(), it replaces tx.vout.resize(1) plus assignment to tx.vout[0].nValue with a direct list initialization of tx.vout using CTxOut{amount + int(is_eff_value) * fees, CScript{}}. The CAmount fees variable is made const. This is a test-only refactor with no functional change to production code or to the test’s semantics.
Changed components
src/wallet/test/coinselection_tests.cppInspect captured patch +4 / −3
### src/wallet/test/coinselection_tests.cpp
@@ -63,10 +63,11 @@ static const CoinSelectionParams default_cs_params = init_cs_params();
static OutputGroup MakeCoin(const CAmount& amount, bool is_eff_value = true, CoinSelectionParams cs_params = default_cs_params, int custom_spending_vsize = P2WPKH_INPUT_VSIZE)
{
// Always assume that we only have one input
+ const CAmount fees = cs_params.m_effective_feerate.GetFee(custom_spending_vsize);
CMutableTransaction tx;
- tx.vout.resize(1);
- CAmount fees = cs_params.m_effective_feerate.GetFee(custom_spending_vsize);
- tx.vout[0].nValue = amount + int(is_eff_value) * fees;
+ tx.vout = {
+ CTxOut{amount + int(is_eff_value) * fees, CScript{}},
+ };
tx.nLockTime = next_lock_time++; // so all transactions get different hashes
OutputGroup group(cs_params);
group.Insert(std::make_shared<COutput>(COutPoint(tx.GetHash(), 0), tx.vout.at(0), /*depth=*/1, /*input_bytes=*/custom_spending_vsize, /*solvable=*/true, /*safe=*/true, /*time=*/0, /*from_me=*/false, /*fees=*/fees), /*ancestors=*/0, /*cluster_count=*/0);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.