test: make `tx_mempool_block_doublespend` cases independent #36830

pull alexanderwiederin wants to merge 2 commits into bitcoin:master from alexanderwiederin:split-txvalidationcache_tests changing 1 files +54 −50
  1. alexanderwiederin commented at 5:48 PM on November 10, 2026: contributor

    Found during #36692: remove test state that is shared and modified across cases.

    tx_mempool_block_doublespend ran four cases against one chain and mempool, removing each case’s mempool transaction by hand before the next one. Each case is now its own test with a fresh setup that builds the two spends. The first commit also fixes the last case’s comment, which had the mempool and block spends reversed. The checks are unchanged.

    The second commit makes the two spends distinct transactions. Previously they were identical (deterministic signing), so in the last case the mempool transaction was removed because it was mined rather than as a conflict. The rejection cases are unaffected: they fail with bad-txns-inputs-missingorspent either way.

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

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. test: split tx_mempool_block_doublespend into independent test cases
    The cases shared one chain and mempool, and had to remove the
    transaction each one added to the mempool before the next case.
    
    Give each case its own test with a fresh setup that builds the two
    spends, and fix the comment of the last case, which had the mempools and
    block spends reversed. The checks are unchanged.
    07540640aa
  5. alexanderwiederin force-pushed on Nov 10, 2026
  6. DrahtBot added the label CI failed on Nov 10, 2026
  7. DrahtBot removed the label CI failed on Nov 10, 2026
  8. in src/test/txvalidationcache_tests.cpp:32 in 07540640aa
      46 | +// double-spends in blocks to pass validation when they should not.
      47 | +struct DoubleSpendSetup : public Dersig100Setup {
      48 | +    const CScript scriptPubKey{CScript{} << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG};
      49 | +
      50 | +    // Returns a signed spend of the first mature coinbase txn.
      51 | +    CMutableTransaction MakeSpend() const
    


    yuvicc commented at 5:51 AM on November 11, 2026:

    Maybe we can use the helper already provided by setup_common.h: CreateValidMempoolTransaction() instead of creating by hand? this would drop the const-ness but is that a problem?


    alexanderwiederin commented at 8:50 AM on November 11, 2026:

    Good idea, but CreateValidMempoolTransaction builds the transactions slightly differently (version 2 and an RBF nSequence instead of version 1 and final), so it would change the test’s transactions, while the first commit should be a pure refactoring. I’d prefer to keep MakeSpend here - at least for now.

  9. in src/test/txvalidationcache_tests.cpp:91 in 07540640aa outdated
     131 | +}
     132 |  
     133 | -    // Final sanity test: first spend in *m_node.mempool, second in block, that's OK:
     134 | -    std::vector<CMutableTransaction> oneSpend;
     135 | -    oneSpend.push_back(spends[0]);
     136 | +BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend_one_in_mempool_other_in_block, DoubleSpendSetup)
    


    yuvicc commented at 6:07 AM on November 11, 2026:

    the last case could assert more: something like spends[0] and spends[1] have different hashes? Also, there is typo in commit message determinitsic -> deterministic in second commit.


    alexanderwiederin commented at 9:05 AM on November 11, 2026:

    Taken - thanks!

  10. yuvicc commented at 6:08 AM on November 11, 2026: contributor

    cr-ACK 19bb40c9872b8695c45e8a977398cb294eb64187

    Verified that the checks match.

  11. test: make tx_mempool_block_doublespend spends conflicting
    Both spends were built identically and signed with deterministic nonces,
    so they were the same transaction rather than a double-spend. In the
    last case, the mempool transaction was therefore removed because it was
    mined, not because it conflicted with the block.
    
    Give the spends a different output values so they are actually
    conflicting transactions.
    0d98c438eb
  12. alexanderwiederin force-pushed on Nov 11, 2026
  13. yuvicc commented at 6:09 PM on November 11, 2026: contributor

    lgtm ACK 0d98c438ebc124ca4252bdd2855d62691e030e58

    <details> <summary>signature</summary>

    iJEEARYKADkWIQRxIqfV4fHauqeDZkLHO83HCSJ4EQUCavSuehsUgAAAAAAEAA5t
    YW51MiwyLjUrMS4xMiwwLDMACgkQxzvNxwkieBEa3gEAvJU8Pjvey0r2cuS/D4mX
    npg5+DCKk0NsYGRzgat+A2AA/jY4TkI2FmjtjVAw6YJIaDw6EUTTlDvSXJxvFwsQ
    pd8F
    =xcDI
    

    </details>


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