test: Handle empty string returned by CLI as None in RPC tests #32286

pull BrandonOdiwuor wants to merge 1 commits into bitcoin:master from BrandonOdiwuor:test-fix-cli-jsonnone changing 1 files +2 −0
  1. BrandonOdiwuor commented at 11:26 AM on April 16, 2025: contributor

    Partially Fixes #32264

    Some tests are failing when bitcoin-cli returns an empty string. This change treats an empty response as None. See #32264 (comment)

    This fixes the error for:

    • feature_bip68_sequence.py
    • feature_nulldummy.py
    • feature_signet.py
    • mining_mainnet.py
    • rpc_scanblocks.py
    • rpc_scantxoutset.py
    • wallet_descriptor.py --descriptors
  2. test: Handle empty string returned by CLI as None in RPC tests a4041c77f0
  3. DrahtBot commented at 11:26 AM on April 16, 2025: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32286.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, pablomartin4btc, mzumsande, achow101

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

  4. DrahtBot added the label Tests on Apr 16, 2025
  5. maflcko commented at 11:46 AM on April 16, 2025: member

    lgtm ACK a4041c77f0e20d004524868e70ff12508832c9eb

    I haven't tested this, but it makes sense to recover an empty string as json-none for legacy RPCs. Obviously, this could lead to errors when an empty string is returned for real, but this should never happen: I checked that all unwrapped json-strings returned are never empty (txid, block hash, hex encodings, addresses, ...). I haven't checked getblocktemplate rejection strings, but this seems fine either way, given that it is only the test suite.

    For new RPCs, they are recommended to return json dicts, always. So this won't be an issue going forward.

  6. in test/functional/test_framework/test_node.py:926 in a4041c77f0
     918 | @@ -919,6 +919,8 @@ def send_cli(self, clicommand=None, *args, **kwargs):
     919 |              # Ignore cli_stdout, raise with cli_stderr
     920 |              raise subprocess.CalledProcessError(returncode, p_args, output=cli_stderr)
     921 |          try:
     922 | +            if not cli_stdout.strip():
     923 | +                return None
     924 |              return json.loads(cli_stdout, parse_float=decimal.Decimal)
     925 |          except (json.JSONDecodeError, decimal.InvalidOperation):
     926 |              return cli_stdout.rstrip("\n")
    


    pablomartin4btc commented at 4:07 PM on April 16, 2025:

    nit: checking for cli_stdout shouldn't be outside the try? also cos it shouldn't fail and if it does the except is also accessing it...

                raise subprocess.CalledProcessError(returncode, p_args, output=cli_stderr)
            if not cli_stdout.strip():
                return None
            try:
                return json.loads(cli_stdout, parse_float=decimal.Decimal)
            except (json.JSONDecodeError, decimal.InvalidOperation):
                return cli_stdout.rstrip("\n")
    

    BrandonOdiwuor commented at 6:42 PM on April 16, 2025:

    I think this was more to keep the logic in one place

  7. pablomartin4btc commented at 4:07 PM on April 16, 2025: member

    ACK a4041c77f0e20d004524868e70ff12508832c9eb

  8. mzumsande commented at 8:51 PM on April 16, 2025: contributor

    ACK a4041c77f0e20d004524868e70ff12508832c9eb

  9. achow101 commented at 11:07 PM on April 16, 2025: member

    ACK a4041c77f0e20d004524868e70ff12508832c9eb

  10. achow101 merged this on Apr 16, 2025
  11. achow101 closed this on Apr 16, 2025

  12. fanquake commented at 11:49 AM on April 17, 2025: member

    Backported in #32292.

  13. fanquake referenced this in commit 8b25ce59be on Apr 17, 2025
  14. sedited referenced this in commit a9c46ce3c3 on Apr 24, 2025
  15. fanquake referenced this in commit 85f3e1de68 on May 6, 2025
  16. fanquake referenced this in commit a124b91339 on May 13, 2025
  17. fanquake referenced this in commit 992c7cad46 on May 13, 2025
  18. fanquake referenced this in commit 589b56192f on May 22, 2025
  19. stickies-v referenced this in commit 772a33e052 on May 23, 2025
  20. fanquake referenced this in commit 39b935a8d4 on Jun 9, 2025
  21. yuvicc referenced this in commit 069643f094 on Jul 6, 2025
  22. bug-castercv502 referenced this in commit 5b0af4b944 on Sep 28, 2025
  23. morozow referenced this in commit f7a19fccb4 on May 8, 2026
  24. morozow referenced this in commit 720cc3ad61 on May 8, 2026
  25. morozow referenced this in commit edc6b10728 on May 8, 2026
  26. morozow referenced this in commit 131bf7e5ca on May 8, 2026
  27. morozow referenced this in commit c0a637fe80 on May 8, 2026
  28. Kino1994 referenced this in commit 2097ce7c14 on Jun 28, 2026
  29. BigcoinBGC referenced this in commit 6bfef46b89 on Jun 30, 2026
  30. bitcoin locked this on Jul 30, 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-08-05 07:51 UTC

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