aboutsummaryrefslogtreecommitdiff
path: root/tests/functional_tests/test_framework/rpc.py
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-12 21:30:28 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-21 19:26:49 +0000
commit8dcd4d3d11368c7c599cb4c675ea172a816b52c9 (patch)
tree8b54728de6554c01a483950c5bdfa38345ff88e5 /tests/functional_tests/test_framework/rpc.py
parentMerge pull request #5267 (diff)
downloadmonero-8dcd4d3d11368c7c599cb4c675ea172a816b52c9.tar.xz
functional_tests: improve RPC blockchain tests
Diffstat (limited to 'tests/functional_tests/test_framework/rpc.py')
-rw-r--r--tests/functional_tests/test_framework/rpc.py40
1 files changed, 37 insertions, 3 deletions
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')