test, bench: construct inputs/outputs declaratively in txpackage, duplicate_inputs and p2sh tests #36788

Manually merged
yuvicc merged 3 commits from test-declarative-txpackage-p2sh into master 2026-11-08 13:42:56 +00:00 AGit
yuvicc commented 2026-11-06 05:09:44 +00:00 (Migrated from github.com)

Part of #36692. Follow-up to #36750

Replaces field-by-field construction of inputs and outputs with COutPoint, CTxIn and CTxOut ctor calls in txpackage_tests, bench/duplicate_inputs and script_p2sh_tests.

CMutableTransaction is kept as the builder while a CTransaction constructor is discussed in #36696. Witnesses are still assigned after vin, since CTxIn has no witness argument yet.

Test-only; the constructed transactions are unchanged.

  • script_p2sh_tests: two outputs created by vout.resize(1) never had a value, so their null nValue (-1) is now explicit.
  • Intentional mutations are left as they are: the scriptSig swap in sign, the dummy signing in ValidateInputsStandardness, and the witness-only copies in txpackage_tests (mtx_child2, mtx_parent2_v2).
Part of #36692. Follow-up to #36750 Replaces field-by-field construction of inputs and outputs with `COutPoint`, `CTxIn` and `CTxOut` ctor calls in `txpackage_tests`, `bench/duplicate_inputs` and `script_p2sh_tests`. `CMutableTransaction` is kept as the builder while a `CTransaction` constructor is discussed in #36696. Witnesses are still assigned after `vin`, since `CTxIn` has no witness argument yet. Test-only; the constructed transactions are unchanged. - `script_p2sh_tests`: two outputs created by `vout.resize(1)` never had a value, so their null `nValue` (`-1`) is now explicit. - Intentional mutations are left as they are: the `scriptSig` swap in `sign`, the dummy signing in `ValidateInputsStandardness`, and the witness-only copies in `txpackage_tests` (`mtx_child2`, `mtx_parent2_v2`).
DrahtBot commented 2026-11-06 05:09:52 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK alexanderwiederin, purpleKarrot, maflcko, janb84, jpk68

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35733 (sign: Remove FillableSigningProvider by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36788 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36788.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36788#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [alexanderwiederin](https://github.com/bitcoin/bitcoin/pull/36788#issuecomment-6691487987), [purpleKarrot](https://github.com/bitcoin/bitcoin/pull/36788#issuecomment-6691668385), [maflcko](https://github.com/bitcoin/bitcoin/pull/36788#issuecomment-6705491235), [janb84](https://github.com/bitcoin/bitcoin/pull/36788#issuecomment-6707473033), [jpk68](https://github.com/bitcoin/bitcoin/pull/36788#issuecomment-6714882579) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35733](https://github.com/bitcoin/bitcoin/pull/35733) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35733.svg"></sub> (sign: Remove FillableSigningProvider by achow101) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: a4a2647834ad · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:df0443dc5cff1224f58cf2f0af2a814b52ac77c4fa18c64584a637f43b36d781:adfdaf6241fe97209d62717f4b34912a3f3c05551d5eb04e28ec078dd3f7e4f2 --> <!-- ralph-base:411c971e75ba8ef16855a41dfe2d31d574ebf507 --> <!-- ralph-head:a4a2647834ad0cc4576b2eb38bddf02c42081173 --> <!-- ralph-case:b62e8c47adefcdcfe8dbf3e9b308b7e57634ff524d8650cc12b09eea74ab3c3c --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`a4a2647834ad`](<https://git.fish.foo/bitcoin/bitcoin/commit/a4a2647834ad0cc4576b2eb38bddf02c42081173>) · [Full review report](<https://review.fish.foo/traces/36788-a4a2647834ad0cc4576b2eb38bddf02c42081173-2315-2.html>) · [Previous reports](<https://review.fish.foo/traces/36788/>) [permalink](<https://review.fish.foo/traces/36788-a4a2647834ad0cc4576b2eb38bddf02c42081173-2315-2.html>)
maflcko (Migrated from github.com) reviewed 2026-11-06 07:18:24 +00:00
maflcko (Migrated from github.com) commented 2026-11-06 07:18:20 +00:00

nit: Move down to make review easier?

nit: Move down to make review easier?
maflcko (Migrated from github.com) commented 2026-11-06 07:17:58 +00:00

not sure if this is meaningfully easier in this test case. Could just vout[9] = CTxOut{1000, witnessUnknown} above to avoid the comments?

not sure if this is meaningfully easier in this test case. Could just `vout[9] = CTxOut{1000, witnessUnknown}` above to avoid the comments?
purpleKarrot (Migrated from github.com) reviewed 2026-11-06 09:47:41 +00:00
purpleKarrot (Migrated from github.com) commented 2026-11-06 09:47:41 +00:00

What about

        /*[9]=*/ CTxOut{1000, witnessUnknown},

This would be aligned with the /*named_arg=*/0 approach recommended by the LLM linter.

What about ```suggestion /*[9]=*/ CTxOut{1000, witnessUnknown}, ``` This would be aligned with the `/*named_arg=*/0` approach recommended by the LLM linter.
purpleKarrot commented 2026-11-06 09:51:53 +00:00 (Migrated from github.com)

Great work! ACK

Maybe apply the changes recommended by the LLM linter.

Great work! ACK Maybe apply the changes recommended by the LLM linter.
alexanderwiederin (Migrated from github.com) reviewed 2026-11-06 10:04:13 +00:00
alexanderwiederin (Migrated from github.com) commented 2026-11-06 10:04:13 +00:00

Another alternative is a helper that appends an output and returns its index:

std::vector<CTxOut> outputs;
const auto add_output{[&](CTxOut out) {
    outputs.push_back(std::move(out));
    return uint32_t(outputs.size() - 1);
}};

const uint32_t sixteen_sigops_idx{add_output(CTxOut{5000, GetScriptForDestination(ScriptHash(sixteenSigops))})};

CMutableTransaction txFrom;
txFrom.vout = std::move(outputs);
AddCoins(coins, CTransaction(txFrom), 0);

Then the spending transactions can use sixteen_sigops_idx instead of 5.

Another alternative is a helper that appends an output and returns its index: ```cpp std::vector<CTxOut> outputs; const auto add_output{[&](CTxOut out) { outputs.push_back(std::move(out)); return uint32_t(outputs.size() - 1); }}; const uint32_t sixteen_sigops_idx{add_output(CTxOut{5000, GetScriptForDestination(ScriptHash(sixteenSigops))})}; CMutableTransaction txFrom; txFrom.vout = std::move(outputs); AddCoins(coins, CTransaction(txFrom), 0); ``` Then the spending transactions can use `sixteen_sigops_idx` instead of `5`.
alexanderwiederin (Migrated from github.com) reviewed 2026-11-06 10:23:00 +00:00
alexanderwiederin (Migrated from github.com) commented 2026-11-06 10:23:00 +00:00

That said, any of the three approaches would be an improvement over the trailing comments, in my view.

That said, any of the three approaches would be an improvement over the trailing comments, in my view.
alexanderwiederin commented 2026-11-06 10:23:47 +00:00 (Migrated from github.com)

Concept ACK

Great to see this.

Concept ACK Great to see this.
yuvicc commented 2026-11-06 14:12:07 +00:00 (Migrated from github.com)

Addressed some suggestions:

  • Took @purpleKarrot's /[i]=/ suggestion. I kept the short descriptions for [0]–[2]. I didn't do vout[9] = …, since indexed writes are what #36692 is trying to remove.
  • @maflcko's nit: moved both declarations down to where they're built.
  • Addressed the linter's named-arg suggestion
Addressed some suggestions: - Took @purpleKarrot's /*[i]=*/ suggestion. I kept the short descriptions for [0]–[2]. I didn't do `vout[9] = …`, since indexed writes are what #36692 is trying to remove. - @maflcko's nit: moved both declarations down to where they're built. - Addressed the linter's named-arg suggestion
alexanderwiederin commented 2026-11-06 17:46:48 +00:00 (Migrated from github.com)

ACK a4a2647834

Re-checked that the constructed transactions are unchanged.

ACK a4a2647834a Re-checked that the constructed transactions are unchanged.
purpleKarrot commented 2026-11-06 17:55:42 +00:00 (Migrated from github.com)

ACK a4a2647834

Excellent work.

ACK a4a2647834ad0cc4576b2eb38bddf02c42081173 Excellent work.
purpleKarrot (Migrated from github.com) approved these changes 2026-11-06 20:53:05 +00:00
maflcko commented 2026-11-07 10:14:36 +00:00 (Migrated from github.com)

review ACK a4a2647834 👒

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK a4a2647834ad0cc4576b2eb38bddf02c42081173 👒
DXAObZQn/RfISpnDaAfgX5XYIirO0W6MWrCGFC8zKg2DtIINpcfyuKpbUuA1U4FJVCKY4rb946ejph7XnfWYBw==
review ACK a4a2647834ad0cc4576b2eb38bddf02c42081173 👒 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK a4a2647834ad0cc4576b2eb38bddf02c42081173 👒 DXAObZQn/RfISpnDaAfgX5XYIirO0W6MWrCGFC8zKg2DtIINpcfyuKpbUuA1U4FJVCKY4rb946ejph7XnfWYBw== ``` </details>
janb84 commented 2026-11-07 13:20:39 +00:00 (Migrated from github.com)

ACK a4a2647834

Checked that outcomes are equal.

ACK a4a2647834ad0cc4576b2eb38bddf02c42081173 Checked that outcomes are equal.
jpk68 commented 2026-11-08 00:11:39 +00:00 (Migrated from github.com)
ACK a4a2647834ad0cc4576b2eb38bddf02c42081173
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36788
No description provided.