qa: assert_equals -> assert_true/assert_false #36257

pull hodlinator wants to merge 6 commits into bitcoin:master from hodlinator:2026/09/assert_true changing 95 files +648 −521
  1. hodlinator commented at 7:45 AM on September 15, 2026: contributor

    Instead of this in the functional tests:

        assert_equals([long expression pushing next arg to the right], True)
        assert_equals([other long expression pushing next arg to the right], False)
    

    we get:

        assert_true([long expression without arg on the right side..])
        assert_false([other long expression without next arg to the right.])
    

    The main point of this change is that assert_true()/assert_false() reduce cognitive tokens when scanning the code (equals to what...?). (As a consequence, assert_true()/assert_false() are also common in other test frameworks).

    assert_equals() continues to be used in cases where we don't compare to boolean literals.

    assert_true([expression]) is different from plain assert [expression] in that assert is truthy while assert_true requires boolean True. (assert can also be deactivated when executing Python code in optimized mode (see #30529 (review))).

    A smaller scale attempt at introducing assert_true() was originally included in #31874 before being dropped.

  2. DrahtBot added the label Tests on Sep 15, 2026
  3. DrahtBot commented at 7:45 AM on September 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36867 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36867.svg"></sub> (test: remove legacy wallet leftovers from wallet functional tests by w0xlt)
    • #36863 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36863.svg"></sub> (test: fix wallet tests that check the wrong wallet by w0xlt)
    • #36796 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36796.svg"></sub> (wallet, sqlite: Enable secure_delete by default by achow101)
    • #36648 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36648.svg"></sub> (descriptor, rpc, wallet: do not echo key material in error messages by fametrano)
    • #36627 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36627.svg"></sub> (tracing: run USDT tests without BPF privileges by willcl-ark)
    • #36598 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc)
    • #36540 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36540.svg"></sub> (mempool: remove time-based transaction expiry by ismaelsadeeq)
    • #36482 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36482.svg"></sub> (wallet: Only broadcast resubmitted transactions that were added to the mempool by achow101)
    • #36402 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36402.svg"></sub> (refactor: wallet_importdescriptors to separate run_test() contents into specific functions by nebula-21)
    • #36387 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36387.svg"></sub> (wallet: rpc: Deprecate encryptwallet RPC for encrypting existing wallets. by davidgumberg)
    • #36170 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36170.svg"></sub> (net: require a dedicated bind for automatic Tor by l0rinc)
    • #35920 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35920.svg"></sub> (net_processing: Ignore MSG_WITNESS_TX entries from INV messages by ajtowns)
    • #35433 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35433.svg"></sub> (wallet: deprecate replaceable argument from transaction (and psbt) creation (and modification) RPCs by rkrux)
    • #35377 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35377.svg"></sub> (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101)
    • #35355 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35355.svg"></sub> (Use atomics for determining whether trace logging is enabled by ajtowns)
    • #34872 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34872.svg"></sub> (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt)
    • #34038 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34038.svg"></sub> (logging: replace -loglevel with -trace, expose trace logging via RPC by ajtowns)
    • #33922 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33922.svg"></sub> (mining: add getMemoryLoad() and track template non-mempool memory footprint by Sjors)
    • #33112 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33112.svg"></sub> (wallet: relax external_signer flag constraints by Sjors)
    • #32857 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32857.svg"></sub> (wallet: allow skipping script paths by Sjors)
    • #31668 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31668.svg"></sub> (Added rescan option for import descriptors by saikiran57)
    • #27865 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (wallet: Track no-longer-spendable TXOs separately 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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in test/functional/test_framework/util.py:86 in 4065d7c607 outdated
      82 | @@ -83,6 +83,15 @@ def summarise_dict_differences(thing1, thing2):
      83 |              d2[k] = thing2[k]
      84 |      return d1, d2
      85 |  
      86 | +def assert_true(expression: bool):
    


    l0rinc commented at 6:47 PM on September 15, 2026:

    4065d7c qa: Add assert_true() / assert_false():

    The first commit introduces dead code; there are no users of the new methods, so I have to go through the next commits to tell if these are fully correct or not.

    But even just looking at these, I don't like that they do something other than what they claim: they're not actually asserting True, but rather truthiness, which doesn't seem to be documented here. Maybe renaming to truthy and falsy would be more predictable.

    I would also like to see tests added to explain their behavior, since otherwise the actual test cases are the test for the new helper method, and both could be incorrect and we wouldn't know. Just a few simple ones with primitives would suffice.


    hodlinator commented at 8:09 PM on September 15, 2026:

    re #36257 (review):

    Thanks for catching the accidental degradation in correctness! I originally used != True/!= False but the ruff linter recommended the truthy/falsy variants. is not seems to fit the bill without angering ruff.

    You can patch the test_runner with this and run it to verify the latest push is more correct:

    <details><summary>Diff</summary>

    --- a/test/functional/test_runner.py
    +++ b/test/functional/test_runner.py
    @@ -30,6 +30,8 @@ import tempfile
     import re
     import logging
     from test_framework.util import (
    +    assert_false,
    +    assert_true,
         Binaries,
         export_env_build_path,
         get_binary_paths,
    @@ -967,4 +969,52 @@ class RPCCoverage():
     
     
     if __name__ == '__main__':
    -    main()
    +    assert_false(False)
    +    assert_true(True)
    +
    +    try:
    +        assert_false(True)
    +    except AssertionError:
    +        pass
    +    else:
    +        raise AssertionError("assert_false(True) should raise")
    +
    +    try:
    +        assert_true(False)
    +    except AssertionError:
    +        pass
    +    else:
    +        raise AssertionError("assert_true(False) should raise")
    +
    +
    +    # Test falsyness
    +    try:
    +        assert_false(list())
    +    except AssertionError:
    +        pass
    +    else:
    +        raise AssertionError("assert_false is falsy")
    +
    +    try:
    +        assert_false([1, 2])
    +    except AssertionError:
    +        pass
    +    else:
    +        raise AssertionError("assert_false is broken")
    +
    +    # Test truthyness
    +    try:
    +        assert_true([1, 2])
    +    except AssertionError:
    +        pass
    +    else:
    +        raise AssertionError("assert_true is truthy")
    +
    +    try:
    +        assert_true(list())
    +    except AssertionError:
    +        pass
    +    else:
    +        raise AssertionError("assert_true is broken")
    +
    +    print("assert_false/assert_true have expected behavior!")
    

    </details>

    None of the other util methods have these meta-tests AFAIK. If you insist do you have any suggestion for where to start adding them?

    Regarding adding them as dead code, it's a natural effect of having to add them before the scripted diff. (Only with the exception of one wallet test in "qa: Fix weird case of 3-arg assert_equal() ahead of scripted diff").

  5. l0rinc commented at 6:54 PM on September 15, 2026: contributor

    I don't mind the change, the only reason I see to use explicit True and False is to flip these after a characterization test - but they could also flip the method name.

    Based on https://mirror.b10c.me/bitcoin-bitcoin/34773#discussion_r3009767675 and https://mirror.b10c.me/bitcoin-bitcoin/34773#discussion_r3009771746, @maflcko might be interested.

  6. hodlinator force-pushed on Sep 15, 2026
  7. hodlinator commented at 8:20 PM on September 15, 2026: contributor

    I don't mind the change, the only reason I see to use explicit True and False is to flip these after a characterization test - but they could also flip the method name.

    It was reviewing your characterization test flipping which made me flip and implement this. :)

  8. maflcko commented at 9:19 AM on September 16, 2026: member

    assert_true([expression]) is different from plain assert [expression] in that the latter can be deactivated when executing Python code in optimized mode (see #30529 (comment)).

    This isn't wrong, but seems to be missing the point: The reason why assert_equal with True or False is used is not because assert may dropped (in theory, no one is doing this in practise?), but rather that the assert only checks truthy/falsy states, not type-safe equality.

    So the only real remaining motivation for this is to reduce code bloat. No objection, but overall I am ~0 on this.

  9. hodlinator commented at 10:06 AM on September 16, 2026: contributor

    Thanks for having a look @maflcko. Re-orged the PR desc to add the truthyness nuance of assert and also to make the cognitive part more prominent as the motivation.

  10. DrahtBot added the label Needs rebase on Sep 26, 2026
  11. hodlinator force-pushed on Oct 1, 2026
  12. DrahtBot removed the label Needs rebase on Oct 1, 2026
  13. DrahtBot added the label Needs rebase on Nov 2, 2026
  14. hodlinator force-pushed on Nov 3, 2026
  15. maflcko commented at 8:48 AM on November 3, 2026: member

    Can you leave this in draft please, while there are reviewed conflicts? Even with review, this isn't going to be merged while it conflicts with real bugfixes. So to avoid wasted review, this should stay in draft while conflicting with reviewed stuff.

  16. DrahtBot removed the label Needs rebase on Nov 3, 2026
  17. DrahtBot added the label Needs rebase on Nov 5, 2026
  18. hodlinator force-pushed on Nov 9, 2026
  19. DrahtBot removed the label Needs rebase on Nov 9, 2026
  20. hodlinator commented at 3:51 PM on November 9, 2026: contributor

    Can you leave this in draft please, while there are reviewed conflicts? Even with review, this isn't going to be merged while it conflicts with real bugfixes. So to avoid wasted review, this should stay in draft while conflicting with reviewed stuff.

    As stated out of band, my prediction is that if the project continues to be healthy, there will continue to be conflicts until this PR is resolved. If a sufficient number of (stale) ACKs are reached, range-diffing to get 2 fresh ACKs on the same push seems doable, at least with the current approach. Last few rebases I've needed to modify some conflicting import changes and re-run the scripted diff. Running the linters to catch mismatching imports and incorrectly applied scripted diff helps sanity-check new pushes.

  21. maflcko commented at 9:51 AM on November 16, 2026: member

    Sure, if stuff is free, we could do all of it. However, #34395 seems more useful than this and it didn't make it either.

  22. hodlinator force-pushed on Nov 16, 2026
  23. scripted-diff: Guard against assert_true|assert_false already existing
    -BEGIN VERIFY SCRIPT-
    git grep -E "\b(assert_true|assert_false)\b" -- test/functional && echo "Error: Target names already exist" >&2 && exit 1 || exit 0
    -END VERIFY SCRIPT-
    f47986b246
  24. qa: Add assert_true() / assert_false() 645fab9380
  25. qa: Fix weird case of 3-arg assert_equal() ahead of scripted diff
    Before 2ef6679c2ca87bbe305f45ff3df3d19ec3f60595 introduced finalized2 we had:
    assert_equal(finalized["complete"], True)
    ...so this is changing things back towards that.
    fe1167ff7e
  26. qa: Fixup imports ahead of scripted diff 965cd5fbc2
  27. scripted-diff: Replace assert_equals([..., ]True/False[, ...]) with assert_true/assert_false
    -BEGIN VERIFY SCRIPT-
    sed -i -E "s/assert_equal\((.*)\, (True|False)\)( *(#.*))?$/assert_\L\2(\E\1)\3/g" $( git grep -lE "assert_equal\(.*, (True|False)\)"  -- test/functional/ )
    sed -i -E "s/assert_equal\((True|False), (.*)$/assert_\L\1\E\(\2/g" $( git grep -lE "assert_equal\((True|False)"  -- test/functional/ )
    -END VERIFY SCRIPT-
    0f6db29fc1
  28. qa: Remove no longer used assert_equals imports cada9cfdad
  29. hodlinator force-pushed on Nov 16, 2026
  30. DrahtBot added the label CI failed on Nov 16, 2026
  31. DrahtBot commented at 10:30 AM on November 16, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/43847803530/job/133232294579</sub> <sub>LLM reason (✨ experimental): CI failed the scripted-diff lint: its guard found existing assert_true/assert_false calls in test/functional.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  32. hodlinator commented at 10:32 AM on November 16, 2026: contributor

    Sure, if stuff is free, we could do all of it. However, #34395 seems more useful than this and it didn't make it either.

    Agree both are very low-priority, but it seems quite subjective which one is more useful (abbreviating the names of functions vs removing begging-the-question tokens (equals ...to arbitrarily long expression ... False/True)).

    Liked how that PR added a guard in the scripted diff against the new names, added a commit here doing the same before introducing the new functions.

  33. DrahtBot removed the label CI failed on Nov 16, 2026

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-11-18 16:51 UTC

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