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

pull yuvicc wants to merge 3 commits into bitcoin:master from yuvicc:test-declarative-txpackage-p2sh changing 3 files +132 −145
  1. yuvicc commented at 5:09 AM on November 6, 2026: contributor

    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).
  2. test: construct txpackage_tests inputs/outputs declaratively
    Replace the field-by-field construction of the inputs and outputs in
    create_placeholder_tx, mtx_child1 and mtx_parent2_v1 with COutPoint,
    CTxIn and CTxOut constructor calls.
    
    As in BuildSpendingTransaction, the scriptWitness assignment must come
    after vin is replaced, since CTxIn has no witness constructor argument.
    
    In create_placeholder_tx, the random values are drawn in the same order
    as before, so the placeholder transactions are unchanged.
    
    The constructed transactions are unchanged.
    5336eaa7fa
  3. DrahtBot commented at 5:09 AM on November 6, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    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 <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-->

  4. in src/test/script_p2sh_tests.cpp:346 in a31519503f
     355 | +        CTxOut{5000, GetScriptForDestination(ScriptHash(fifteenSigops))}, // vout[4]
     356 | +        CTxOut{5000, GetScriptForDestination(ScriptHash(sixteenSigops))}, // vout[5]
     357 | +        CTxOut{3000, GetScriptForDestination(ScriptHash(twentySigops))}, // vout[6]
     358 | +        CTxOut{1000, no_sigops}, // vout[7]
     359 | +        CTxOut{1000, GetScriptForDestination(ScriptHash(op_return_script))}, // vout[8]
     360 | +        CTxOut{1000, witnessUnknown}, // vout[9]
    


    maflcko commented at 7:17 AM on November 6, 2026:

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


    purpleKarrot commented at 9:47 AM on November 6, 2026:

    What about

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

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


    alexanderwiederin commented at 10:04 AM on November 6, 2026:

    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.


    alexanderwiederin commented at 10:23 AM on November 6, 2026:

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

  5. in src/bench/duplicate_inputs.cpp:39 in a31519503f


    maflcko commented at 7:18 AM on November 6, 2026:

    nit: Move down to make review easier?

  6. purpleKarrot commented at 9:51 AM on November 6, 2026: contributor

    Great work! ACK

    Maybe apply the changes recommended by the LLM linter.

  7. alexanderwiederin commented at 10:23 AM on November 6, 2026: contributor

    Concept ACK

    Great to see this.

  8. bench: construct duplicate_inputs inputs/outputs declaratively
    Replace the field-by-field construction of the coinbase input and
    output, and of the naughtyTx output, in DuplicateInputs with COutPoint,
    CTxIn and CTxOut constructor calls.
    
    The constructed transactions are unchanged.
    7fc7d26e75
  9. test: construct script_p2sh_tests inputs/outputs declaratively
    Replace field-by-field construction of inputs and outputs with
    COutPoint, CTxIn and CTxOut constructor calls.
    
    Outputs previously created by vout.resize() without a value now spell
    out the null nValue (-1) explicitly. Loop indices become uint32_t to
    match COutPoint::n, since brace-initialization rejects the narrowing.
    
    The scriptSig mutations after signing are intentional and kept.
    
    The constructed transactions are unchanged.
    a4a2647834
  10. yuvicc force-pushed on Nov 6, 2026
  11. yuvicc commented at 2:12 PM on November 6, 2026: contributor

    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
  12. alexanderwiederin commented at 5:46 PM on November 6, 2026: contributor

    ACK a4a2647834a

    Re-checked that the constructed transactions are unchanged.

  13. DrahtBot requested review from purpleKarrot on Nov 6, 2026
  14. purpleKarrot commented at 5:55 PM on November 6, 2026: contributor

    ACK a4a2647834ad0cc4576b2eb38bddf02c42081173

    Excellent work.

  15. purpleKarrot approved
  16. maflcko commented at 10:14 AM on November 7, 2026: member

    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>

  17. janb84 commented at 1:20 PM on November 7, 2026: contributor

    ACK a4a2647834ad0cc4576b2eb38bddf02c42081173

    Checked that outcomes are equal.

  18. jpk68 commented at 12:11 AM on November 8, 2026: contributor

    ACK a4a2647834ad0cc4576b2eb38bddf02c42081173

  19. sedited merged this on Nov 8, 2026
  20. sedited closed this on Nov 8, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-18 16:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me