test: interface_http follow-ups #35086

pull pinheadmz wants to merge 1 commits into bitcoin:master from pinheadmz:interface-http-followups changing 1 files +66 −53
  1. pinheadmz commented at 8:05 PM on April 15, 2026: member

    This addresses post-merge and slightly-pre-merge comments from #34772 and closes #35082

    • Only one node needed for test
    • Use ascii encoding instead of utf-8
    • Make tests independent of each other
    • Expect HTTP error code 413 for too-large request
    • Clarify python client race condition in comment
  2. DrahtBot added the label Tests on Apr 15, 2026
  3. DrahtBot commented at 8:05 PM on April 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, hodlinator
    Stale ACK fjahr

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. pinheadmz force-pushed on Apr 15, 2026
  5. DrahtBot added the label CI failed on Apr 15, 2026
  6. pinheadmz force-pushed on Apr 15, 2026
  7. DrahtBot removed the label CI failed on Apr 15, 2026
  8. in test/functional/interface_http.py:334 in 7d81713d76
     330 | @@ -325,41 +331,45 @@ def check_idle_timeout(self):
     331 |          # the server. Negating this setting will force the AuthServiceProxy
     332 |          # for this node to create a fresh new HTTP connection for every command
     333 |          # called for the remainder of this test.
     334 | -        self.nodes[2].reuse_http_connections = False
     335 | +        self.nodes[0].reuse_http_connections = False
    


    hodlinator commented at 6:56 AM on April 16, 2026:

    nit: How about doing this only once at the top of run_test() with a variation of the comment above to ensure less state is carried between all test functions? https://github.com/hodlinator/bitcoin/commit/27134f49a833fa77a74dbc2c4ecfe12964af0305 (I guess it doesn't really make a difference until the last 2 tests which restart the node).


    pinheadmz commented at 2:23 PM on April 17, 2026:

    sure will hoist up the setting

  9. in test/functional/interface_http.py:71 in 7d81713d76
      67 | @@ -68,7 +68,7 @@ def post_raw(self, path, data):
      68 |          req += f'Authorization: Basic {str_to_b64str(self.authpair)}\r\n'
      69 |          req += f'Content-Length: {len(data)}\r\n\r\n'
      70 |          req += data
      71 | -        self.conn.sock.sendall(req.encode("utf-8"))
      72 | +        self.conn.sock.sendall(req.encode("ascii"))
    


    hodlinator commented at 7:37 AM on April 16, 2026:

    nit: I prefer keeping it to UTF-8 - something closer to suggestion commit: https://github.com/hodlinator/bitcoin/commit/758d5da7377ff5a43e8ab98b4c52637279ee4b59

        def post_raw(self, path, data):
            if isinstance(data, str):
                data = data.encode("utf-8")
            assert isinstance(data, bytes), f"Expected data as bytes but got: {type(data)}"
            req = (f"POST {path} HTTP/1.1\r\n" +
                   f"Authorization: Basic {str_to_b64str(self.authpair)}\r\n" +
                   f"Content-Length: {len(data)}\r\n\r\n").encode("utf-8")
            req += data
            self.conn.sock.sendall(req)
    

    With ASCII it's easy to trigger errors like:

    2026-04-16T07:48:52.476912Z TestFramework (INFO): Checking excessive request size
    2026-04-16T07:48:52.881198Z TestFramework (ERROR): Unexpected exception:
    Traceback (most recent call last):
      File "/home/hodlinator/bc/2/test/functional/test_framework/test_framework.py", line 143, in main
        self.run_test()
        ~~~~~~~~~~~~~^^
      File "/home/hodlinator/bc/2/./build/test/functional/interface_http.py", line 107, in run_test
        self.check_excessive_request_size()
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
      File "/home/hodlinator/bc/2/./build/test/functional/interface_http.py", line 213, in check_excessive_request_size
        conn.post_raw('/', f'{{"jsonrpc": "2.0", "id": "0", "method": "submitblock", "params": ["{"₿" * bytes_above_limit}"]}}')
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/hodlinator/bc/2/./build/test/functional/interface_http.py", line 71, in post_raw
        self.conn.sock.sendall(req.encode("ascii"))
                               ~~~~~~~~~~^^^^^^^^^
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 235-33554597: ordinal not in range(128)
    

    hodlinator commented at 8:03 PM on April 16, 2026:

    re @maflcko at #34772 (review):

    Sure, looks good. Just seems odd to use uf8 when it is not needed in the test. For the data it should be fine, maybe a test can echo an emoji? For the headers I am not sure, I think they must be ascii?

    Hm... from the specs I could find it seems like everything before the body itself should be visible-ish ASCII. So I guess using/requiring ASCII-encoding for all but the body is a safeguard on the test-side unless we want to test how the server reacts to this form of standards-breaking.

    In light of this I think only data should be encoded as UTF-8.


    pinheadmz commented at 2:34 PM on April 17, 2026:

    Ok will encode the body data as utf8 and keep everything old-school, like HTTP ;-)

  10. in test/functional/interface_http.py:214 in 7d81713d76
     211 | +        conn = BitcoinHTTPConnection(self.nodes[0])
     212 |          try:
     213 |              # Excessive body size is invalid
     214 | -            response5 = conn.post('/', f'{{"jsonrpc": "2.0", "id": "0", "method": "submitblock", "params": ["{"0" * bytes_above_limit}"]}}')
     215 | +            conn.post_raw('/', f'{{"jsonrpc": "2.0", "id": "0", "method": "submitblock", "params": ["{"0" * bytes_above_limit}"]}}')
     216 | +            self.log.debug("Client finished sending request before connection was terminated")
    


    hodlinator commented at 7:41 AM on April 16, 2026:

    nit: I think it might be good to use info to log the racy behavior.

                self.log.info("Client finished sending request before connection was terminated")
    

    Full suggestion: https://github.com/hodlinator/bitcoin/commit/c592b6df07d39b6b77b9ca9190f3618b1d84f287


    pinheadmz commented at 2:37 PM on April 17, 2026:

    Cool, promoting these messages to info level

  11. in test/functional/interface_http.py:97 in 7d81713d76 outdated
      93 | @@ -94,7 +94,7 @@ def expect_timeout(self, seconds):
      94 |  
      95 |  class HTTPBasicsTest (BitcoinTestFramework):
      96 |      def set_test_params(self):
      97 | -        self.num_nodes = 3
      98 | +        self.num_nodes = 1
    


    hodlinator commented at 7:43 AM on April 16, 2026:

    nanonit: Could introduce self.node = self.nodes[0] to decrease tokens: https://github.com/hodlinator/bitcoin/commit/758d5da7377ff5a43e8ab98b4c52637279ee4b59


    pinheadmz commented at 2:38 PM on April 17, 2026:

    sure, using self.node everywhere

  12. hodlinator commented at 7:53 AM on April 16, 2026: contributor

    ACK f0e63edcb186efed0cd88b369360ba332e0e7ca7

    I'd really prefer keeping it to UTF-8, feel less strongly about the other nits.

    Full suggestion branch: https://github.com/bitcoin/bitcoin/compare/master...hodlinator:bitcoin:pr/35086_suggestions

  13. hodlinator approved
  14. hodlinator commented at 7:56 AM on April 16, 2026: contributor

    re-ACK 7d81713d76dd5cffb74636f506f28d063fa4253f

    See #35086#pullrequestreview-4118857237

  15. fanquake requested review from fjahr on Apr 16, 2026
  16. fanquake added this to the milestone 32.0 on Apr 16, 2026
  17. fjahr commented at 12:40 PM on April 16, 2026: contributor

    Code review ACK 7d81713d76dd5cffb74636f506f28d063fa4253f

    Happy to re-review if you decide to address @hodlinator 's nits.

  18. test: interface_http follow-ups
    - Only one node needed for test
    - Use ascii encoding instead of utf-8
    - Make tests independent of each other
    - Expect HTTP error code 413 for too-large request
    - Clarify python client race condition in comment
    f49a2afd94
  19. pinheadmz force-pushed on Apr 17, 2026
  20. pinheadmz commented at 2:51 PM on April 17, 2026: member

    push to f49a2afd94

    • Address feedback from @hodlinator. Mostly nits, kept ascii encoding for http headers but allow utf8 for message body
  21. maflcko commented at 3:27 PM on April 17, 2026: member

    lgtm ACK f49a2afd94c3b8a5c06d7b77155d0596300bdc2e

  22. DrahtBot requested review from hodlinator on Apr 17, 2026
  23. hodlinator approved
  24. hodlinator commented at 5:33 PM on April 17, 2026: contributor

    re-ACK f49a2afd94c3b8a5c06d7b77155d0596300bdc2e

    Thanks for taking my suggestions!

  25. fanquake merged this on Apr 17, 2026
  26. fanquake closed this on Apr 17, 2026

  27. fjahr commented at 9:05 AM on April 18, 2026: contributor

    post-merge ACK f49a2afd94c3b8a5c06d7b77155d0596300bdc2e


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-04-21 09:12 UTC

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