test: Use consistent assert functions #26356

pull NorrinRadd wants to merge 2 commits into bitcoin:master from NorrinRadd:issue/23119/part-1 changing 3 files +31 −21
  1. NorrinRadd commented at 6:46 PM on October 20, 2022: none

    ref #23119: Updated a subset of the test cases to get approach feedback before making a large amount of changes that may need to change again.

    Approach:

    • assert_equal is preferred over assert where possible.
    • A matching assert_not_equal function has been added also.
    • Where assert_equal is not possible, the built-in assert function will be used.

    Rationale: This has been discussed in a few PRs / Issue. The most recent consensus is that a minimal approach is best.

  2. NorrinRadd renamed this:
    test: Use a consistent assert functions: ref #23119
    test: Use a consistent assert functions
    on Oct 20, 2022
  3. NorrinRadd renamed this:
    test: Use a consistent assert functions
    test: Use consistent assert functions
    on Oct 20, 2022
  4. DrahtBot added the label Tests on Oct 20, 2022
  5. DrahtBot commented at 11:47 PM on October 20, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK shaavan

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26257 (script, test: python linter fixups and updates by jonatack)
    • #23502 (wallet: Avoid underpaying transaction fees when signing taproot spends 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.

  6. shaavan commented at 8:05 AM on October 21, 2022: contributor

    Concept ACK on using the consistent assert function.

    However, I am skeptical of this statement.

    Other variations of assert will be removed.

    There are many variations of assert in test/test_framework/util.py, and all serve different purposes. For example, assert_is_hex_string will be used in the case of verifying hex strings. If we eliminate all variants other than assert_equal and assert_not_equal, it will increase the verbosity of the assert code on the usage side, making maintaining and debugging code a challenge.

    IMO, I would rather have a bunch of variations of assert statements based on a different case, maintained in the same file, and used consistently throughout the codebase than have only a minimal amount of functions implemented and use them to write custom code on the usage side.

  7. in .gitignore:59 in ce71207e09 outdated
      55 | @@ -56,6 +56,7 @@ src/qt/bitcoin-qt.creator.user
      56 |  src/qt/bitcoin-qt.files
      57 |  src/qt/bitcoin-qt.includes
      58 |  
      59 | +tags
    


    brunoerg commented at 11:48 AM on October 25, 2022:

    Reason for this?


    NorrinRadd commented at 11:17 PM on October 26, 2022:

    This is the tags indexing file that IDEs use for quickly navigating to symbols within the project. It updates as changes happen so it is also not static.


    sipa commented at 11:24 PM on October 26, 2022:

    You can add it to your personal git config then. It's not specific to the project.

  8. NorrinRadd commented at 12:01 AM on October 27, 2022: none

    That is an important distinction. assert and assert_equal will be used where possible.

    Concept ACK on using the consistent assert function.

    However, I am skeptical of this statement.

    Other variations of assert will be removed.

    There are many variations of assert in test/test_framework/util.py, and all serve different purposes. For example, assert_is_hex_string will be used in the case of verifying hex strings. If we eliminate all variants other than assert_equal and assert_not_equal, it will increase the verbosity of the assert code on the usage side, making maintaining and debugging code a challenge.

    IMO, I would rather have a bunch of variations of assert statements based on a different case, maintained in the same file, and used consistently throughout the codebase than have only a minimal amount of functions implemented and use them to write custom code on the usage side.

    Yes, that's an important point. I'll update the summary accordingly and also revert some of the removals of assert_greater_than, as I can see in previous PRs that function was acceptable.

  9. NorrinRadd force-pushed on Oct 27, 2022
  10. Use a consistent assert functions: ref #23119
    Updated a subset of the test cases to get approach feedback.
    
    assert_equal is preferred over assert where possible.
    A matching assert_not_equal function has been added also.
    Where assert_equal is not possible, the built-in assert function will be used.
    6534222196
  11. NorrinRadd force-pushed on Oct 27, 2022
  12. NorrinRadd commented at 9:56 PM on October 31, 2022: none

    Any more issues? Is this good to merge? Once accepted I can make these changes to the other TC files and hopefully close out #23119

  13. in test/functional/test_framework/util.py:66 in 6534222196 outdated
      63 | +def assert_not_equal(thing1, thing2, *args, err_msg=None):
      64 | +    if thing1 == thing2 or any(thing1 == arg for arg in args):
      65 | +        msg = "%s" % " == ".join(str(arg) for arg in (thing1, thing2) + args)
      66 | +        if err_msg is not None:
      67 | +            msg = err_msg
      68 | +        raise AssertionError(msg)
    


    shaavan commented at 6:33 PM on November 1, 2022:

    nit: I think you can update code to make it consistent with the assert_equal function.

            if err_msg is None:
                    err_msg = "%s" % " == ".join(str(arg) for arg in (thing1, thing2) + args)
            raise AssertionError(err_msg)
    

    NorrinRadd commented at 7:27 PM on November 2, 2022:

    This makes sense. More efficient.

  14. Get rid of unnecessary variable
    Co-authored-by: Shashwat Vangani <shaavan.github@gmail.com>
    04966478c5
  15. in test/functional/feature_segwit.py:260 in 6534222196 outdated
     256 | @@ -256,7 +257,7 @@ def run_test(self):
     257 |          txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
     258 |          raw_tx = self.nodes[0].getrawtransaction(txid, True)
     259 |          tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
     260 | -        assert_greater_than_or_equal(tmpl['sizelimit'], 3999577)  # actual maximum size is lower due to minimum mandatory non-witness data
     261 | +        assert_greater_than_or_equal(tmpl['sizelimit'], 3999577) # actual maximum size is lower due to minimum mandatory non-witness data
    


    aureleoules commented at 5:32 PM on November 21, 2022:

    this can be removed (useless change)

  16. aureleoules approved
  17. aureleoules commented at 6:48 PM on November 21, 2022: member

    LGTM. I think you should squash the commits.

  18. DrahtBot added the label Needs rebase on Dec 9, 2022
  19. DrahtBot commented at 5:32 PM on December 9, 2022: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

  20. fanquake marked this as a draft on Feb 6, 2023
  21. fanquake commented at 3:07 PM on February 6, 2023: member

    Moved to draft for now. Seems like there could be agreement on making this change, but it needs rebasing (2 months), changes need squashing, needs review comments addressing.

  22. fanquake commented at 12:16 PM on March 20, 2023: member

    Closing for now. Looks like the user has also disspeared off GitHub.

  23. fanquake closed this on Mar 20, 2023

  24. bitcoin locked this on Mar 19, 2024

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-04-28 06:13 UTC

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