test: add unit test coverage for the empty leaves path in MerkleComputation #33858

pull frankomosh wants to merge 1 commits into bitcoin:master from frankomosh:merkle-empty-path changing 1 files +5 −0
  1. frankomosh commented at 0:08 am on November 12, 2025: contributor

    As noted in #32243 (comment), the early return inside MerkleComputation when leaves.size() == 0 was only exercised by fuzz tests.

    The existing merkle_test_empty_block calls BlockMerkleRoot, which uses ComputeMerkleRoot, but does not exercise the TransactionMerklePathComputeMerklePathMerkleComputation code path.

    Coverage before adding test:

    Coverage after adding test:

  2. test: exercise TransactionMerklePath with empty block; targets the MerkleComputation empty-leaves path that was only reached by fuzz tests ffcae82a68
  3. DrahtBot added the label Tests on Nov 12, 2025
  4. DrahtBot commented at 0:08 am on November 12, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33858.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK kevkevinpal, brunoerg, maflcko, sedited

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

  5. maflcko commented at 8:14 am on November 12, 2025: member

    Coverage before adding test:

    Coverage after adding test:

    I don’t think those links work. Also, this is redundant to the corecheck result anyway?

  6. frankomosh commented at 11:16 am on November 12, 2025: contributor

    I don’t think those links work.

    I’m not sure why they didn’t render correctly here. [Edit: I think it renders now]

    Also, this is redundant to the corecheck result anyway?

    I included them mainly to visually show % increase, but you’re right that they may be redundant. (also, I think you have been against adding tests without showing any proof of coverage)

  7. kevkevinpal commented at 3:07 pm on November 12, 2025: contributor

    ACK ffcae82

    According to corecheck it looks like there was an increase in coverage https://corecheck.dev/bitcoin/bitcoin/pulls/33858

  8. in src/test/merkle_tests.cpp:160 in ffcae82a68
    153@@ -154,6 +154,11 @@ BOOST_AUTO_TEST_CASE(merkle_test_empty_block)
    154 
    155     BOOST_CHECK_EQUAL(root.IsNull(), true);
    156     BOOST_CHECK_EQUAL(mutated, false);
    157+
    158+    // Verify TransactionMerklePath handles empty block correctly
    159+    // This tests the early-return path in MerkleComputation
    160+    std::vector<uint256> merkle_path = TransactionMerklePath(block, 0);
    


    brunoerg commented at 7:24 pm on November 20, 2025:

    nit:

    0    std::vector<uint256> merkle_path = TransactionMerklePath(block, /*position=*/0);
    

    frankomosh commented at 7:17 pm on November 24, 2025:
    Thanks for suggestion. Can we keep it this way for now?
  9. brunoerg approved
  10. brunoerg commented at 7:28 pm on November 20, 2025: contributor

    code review ACK ffcae82a68104c1992964b26c592b62cbca391bf

    It’s just a simple test addition to exercise MerkleComputation with an empty vector of leaves, it’s ok. Note that it just checks the path is empty which is fine since there is a proposal to remove the unused pmutated and proot (https://github.com/bitcoin/bitcoin/pull/33805).

  11. maflcko commented at 10:26 am on November 21, 2025: member
    lgtm ACK ffcae82a68104c1992964b26c592b62cbca391bf
  12. sedited approved
  13. sedited commented at 1:35 pm on December 4, 2025: contributor

    ACK ffcae82a68104c1992964b26c592b62cbca391bf

    rfm?

  14. frankomosh commented at 12:22 pm on December 5, 2025: contributor

    rfm?

    I think it is

  15. fanquake merged this on Dec 5, 2025
  16. fanquake closed this on Dec 5, 2025

  17. frankomosh deleted the branch on Dec 6, 2025

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: 2025-12-23 03:13 UTC

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