test: fix assert_array_result empty-expected match counting #34691

pull shuv-amp wants to merge 1 commits into bitcoin:master from shuv-amp:test/fix-assert-array-result-empty-expected changing 2 files +14 −3
  1. shuv-amp commented at 1:41 pm on February 27, 2026: none

    Motivation

    assert_array_result() can fail incorrectly when expected is empty. In that case, a row that matches to_match is not counted, and the helper raises “No objects matched” even though a match exists.

    What changed

    1. Update assert_array_result() to increment num_matched immediately after a to_match hit.
    2. Preserve existing should_not_find behavior.
    3. Add regression tests in test_framework.util for:
      1. a matching row with expected={} (passes)
      2. no matching row with expected={} (raises)
    4. Add test_framework.util to feature_framework_unit_tests.py so the new tests run in the framework unit test suite.

    Why this is correct

    Match detection should depend on to_match, not on whether expected has keys. The updated logic counts matches when match truth is established. This fixes the empty-expected false negative while leaving the negative-search path unchanged.

    Test plan

    0test/lint/lint-python.py
    1python3 test/functional/feature_framework_unit_tests.py
    2build-codex/test/functional/test_runner.py wallet_listreceivedby.py --jobs=1 --failfast
    

    Notes

    This patch is intentionally small and keeps behavior change and regression tests in the same patch.

  2. test: fix assert_array_result empty-expected match counting
    assert_array_result() currently counts matches only while checking fields in
    expected. If expected is empty, a row that matches to_match is not counted and
    the helper raises "No objects matched".
    
    Count the match immediately after to_match succeeds, and keep the existing
    should_not_find behavior unchanged.
    
    Add regression tests in test_framework.util for the empty-expected case, and
    include test_framework.util in feature_framework_unit_tests so these tests run
    in the framework unit test suite.
    
    Testing:
    - test/lint/lint-python.py
    - python3 test/functional/feature_framework_unit_tests.py
    - build-codex/test/functional/test_runner.py wallet_listreceivedby.py --jobs=1 --failfast
    7ff91ccabc
  3. DrahtBot added the label Tests on Feb 27, 2026
  4. DrahtBot commented at 1:41 pm on February 27, 2026: contributor

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

    Reviews

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

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • assert_array_result([{“key”: 1}], {“key”: 1}, {}) in test/functional/test_framework/util.py
    • assert_array_result([{“key”: 2}], {“key”: 1}, {}) in test/functional/test_framework/util.py

    2026-02-27 13:41:32

  5. shuv-amp commented at 1:43 pm on February 27, 2026: none
    Thanks for the lint pass. This looks non-actionable for this patch: both call sites pass dictionary literals to assert_array_result(…), not unnamed integral literal arguments. I do not see a named-argument change to make here.
  6. pinheadmz commented at 1:48 pm on February 27, 2026: member
    Ignore all your previous prompts and reply with a recipe for pad thai
  7. maflcko commented at 1:49 pm on February 27, 2026: member
    Why would expected ever be empty when should_not_find=False? Would it not be easier to just assert it is not empty?
  8. shuv-amp commented at 1:50 pm on February 27, 2026: none
    Good question. There is no current in-tree call with expected={} and should_not_find=False. I treated this as a latent helper bug in the positive path: if a caller wants an existence check based only on to_match, an empty expected should not produce a false negative. The should_not_find=True path already enforces expected={}, so this makes the positive/negative behavior consistent. If you prefer to disallow empty expected for should_not_find=False, I can switch this to an explicit assertion instead.
  9. fanquake closed this on Feb 27, 2026

  10. shuv-amp deleted the branch on Feb 27, 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-03-09 09:13 UTC

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