Merge bitcoin/bitcoin#31955: test: Fix authproxy named args debug logging

fac1dd9dff test: Fix authproxy named args debug logging (MarcoFalke)

Pull request description:

  In Python the meaning of `args or argsn` is that `argsn` is fully ignored when `args` is a list with at least one element. However, the RPC server accepts mixed positional and named args in the same RPC.

  Fix the debug log by always printing both. Also, add a new `_json_dumps` helper to avoid bloated code.

  Can be tested via `--tracerpc` on a call that uses named args mixed with positional args.

ACKs for top commit:
  i-am-yuvi:
    Tested ACK fac1dd9dff
  rkrux:
    tACK fac1dd9dff
  musaHaruna:
    Tested ACK [fac1dd9](fac1dd9dff)
  ryanofsky:
    Code review ACK fac1dd9dff. Thanks for logging fix. This change should have been included in #19762

Tree-SHA512: ff63fbc2564b2c7589e9294baacf4c7a79f10d593776813392510702ca726e3893a29db3ba261f3aee1789a59bb215d7cb10fc85ca1a02632631d3722ddcdfc5
This commit is contained in:
merge-script 2025-03-12 09:43:36 +08:00
commit e38f09b776
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -105,14 +105,19 @@ class AuthServiceProxy():
self.__conn.request(method, path, postdata, headers)
return self._get_response()
def _json_dumps(self, obj):
return json.dumps(obj, default=serialization_fallback, ensure_ascii=self.ensure_ascii)
def get_request(self, *args, **argsn):
AuthServiceProxy.__id_count += 1
log.debug("-{}-> {} {}".format(
log.debug("-{}-> {} {} {}".format(
AuthServiceProxy.__id_count,
self._service_name,
json.dumps(args or argsn, default=serialization_fallback, ensure_ascii=self.ensure_ascii),
self._json_dumps(args),
self._json_dumps(argsn),
))
if args and argsn:
params = dict(args=args, **argsn)
else:
@ -123,7 +128,7 @@ class AuthServiceProxy():
'id': AuthServiceProxy.__id_count}
def __call__(self, *args, **argsn):
postdata = json.dumps(self.get_request(*args, **argsn), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
postdata = self._json_dumps(self.get_request(*args, **argsn))
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
# For backwards compatibility tests, accept JSON RPC 1.1 responses
if 'jsonrpc' not in response:
@ -150,7 +155,7 @@ class AuthServiceProxy():
return response['result']
def batch(self, rpc_call_list):
postdata = json.dumps(list(rpc_call_list), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
postdata = self._json_dumps(list(rpc_call_list))
log.debug("--> " + postdata)
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
if status != HTTPStatus.OK:
@ -197,7 +202,7 @@ class AuthServiceProxy():
response = json.loads(responsedata, parse_float=decimal.Decimal)
elapsed = time.time() - req_start_time
if "error" in response and response["error"] is None:
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, self._json_dumps(response["result"])))
else:
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
return response, http_response.status