test: Use test framework utils in functional tests #28528

pull osagie98 wants to merge 1 commits into bitcoin:master from osagie98:replace-bare-asserts changing 74 files +422 −260
  1. osagie98 commented at 4:14 am on September 25, 2023: none

    Replaces bare asserts with test framework utils across both the functional tests and the test framework itself.

    Also adds the assert_not_equal, assert_less_than, and assert_less_than_or_equal util functions for greater readability.

    Fixes #23119.

  2. DrahtBot commented at 4:14 am on September 25, 2023: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK BrandonOdiwuor

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29007 (test: create deterministic addrman in the functional tests by stratospher)
    • #28926 (rpc: add ‘getnetmsgstats’ RPC by willcl-ark)
    • #28890 (rpc: Remove deprecated -rpcserialversion by maflcko)
    • #28550 (Covenant tools softfork by jamesob)
    • #28312 (test: fix keys_to_multisig_script (P2MS) helper for n/k > 16 by theStack)
    • #28307 (rpc, wallet: fix incorrect segwit redeem script size limit by furszy)
    • #21283 (Implement BIP 370 PSBTv2 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.

  3. DrahtBot added the label Tests on Sep 25, 2023
  4. DrahtBot added the label CI failed on Sep 25, 2023
  5. osagie98 marked this as ready for review on Sep 25, 2023
  6. osagie98 commented at 5:16 am on September 25, 2023: none
    Though the change is simple, it touches a ton of files. I can break it into multiple PRs if that makes sense.
  7. DrahtBot removed the label CI failed on Sep 25, 2023
  8. maflcko requested review from theStack on Sep 26, 2023
  9. DrahtBot added the label Needs rebase on Oct 5, 2023
  10. maflcko commented at 4:56 pm on October 5, 2023: member
    @theStack Added you as reviewer/mentor, because the issue was opened by you
  11. theStack commented at 9:40 pm on October 5, 2023: contributor
    @osagie98: Can you squash the commits and rebase on master? Happy to review.
  12. osagie98 force-pushed on Oct 6, 2023
  13. osagie98 commented at 5:53 am on October 6, 2023: none
    @theStack done (I hope, still getting used to the GitHub workflow). Let me know if you’ll need anything else
  14. DrahtBot removed the label Needs rebase on Oct 6, 2023
  15. DrahtBot added the label Needs rebase on Oct 8, 2023
  16. osagie98 force-pushed on Oct 12, 2023
  17. DrahtBot removed the label Needs rebase on Oct 12, 2023
  18. DrahtBot added the label Needs rebase on Oct 19, 2023
  19. osagie98 force-pushed on Oct 24, 2023
  20. osagie98 commented at 4:21 pm on October 24, 2023: none
    Hi @theStack, any chance you’d be able to review this?
  21. DrahtBot removed the label Needs rebase on Oct 24, 2023
  22. DrahtBot added the label CI failed on Oct 24, 2023
  23. theStack commented at 11:47 pm on October 24, 2023: contributor

    Hi @theStack, any chance you’d be able to review this?

    Yes, planning to (finally) review this within the next 1-2 days.

  24. DrahtBot removed the label CI failed on Oct 25, 2023
  25. DrahtBot added the label Needs rebase on Oct 25, 2023
  26. in test/functional/feature_coinstatsindex.py:231 in 8f00a52b34 outdated
    227@@ -226,7 +228,7 @@ def _test_coin_stats_index(self):
    228 
    229         self.generate(index_node, 1, sync_fun=self.no_op)
    230         res10 = index_node.gettxoutsetinfo('muhash')
    231-        assert res8['txouts'] < res10['txouts']
    232+        assert_greater_than(res10['txouts'], res8['txouts'])
    


    theStack commented at 3:53 pm on October 25, 2023:
    I noticed that here (and at some other places), assert x < y is replaced by assert_greater_than(y, x) rather than the more obvious assert_less_than(x, y). Is that change intentional or is that a left-over from an earlier version, when assert_less_than was not introduced yet?

    osagie98 commented at 6:50 pm on October 26, 2023:
    Yes, early on I kept only assert_greater_than() before I decided that assert_less_than()was needed. I can go back and fix those to make it clear.

    osagie98 commented at 5:49 pm on October 28, 2023:
    Done. Force pushed to allow for the rebase.
  27. osagie98 force-pushed on Oct 28, 2023
  28. DrahtBot removed the label Needs rebase on Oct 28, 2023
  29. DrahtBot added the label Needs rebase on Oct 29, 2023
  30. BrandonOdiwuor commented at 1:38 pm on November 15, 2023: contributor

    Concept ACK

    This PR improves functional tests (readability) by using/introducing complimentary util functions to assert ie assert_equal, assert_not_equal, assert_less_than, assert_less_than_or_equal

  31. BrandonOdiwuor commented at 11:19 am on November 16, 2023: contributor
    There are still some instances of bare assert which could be replaced by the helpers such as in rpc_psbt.py, wallet_disable.py is this intentional?
  32. test: Use test framework utils in functional tests
    Replaces bare asserts with test framework utils across both the
    functional tests and the test framework itself.
    
    Also adds the `assert_not_equal`, `assert_less_than`, and
    `assert_less_than_or_equal` util functions for greater readability.
    
        Fixes #23119.
    2103e12699
  33. osagie98 force-pushed on Dec 11, 2023
  34. osagie98 commented at 4:28 am on December 11, 2023: none

    Hi @BrandonOdiwuor,

    Sorry, I missed the notification of your messages. I missed a few asserts, so I went back to add them. I also initially chose not to change any assert x is True/False as I wasn’t sure if it would be useful, but I decided now to change those as well.

    Please take another look whenever you’re free, thank you!

  35. DrahtBot added the label CI failed on Dec 11, 2023
  36. DrahtBot removed the label Needs rebase on Dec 11, 2023
  37. in test/functional/wallet_miniscript.py:279 in 2103e12699
    275@@ -275,7 +276,8 @@ def signing_test(
    276         self.wait_until(lambda: txid in self.funder.getrawmempool())
    277         self.funder.generatetoaddress(1, self.funder.getnewaddress())
    278         utxo = self.ms_sig_wallet.listunspent(addresses=[addr])[0]
    279-        assert txid == utxo["txid"] and utxo["solvable"]
    280+        assert_equal(txid == utxo["txid"])
    


    kevkevinpal commented at 2:58 pm on January 4, 2024:
    0        assert_equal(txid, utxo["txid"])
    
  38. in test/functional/test_framework/util.py:77 in 2103e12699
    71@@ -67,6 +72,16 @@ def assert_greater_than_or_equal(thing1, thing2):
    72         raise AssertionError("%s < %s" % (str(thing1), str(thing2)))
    73 
    74 
    75+def assert_less_than(thing1, thing2):
    76+    if thing1 >= thing2:
    77+        raise AssertionError("%s .= %s" % (str(thing1), str(thing2)))
    


    stratospher commented at 3:44 pm on January 4, 2024:

    2103e12: here and for assert_less_than_or_equal too.

    0        raise AssertionError("%s >= %s" % (str(thing1), str(thing2)))
    
  39. in test/functional/test_framework/util.py:60 in 2103e12699
    56@@ -57,6 +57,11 @@ def assert_equal(thing1, thing2, *args):
    57         raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    58 
    59 
    60+def assert_not_equal(thing1, thing2, *args):
    


    stratospher commented at 3:49 pm on January 4, 2024:
    2103e12: maybe just have assert_not_equal(thing1, thing2). i couldn’t find an occurrence where we needed to assert_not_equal 3+ things. ex: assert_not_equal(2, 2, 3)

    stratospher commented at 4:04 pm on January 4, 2024:

    i think you can find more places where assert_not_equal can be used using the command @theStack mentioned here!

    example first 3 lines output:

    0$ git grep "assert ".*\!=
    1feature_fee_estimation.py:        assert fee_dat_current_content != fee_dat_initial_content
    2feature_fee_estimation.py:        assert fee_dat_current_content != fee_dat_initial_content
    3mempool_accept_wtxid.py:        assert child_one_wtxid != child_two_wtxid
    
  40. DrahtBot added the label Needs rebase on Jan 5, 2024
  41. DrahtBot commented at 11:39 am on January 5, 2024: contributor

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

  42. maflcko commented at 5:40 pm on February 22, 2024: member

    Closing for now due to inactivity. I think it is pretty clear that a change like this won’t be going in in one go.

    If someone wants to try this again, I’d recommend to try a smaller portion and see if reviewers like it. If not, then maybe it isn’t worth changing?

  43. maflcko closed this on Feb 22, 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: 2024-06-29 10:13 UTC

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