mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
qa: assert_equal -> assert_true/assert_false #36257
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36257
Loading…
Reference in a new issue
No description provided.
Delete branch "2026/09/assert_true"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Instead of this in the functional tests:
we get:
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_equal()continues to be used in cases where we don't compare to boolean literals.assert_true([expression])is different from plainassert [expression]in thatassertis truthy whileassert_truerequires booleanTrue. (assertcan also be deactivated when executing Python code in optimized mode (see https://github.com/bitcoin/bitcoin/pull/30529#discussion_r1893029530)).A smaller scale attempt at introducing
assert_true()was originally included in #31874 before being dropped.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
Reviewers, this pull request conflicts with the following ones:
wallet_migration.pyby l0rinc)wallet_importdescriptorsto separaterun_test()contents into specific functions by nebula-21)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.
I don't mind the change, the only reason I see to use explicit
TrueandFalseis 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.
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 totruthyandfalsywould 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.
It was reviewing your characterization test flipping which made me flip and implement this. :)
re https://github.com/bitcoin/bitcoin/pull/36257#discussion_r4019082601:
Thanks for catching the accidental degradation in correctness! I originally used
!= True/!= Falsebut the ruff linter recommended the truthy/falsy variants.is notseems 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:
Diff
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").
This isn't wrong, but seems to be missing the point: The reason why assert_equal with
TrueorFalseis used is not becauseassertmay 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.
Thanks for having a look @maflcko. Re-orged the PR desc to add the truthyness nuance of
assertand also to make the cognitive part more prominent as the motivation.🐙 This pull request conflicts with the target branch and needs rebase.
Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🔵 Suggestion ·
assert_trueandassert_falseomit the checked value from failuresThe new functional-test helpers omit the actual value from assertion failures, making unexpected non-boolean results harder to diagnose than with the replaced
assert_equalcalls.Location:
test/functional/test_framework/util.py:91(head).🔵 Suggestion · Import preparation mixes required additions with unrelated formatting
The hand-edited import-preparation commit also moves and reindents existing imports, adding manual comparison work before the scripted conversion.
Location: test/functional/rpc_blockchain.py:58 (commit).
Review coverage was incomplete.
Reviewed:
f1196fb0386b· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
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.
🐙 This pull request conflicts with the target branch and needs rebase.
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.
Sure, if stuff is free, we could do all of it. However, https://github.com/bitcoin/bitcoin/pull/34395 seems more useful than this and it didn't make it either.
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/43847803530/job/133232294579LLM reason (✨ experimental): CI failed the scripted-diff lint: its guard found existing
assert_true/assert_falsecalls intest/functional.Hints
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.
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.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
True
@maflcko I checked your approach in #35139, where you only have
ASSERT()rather thanASSERT_TRUE()/ASSERT_FALSE(). One could introduce just one custom non-truthyassert_(arg)function for Python too. The problem with that is I couldn't find a type safe way of negating a boolean aside from also introducing a customnot_(arg)function.I don't think https://github.com/bitcoin/bitcoin/pull/35139 is going to make it any time soon, it is marked as DRAFT , mostly meant as a tracking issue for the bugs, but maybe I should close it. Also, for reference it has
#define ASSERT_EQ(l, r) detail::check_op(l, r, #l " == " #r, "!=", std::equal_to<>{}), not only a single one.Personally, I sometimes use
assert_equal(True, long...expr)...Yes, I'm all for keeping
assert_equalfor comparisons against non-literals.One could create a scripted diff for switching existing cases of
assert_equal(long...expr, True)toassert_equal(True, long...expr)(not that you have advocated for it). But the current PR approach seems like a better path forward.