From 8dcd4d3d11368c7c599cb4c675ea172a816b52c9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 12 Mar 2019 21:30:28 +0000 Subject: functional_tests: improve RPC blockchain tests --- tests/functional_tests/test_framework/rpc.py | 40 +++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'tests/functional_tests/test_framework/rpc.py') diff --git a/tests/functional_tests/test_framework/rpc.py b/tests/functional_tests/test_framework/rpc.py index b21df7b93..b857be4d2 100644 --- a/tests/functional_tests/test_framework/rpc.py +++ b/tests/functional_tests/test_framework/rpc.py @@ -29,21 +29,55 @@ import requests import json +class Response(dict): + def __init__(self, d): + for k in d.keys(): + if type(d[k]) == dict: + self[k] = Response(d[k]) + elif type(d[k]) == list: + self[k] = [] + for i in range(len(d[k])): + if type(d[k][i]) == dict: + self[k].append(Response(d[k][i])) + else: + self[k].append(d[k][i]) + else: + self[k] = d[k] + + def __getattr__(self, key): + return self[key] + def __setattr__(self, key, value): + self[key] = value + def __eq__(self, other): + if type(other) == dict: + return self == Response(other) + if self.keys() != other.keys(): + return False + for k in self.keys(): + if self[k] != other[k]: + return False + return True + class JSONRPC(object): def __init__(self, url): self.url = url - def send_request(self, inputs): + def send_request(self, path, inputs, result_field = None): res = requests.post( - self.url, + self.url + path, data=json.dumps(inputs), headers={'content-type': 'application/json'}) res = res.json() assert 'error' not in res, res - return res['result'] + if result_field: + res = res[result_field] + + return Response(res) + def send_json_rpc_request(self, inputs): + return self.send_request("/json_rpc", inputs, 'result') -- cgit v1.2.3