aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorMatthew Zipkin <pinheadmz@gmail.com>2024-06-06 11:42:38 -0400
committerMatthew Zipkin <pinheadmz@gmail.com>2024-06-07 09:26:55 -0400
commitb22529529823c0cb5916ac318c8536e9107b7e78 (patch)
treecd9bae0e64a213d24e43c63dfb8bee42dfe104bc /test/functional/test_framework
parent391843b0297db03d71a8d88ab77609e2ad230bf2 (diff)
downloadbitcoin-b22529529823c0cb5916ac318c8536e9107b7e78.tar.xz
test: use json-rpc 2.0 in all functional tests by default
Diffstat (limited to 'test/functional/test_framework')
-rw-r--r--test/functional/test_framework/authproxy.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py
index 7edf9f3679..a357ae4d34 100644
--- a/test/functional/test_framework/authproxy.py
+++ b/test/functional/test_framework/authproxy.py
@@ -26,7 +26,7 @@ ServiceProxy class:
- 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
@@ -117,7 +117,7 @@ class AuthServiceProxy():
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}
@@ -125,15 +125,28 @@ class AuthServiceProxy():
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):
@@ -142,7 +155,7 @@ class AuthServiceProxy():
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):