test: Add encodable PUSHDATA1 examples to feature_taproot #32114

pull instagibbs wants to merge 1 commits into bitcoin:master from instagibbs:2025-03-taproot_tests changing 1 files +46 −3
  1. instagibbs commented at 4:07 pm on March 21, 2025: member

    Inspired by discussion in #31640 (comment) I made an example adding coverage I think is missing, with some extra commentary that might help future contributors (including myself when I forget how it works again).

    Open for suggestions how we can make it more welcoming beyond this.

    cc darosior EthanHeilman sipa

  2. DrahtBot commented at 4:07 pm on March 21, 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/32114.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK janb84, fjahr
    Concept ACK darosior, rkrux

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Tests on Mar 21, 2025
  4. darosior commented at 5:27 pm on March 21, 2025: member
    Nice. Concept ACK on having an example there.
  5. fjahr commented at 8:45 pm on March 23, 2025: contributor

    Concept ACK

    Not sure about having the documentation to add new spenders mixed within this particular set of spenders. What if I want to add new spenders Maybe it would be better in a comment block at the top of the test or in the docstring of spenders_taproot_active?

  6. in test/functional/feature_taproot.py:655 in 69d5334c01 outdated
    651@@ -652,6 +652,30 @@ def spenders_taproot_active():
    652 
    653     spenders = []
    654 
    655+    # === To add a spender: ===
    


    rkrux commented at 12:40 pm on March 24, 2025:

    I agree with this comment #32114 (comment) that commentary like this can be put in a more “generic” place like the Spender tuple declaration here: https://github.com/bitcoin/bitcoin/blob/770d39a37652d40885533fecce37e9f71cc0d051/test/functional/feature_taproot.py#L465-L480

    Something that lets the reader/tester quickly know in a generic way on how to use the Spender tuple, i.e.

    1. make_spender
    2. add_spender
    3. test_spender

    One more (smaller) reason to avoid adding here is that the above flow is also used in the spenders_taproot_nonstandard function, someone updating that function (although rarely) might miss the commentary here.


    instagibbs commented at 1:08 pm on March 24, 2025:
    I find that particular code block really tucked away and hard to find fwiw.

    rkrux commented at 1:26 pm on March 24, 2025:

    True. I mentioned it because one would end up looking at it once they see make_spender. This place would be more useful if the Spender type was also used more in the test such as while initialising the spenders list.

    I find right at the top a suitable alternative as well though I missed this section entirely the first time I read the test: https://github.com/bitcoin/bitcoin/blob/770d39a37652d40885533fecce37e9f71cc0d051/test/functional/feature_taproot.py#L121

    Fine either way.


    rkrux commented at 1:58 pm on March 24, 2025:

    Open for suggestions how we can make it more welcoming beyond this.

    One point I want to mention is that initially it was not evident to me that a spender is a test case in itself until I saw err_msg being a part of it. Technically this is mentioned in the file albeit in a buried location: https://github.com/bitcoin/bitcoin/blob/770d39a37652d40885533fecce37e9f71cc0d051/test/functional/feature_taproot.py#L1330

    A more elaborate name like spender_test_case or spender_tc would be useful but Idk if it’s feasible to incorporate a relatively bigger change like this now. If not, then maybe highlighting this comment by extracting it out could be useful as well.

  7. instagibbs commented at 12:56 pm on March 24, 2025: member
    @fjahr I could do that, where the comment is literal examples that aren’t an attempt to expand coverage. I think seeing it right at the top could be helpful
  8. rkrux commented at 1:05 pm on March 24, 2025: contributor

    Concept ACK

    Putting in my 2 sats here because I recently had the opportunity to go through this test couple weeks back. Although it took me some time to understand the overall structure of the test but I was able to appreciate it soon after.

  9. instagibbs commented at 2:14 pm on March 24, 2025: member

    @rkrux pushed an update with another related direction. Ideally a new contributor can add a set of spenders under a new function, aggregate to the list, without having to touch the current walls of current spender making functions?

    Let me know if I’m getting warmer.

  10. rkrux commented at 2:54 pm on March 24, 2025: contributor

    Nice, I like this approach. In addition to making it easier to onboard by adding the commentary, it also helps in not increasing the size of the spenders_taproot_active, which is more than 500 lines long already.

    I will look at it in detail soon.

  11. rkrux commented at 1:46 pm on March 25, 2025: contributor
    The new design also allows for using different keys and pubs in different tests instead of using one set in all the tests. The overall commentary looks great, the commits can be cleaned up.
  12. test: Add encodable PUSHDATA1 examples to feature_taproot 3dd29b12e1
  13. instagibbs force-pushed on Mar 25, 2025
  14. instagibbs commented at 1:48 pm on March 25, 2025: member
    @rkrux done thanks
  15. in test/functional/feature_taproot.py:1237 in 3dd29b12e1
    1229@@ -1230,6 +1230,41 @@ def spenders_taproot_nonstandard():
    1230 
    1231     return spenders
    1232 
    1233+def sample_spenders():
    1234+
    1235+    # Create key(s) for output creation, as well as key and script-spends
    1236+    secs = [generate_privkey() for _ in range(2)]
    1237+    pubs = [compute_xonly_pubkey(sec)[0] for sec in secs]
    


    EthanHeilman commented at 0:52 am on March 27, 2025:
    Why are two secs and two pubs created if only one is used? Is to show a pattern of generating more than one so other people can add additional tests to this?

    instagibbs commented at 12:57 pm on March 27, 2025:
    yep, don’t feel strongly on this one but that’s probably an expected pattern
  16. in test/functional/feature_taproot.py:1233 in 3dd29b12e1
    1229@@ -1230,6 +1230,41 @@ def spenders_taproot_nonstandard():
    1230 
    1231     return spenders
    1232 
    1233+def sample_spenders():
    


    EthanHeilman commented at 0:55 am on March 27, 2025:
    This is helpful for understanding how to write these tests. I might make sense to put this as the first testcase just below # === Actual test cases ===. I worry people might not scroll down the 600 lines to find this. It is a good introduction to the rest of the tests

    instagibbs commented at 12:57 pm on March 27, 2025:
    Seems like a matter of taste; leaving as-is for now?

    rkrux commented at 1:06 pm on March 27, 2025:
    Though a practical suggestion but I think it can be left as-is. It’s highly likely that the reader would go through the run_test() from where they can navigate to the implementation of sample_spenders().
  17. EthanHeilman commented at 0:55 am on March 27, 2025: contributor
    ut_ack
  18. janb84 commented at 12:19 pm on March 27, 2025: contributor

    LGTM ACK 3dd29b1

    • Tested ✅

    Given the complexity it is nice to have examples.

  19. DrahtBot requested review from darosior on Mar 27, 2025
  20. DrahtBot requested review from rkrux on Mar 27, 2025
  21. DrahtBot requested review from fjahr on Mar 27, 2025
  22. fjahr commented at 2:22 pm on March 27, 2025: contributor
    Code review ACK 3dd29b12e1931147145251944d4a1b733be841f9

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-03-28 15:12 UTC

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