AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 15 Bitcoin

Merge bitcoin/bitcoin#36606: test, bench: construct inputs/outputs declaratively in context-dependent cases

Public commit record

What the developer wrote

Authored by merge-script

100/100 · Strong
Merge bitcoin/bitcoin#36606: test, bench: construct inputs/outputs declaratively in context-dependent cases

bdf58dd89cc2fe2f0be5ac63755e821661022be6 test: construct transaction_tests test_Get inputs/outputs declaratively (Alexander Wiederin)
24d00c4539479415207d3b912ec3648b4020c4e0 bench: construct ccoins_caching inputs/outputs declaratively (Alexander Wiederin)
a45478aa27553d28479cb288bb2d33f917bc544b test: construct sigopcount_tests BuildTxs inputs/outputs declaratively (Alexander Wiederin)
524d554e2bf952082f7e621145ca1b3a4b81d6c7 test: construct CreateBlockChain coinbase declaratively (Alexander Wiederin)
60be0930ca92eeee960ef6a2d7e2c61ef03c93dd test: construct transaction_utils inputs/outputs declaratively (Alexander Wiederin)

Pull request description:

Part of https://github.com/bitcoin/bitcoin/issues/36692 (previously discussed in https://github.com/bitcoin/bitcoin/pull/35994): replace procedural, field-by-field construction of `COutPoint`, `CTxIn` and `CTxOut` in test code with constructor calls.

This PR covers cases that are context-dependent and need manual changes, independent of a scripted-diff for the trivial bulk:
- `test/util/transaction_utils`: in `BuildSpendingTransaction`, the `scriptWitness` assignment has to be moved after `vin` is replaced, otherwise the witness is dropped.
- `test/util/mining`: in `CreateBlockChain`, the coinbase input's fields were split by the output assignments, with comments that are now kept next to the constructor arguments.
- `sigopcount_tests`: `BuildTxs` has the same witness ordering issue as `BuildSpendingTransaction`.
- `bench/ccoins_caching`: The `scriptSig`s are built with `<<` appends, and the second output was created by `vout.resize(2)` but never assigned, so it is kept as a null `CTxOut{}`.
- `transaction_tests`: `test_Get` builds the same transaction as `bench/ccoins_caching`, with the same `<<` appends and null second output.

**This change is test- and bench-only and does not change the constructed transactions.**

Notes for reviewers:
- `CTxIn` has no witness constructor argument, so `scriptWitness` is assigned after `vin` is replaced.
- `BuildTxs` is called repeatedly on the same transaction objects. Previously, `resize(1)` kept the existing inputs and only overwrote some of their fields; now they are replaced entirely. The fields that were left untouched by `BuildTxs` are never modified by the test, so the transactions are unchanged.
- The null second output in `ccoins_caching` is copied from `test_Get` in `transaction_tests` and looks like an oversight. It is kept here to avoid behaviour changes.

ACKs for top commit:
maflcko:
review ACK bdf58dd89cc2fe2f0be5ac63755e821661022be6 🍠
purpleKarrot:
But even when the approach does not follow the steps 1 and 2, it is a step in the right direction, hence ACK bdf58dd89cc2fe2f0be5ac63755e821661022be6

Tree-SHA512: af4c7489ddc553eda466b7ac4ca33cff400a495264b8cb2d869929e108fab8dac08f3cc164be79a3505b7c8b461514fc6f87f5afd42919f0712dd1d325d824b7
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit is a code cleanup inside Bitcoin Core's tests and benchmarks. It replaces a manual, field-by-field way of building fake transactions with a more direct constructor style. The author explicitly states that the actual transaction data being built is unchanged, and the diff confirms the values and structure stay the same. There is no security issue here.

Recommended action

No action required; this is a benign test/bench refactor.

Security signals we found

No strong security signals were identified.

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.