Skip to content

Commit e38f09b

Browse files
committed
Merge bitcoin/bitcoin#31955: test: Fix authproxy named args debug logging
fac1dd9 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 fac1dd9 rkrux: tACK fac1dd9 musaHaruna: Tested ACK [fac1dd9](bitcoin/bitcoin@fac1dd9) ryanofsky: Code review ACK fac1dd9. Thanks for logging fix. This change should have been included in #19762 Tree-SHA512: ff63fbc2564b2c7589e9294baacf4c7a79f10d593776813392510702ca726e3893a29db3ba261f3aee1789a59bb215d7cb10fc85ca1a02632631d3722ddcdfc5
2 parents 1d0a1a6 + fac1dd9 commit e38f09b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/functional/test_framework/authproxy.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@ def _request(self, method, path, postdata):
105105
self.__conn.request(method, path, postdata, headers)
106106
return self._get_response()
107107

108+
def _json_dumps(self, obj):
109+
return json.dumps(obj, default=serialization_fallback, ensure_ascii=self.ensure_ascii)
110+
108111
def get_request(self, *args, **argsn):
109112
AuthServiceProxy.__id_count += 1
110113

111-
log.debug("-{}-> {} {}".format(
114+
log.debug("-{}-> {} {} {}".format(
112115
AuthServiceProxy.__id_count,
113116
self._service_name,
114-
json.dumps(args or argsn, default=serialization_fallback, ensure_ascii=self.ensure_ascii),
117+
self._json_dumps(args),
118+
self._json_dumps(argsn),
115119
))
120+
116121
if args and argsn:
117122
params = dict(args=args, **argsn)
118123
else:
@@ -123,7 +128,7 @@ def get_request(self, *args, **argsn):
123128
'id': AuthServiceProxy.__id_count}
124129

125130
def __call__(self, *args, **argsn):
126-
postdata = json.dumps(self.get_request(*args, **argsn), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
131+
postdata = self._json_dumps(self.get_request(*args, **argsn))
127132
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
128133
# For backwards compatibility tests, accept JSON RPC 1.1 responses
129134
if 'jsonrpc' not in response:
@@ -150,7 +155,7 @@ def __call__(self, *args, **argsn):
150155
return response['result']
151156

152157
def batch(self, rpc_call_list):
153-
postdata = json.dumps(list(rpc_call_list), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
158+
postdata = self._json_dumps(list(rpc_call_list))
154159
log.debug("--> " + postdata)
155160
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
156161
if status != HTTPStatus.OK:
@@ -197,7 +202,7 @@ def _get_response(self):
197202
response = json.loads(responsedata, parse_float=decimal.Decimal)
198203
elapsed = time.time() - req_start_time
199204
if "error" in response and response["error"] is None:
200-
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
205+
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, self._json_dumps(response["result"])))
201206
else:
202207
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
203208
return response, http_response.status

0 commit comments

Comments
 (0)