Skip to content

Commit

Permalink
test: use json-rpc 2.0 in all functional tests by default
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Jun 7, 2024
1 parent 391843b commit b225295
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions test/functional/test_framework/authproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- HTTP connections persist for the life of the AuthServiceProxy object
(if server supports HTTP/1.1)
- sends protocol 'version', per JSON-RPC 1.1
- sends "jsonrpc":"2.0", per JSON-RPC 2.0
- sends proper, incrementing 'id'
- sends Basic HTTP authentication headers
- parses all JSON numbers that look like floats as Decimal
Expand Down Expand Up @@ -117,23 +117,36 @@ def get_request(self, *args, **argsn):
params = dict(args=args, **argsn)
else:
params = args or argsn
return {'version': '1.1',
return {'jsonrpc': '2.0',
'method': self._service_name,
'params': params,
'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)
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
if response['error'] is not None:
raise JSONRPCException(response['error'], status)
elif 'result' not in response:
raise JSONRPCException({
'code': -343, 'message': 'missing JSON-RPC result'}, status)
elif status != HTTPStatus.OK:
raise JSONRPCException({
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
# For backwards compatibility tests, accept JSON RPC 1.1 responses
if 'jsonrpc' not in response:
if response['error'] is not None:
raise JSONRPCException(response['error'], status)
elif 'result' not in response:
raise JSONRPCException({
'code': -343, 'message': 'missing JSON-RPC result'}, status)
elif status != HTTPStatus.OK:
raise JSONRPCException({
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
else:
return response['result']
else:
assert response['jsonrpc'] == '2.0'
if status != HTTPStatus.OK:
raise JSONRPCException({
'code': -342, 'message': 'non-200 HTTP status code'}, status)
if 'error' in response:
raise JSONRPCException(response['error'], status)
elif 'result' not in response:
raise JSONRPCException({
'code': -343, 'message': 'missing JSON-RPC 2.0 result and error'}, status)
return response['result']

def batch(self, rpc_call_list):
Expand All @@ -142,7 +155,7 @@ def batch(self, rpc_call_list):
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
if status != HTTPStatus.OK:
raise JSONRPCException({
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
'code': -342, 'message': 'non-200 HTTP status code'}, status)
return response

def _get_response(self):
Expand Down

0 comments on commit b225295

Please sign in to comment.