Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Use test framework utils in functional tests #28528

Closed
wants to merge 1 commit into from

Conversation

osagie98
Copy link

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 25, 2023

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.

@osagie98 osagie98 marked this pull request as ready for review September 25, 2023 05:16
@osagie98
Copy link
Author

Though the change is simple, it touches a ton of files. I can break it into multiple PRs if that makes sense.

@maflcko
Copy link
Member

maflcko commented Oct 5, 2023

@theStack Added you as reviewer/mentor, because the issue was opened by you

@theStack
Copy link
Contributor

theStack commented Oct 5, 2023

@osagie98: Can you squash the commits and rebase on master? Happy to review.

@osagie98
Copy link
Author

osagie98 commented Oct 6, 2023

@theStack done (I hope, still getting used to the GitHub workflow). Let me know if you'll need anything else

@theStack
Copy link
Contributor

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

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

@@ -226,7 +228,7 @@ def _test_coin_stats_index(self):

self.generate(index_node, 1, sync_fun=self.no_op)
res10 = index_node.gettxoutsetinfo('muhash')
assert res8['txouts'] < res10['txouts']
assert_greater_than(res10['txouts'], res8['txouts'])
Copy link
Contributor

@theStack theStack Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Author

@osagie98 osagie98 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Force pushed to allow for the rebase.

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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 bitcoin#23119.
@osagie98
Copy link
Author

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!

@@ -275,7 +276,8 @@ def signing_test(
self.wait_until(lambda: txid in self.funder.getrawmempool())
self.funder.generatetoaddress(1, self.funder.getnewaddress())
utxo = self.ms_sig_wallet.listunspent(addresses=[addr])[0]
assert txid == utxo["txid"] and utxo["solvable"]
assert_equal(txid == utxo["txid"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_equal(txid == utxo["txid"])
assert_equal(txid, utxo["txid"])

@@ -67,6 +72,16 @@ def assert_greater_than_or_equal(thing1, thing2):
raise AssertionError("%s < %s" % (str(thing1), str(thing2)))


def assert_less_than(thing1, thing2):
if thing1 >= thing2:
raise AssertionError("%s .= %s" % (str(thing1), str(thing2)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2103e12: here and for assert_less_than_or_equal too.

Suggested change
raise AssertionError("%s .= %s" % (str(thing1), str(thing2)))
raise AssertionError("%s >= %s" % (str(thing1), str(thing2)))

@@ -57,6 +57,11 @@ def assert_equal(thing1, thing2, *args):
raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))


def assert_not_equal(thing1, thing2, *args):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

$ git grep "assert ".*\!=
feature_fee_estimation.py:        assert fee_dat_current_content != fee_dat_initial_content
feature_fee_estimation.py:        assert fee_dat_current_content != fee_dat_initial_content
mempool_accept_wtxid.py:        assert child_one_wtxid != child_two_wtxid

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 5, 2024

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

@maflcko
Copy link
Member

maflcko commented Feb 22, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: replace bare asserts with assertion helpers (assert_equal() etc.)
7 participants