test: make script_combineSigs and spends_witness_prog cases independent #36794

pull alexanderwiederin wants to merge 2 commits into bitcoin:master from alexanderwiederin:script_test_split changing 2 files +211 −178
  1. alexanderwiederin commented at 7:11 PM on November 6, 2026: contributor

    Part of #36692: remove test state that is shared and modified across cases.

    • script_combineSigs: The P2PKH, P2SH and multisig cases shared one funding transaction, whose scriptPubkey was modified between them, and one keystore. Each case is now its own test with its own keys, keystore and funding transaction.
    • spends_witness_prog: every output type reused the same transactions and coins view. The P2SH-wrapped cases relied on the scriptPubkey left by the previous case and had to clear the scriptSig they set. Each check now builds fresh state, and the scripts are named.

    The checks are unchanged.

  2. DrahtBot added the label Tests on Nov 6, 2026
  3. DrahtBot commented at 7:11 PM 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.

    Type Reviewers
    ACK yuvicc, janb84

    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:

    • #36466 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36466.svg"></sub> (policy: make unstructured Taproot annexes standard by RobinLinus)
    • #36122 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr)

    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. alexanderwiederin marked this as a draft on Nov 6, 2026
  5. alexanderwiederin force-pushed on Nov 6, 2026
  6. alexanderwiederin force-pushed on Nov 6, 2026
  7. DrahtBot added the label CI failed on Nov 6, 2026
  8. DrahtBot removed the label CI failed on Nov 6, 2026
  9. yuvicc commented at 6:49 AM on November 7, 2026: contributor

    Concept ACK

  10. alexanderwiederin marked this as ready for review on Nov 9, 2026
  11. alexanderwiederin force-pushed on Nov 9, 2026
  12. in src/test/script_tests.cpp:1290 in d139d58694
    1297 |  
    1298 | -    CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(PKHash(keys[0].GetPubKey())));
    1299 | -    CMutableTransaction txTo = BuildSpendingTransaction(CScript(), CScriptWitness(), CTransaction(txFrom));
    1300 | -    CScript& scriptPubKey = txFrom.vout[0].scriptPubKey;
    1301 | -    SignatureData scriptSig;
    1302 | +// Test the ProduceSignature's ability to combine signatures function
    


    yuvicc commented at 1:14 PM on November 9, 2026:

    I think this comment can be moved above to CombineSigsTest as it describes all three cases?

  13. in src/test/script_tests.cpp:1281 in d139d58694
    1284 | -        CKey key = GenerateRandomKey(/*compressed=*/i%2 == 1);
    1285 | -        keys.push_back(key);
    1286 | -        pubkeys.push_back(key.GetPubKey());
    1287 | -        BOOST_CHECK(keystore.AddKey(key));
    1288 | +        for (int i = 0; i < 3; i++)
    1289 | +        {
    


    yuvicc commented at 1:22 PM on November 9, 2026:

    as per developer notes braces should be in the same line and ++i is preferred over i++ (link).


    alexanderwiederin commented at 2:35 PM on November 9, 2026:

    Taken - thanks!

  14. in src/test/script_tests.cpp:1326 in d139d58694
    1343 | +    CMutableTransaction txTo{BuildSpendingTransaction(CScript{}, CScriptWitness{}, txFrom)};
    1344 | +
    1345 | +    SignatureData empty;
    1346 | +    SignatureData dummy;
    1347 | +    BOOST_CHECK(SignSignature(keystore, txFrom, txTo, /*nIn=*/0, SIGHASH_ALL, dummy));
    1348 | +    SignatureData scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
    


    yuvicc commented at 1:26 PM on November 9, 2026:

    doesn't harm but we could keep the label here as well?

        SignatureData scriptSig = DataFromTransaction(txTo, /*nIn=*/0, txFrom.vout[0])
    
  15. yuvicc commented at 2:20 PM on November 9, 2026: contributor

    crACK 1f9802c192432717d06bc0bb94d3dc22aae2ec4f

    I went through both diffs and the checks match.

    Left some non-blocking nits.

  16. test: split script_combineSigs into independent test cases
    The P2PKH, P2SH and multisig cases shared one funding transaction, whose
    scriptPubKey was modified between them, and one keystore.
    
    Give each case its own test with its own keys, keystore and const
    funding transaction. The checks are unchanged.
    96de98e4d7
  17. alexanderwiederin force-pushed on Nov 9, 2026
  18. yuvicc commented at 6:24 AM on November 10, 2026: contributor

    ACK 26d2f7625a56f2fa6804aac4a6c033eaa91eadca

  19. in src/test/transaction_tests.cpp:1368 in 26d2f7625a outdated
    1492 | +BOOST_AUTO_TEST_CASE(spends_witness_prog_p2a)
    1493 | +{
    1494 | +    std::vector<std::vector<uint8_t>> sol_dummy;
    1495 | +    const CScript p2a{GetScriptForDestination(PayToAnchor{})};
    1496 | +    BOOST_CHECK_EQUAL(Solver(p2a, sol_dummy), TxoutType::ANCHOR);
    1497 | +    BOOST_CHECK(!SpendsWitnessProg(p2a));
    


    janb84 commented at 6:47 PM on November 10, 2026:

    NIT (non-blocking); with the name change of the helper, this case can be a bit confusing. A clarifying comment can help

        // P2A is a witness program, but anchor spends are excluded.
        BOOST_CHECK(!SpendsWitnessProg(p2a));
    

    alexanderwiederin commented at 8:19 PM on November 10, 2026:

    Taken - thanks!

  20. in src/test/script_tests.cpp:1307 in 26d2f7625a outdated
    1317 |      combined = CombineSignatures(txFrom.vout[0], txTo, scriptSig, empty);
    1318 |      BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
    1319 |      combined = CombineSignatures(txFrom.vout[0], txTo, empty, scriptSig);
    1320 |      BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
    1321 |      SignatureData scriptSigCopy = scriptSig;
    1322 |      // Signing again will give a different, valid signature:
    


    janb84 commented at 7:12 PM on November 10, 2026:

    Note: Old problem but this comment is not correct. Easy to check; BOOST_CHECK_EQUAL(scriptSig.scriptSig, scriptSigCopy.scriptSig);

    Not something I suggest to fix in this PR.


    alexanderwiederin commented at 8:21 PM on November 10, 2026:

    Thanks - good catch!

  21. janb84 commented at 7:13 PM on November 10, 2026: contributor

    ACK 26d2f7625a56f2fa6804aac4a6c033eaa91eadca

    It matches the recent "declarative tests" series :) Each new test case makes the same assertions as the old code, in the same order, with the same expected values.

  22. test: split spends_witness_prog into independent test cases
    The test reused funding transaction, spending transaction and coins view
    for every output type, modifying them between checks. The P2SH-wrapped
    cases relied on the scriptPubkey left by the previous case, and each one
    had to clear the scriptSig it set.
    
    Give each output type its own test case with its own key and scripts,
    and check each spend with a helper that builds fresh transactions and a
    fresh coins view. The checks are unchanged.
    7358d35bb0
  23. alexanderwiederin force-pushed on Nov 10, 2026
  24. yuvicc commented at 4:47 AM on November 11, 2026: contributor

    re-ACK 7358d35bb01dfc9ba844747dbf27b58c5482b066

    <details> <summary>Show signature</summary> ```bash -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512

    re-ACK 7358d35bb01dfc9ba844747dbf27b58c5482b066 -----BEGIN PGP SIGNATURE-----

    iJEEARYKADkWIQRxIqfV4fHauqeDZkLHO83HCSJ4EQUCavPzBhsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwwLDMACgkQxzvNxwkieBH7MAEAg/CcUjT+GTywtxOE8MZr AdPwyBUzBEIgOPLZyTBoyQcBAOuCEIcJxmBDTJyWV4PRFnqqI4gOnipGrgT7p+qt E8oH =53QK -----END PGP SIGNATURE-----

    </details>
    
  25. DrahtBot requested review from janb84 on Nov 11, 2026
  26. janb84 commented at 8:37 AM on November 11, 2026: contributor

    re ACK 7358d35bb01dfc9ba844747dbf27b58c5482b066

    Thanks for taking my suggestion. LGTM !


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