aboutsummaryrefslogtreecommitdiff
path: root/tests/functional_tests/test_framework
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional_tests/test_framework')
-rw-r--r--tests/functional_tests/test_framework/daemon.py64
-rw-r--r--tests/functional_tests/test_framework/rpc.py40
-rw-r--r--tests/functional_tests/test_framework/wallet.py16
3 files changed, 100 insertions, 20 deletions
diff --git a/tests/functional_tests/test_framework/daemon.py b/tests/functional_tests/test_framework/daemon.py
index f3490b232..c7619a434 100644
--- a/tests/functional_tests/test_framework/daemon.py
+++ b/tests/functional_tests/test_framework/daemon.py
@@ -32,8 +32,8 @@ from .rpc import JSONRPC
class Daemon(object):
- def __init__(self, protocol='http', host='127.0.0.1', port=18081, path='/json_rpc'):
- self.rpc = JSONRPC('{protocol}://{host}:{port}{path}'.format(protocol=protocol, host=host, port=port, path=path))
+ def __init__(self, protocol='http', host='127.0.0.1', port=18081):
+ self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port))
def getblocktemplate(self, address):
getblocktemplate = {
@@ -45,7 +45,7 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(getblocktemplate)
+ return self.rpc.send_json_rpc_request(getblocktemplate)
def submitblock(self, block):
submitblock = {
@@ -54,7 +54,7 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(submitblock)
+ return self.rpc.send_json_rpc_request(submitblock)
def getblock(self, height=0):
getblock = {
@@ -65,7 +65,39 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(getblock)
+ return self.rpc.send_json_rpc_request(getblock)
+
+ def getlastblockheader(self):
+ getlastblockheader = {
+ 'method': 'getlastblockheader',
+ 'params': {
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(getlastblockheader)
+
+ def getblockheaderbyhash(self, hash):
+ getblockheaderbyhash = {
+ 'method': 'getblockheaderbyhash',
+ 'params': {
+ 'hash': hash,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(getblockheaderbyhash)
+
+ def getblockheaderbyheight(self, height):
+ getblockheaderbyheight = {
+ 'method': 'getblockheaderbyheight',
+ 'params': {
+ 'height': height,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(getblockheaderbyheight)
def get_connections(self):
get_connections = {
@@ -73,7 +105,7 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(get_connections)
+ return self.rpc.send_json_rpc_request(get_connections)
def get_info(self):
get_info = {
@@ -81,7 +113,7 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(get_info)
+ return self.rpc.send_json_rpc_request(get_info)
def hard_fork_info(self):
hard_fork_info = {
@@ -89,7 +121,7 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(hard_fork_info)
+ return self.rpc.send_json_rpc_request(hard_fork_info)
def generateblocks(self, address, blocks=1):
generateblocks = {
@@ -102,4 +134,18 @@ class Daemon(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(generateblocks)
+ return self.rpc.send_json_rpc_request(generateblocks)
+
+ def get_height(self):
+ get_height = {
+ 'method': 'get_height',
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_request("/get_height", get_height)
+
+ def pop_blocks(self, nblocks = 1):
+ pop_blocks = {
+ 'nblocks' : nblocks,
+ }
+ return self.rpc.send_request("/pop_blocks", pop_blocks)
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')
diff --git a/tests/functional_tests/test_framework/wallet.py b/tests/functional_tests/test_framework/wallet.py
index 357eab5b2..2ea2e4b68 100644
--- a/tests/functional_tests/test_framework/wallet.py
+++ b/tests/functional_tests/test_framework/wallet.py
@@ -32,8 +32,8 @@ from .rpc import JSONRPC
class Wallet(object):
- def __init__(self, protocol='http', host='127.0.0.1', port=18083, path='/json_rpc'):
- self.rpc = JSONRPC('{protocol}://{host}:{port}{path}'.format(protocol=protocol, host=host, port=port, path=path))
+ def __init__(self, protocol='http', host='127.0.0.1', port=18083):
+ self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port))
def make_uniform_destinations(self, address, transfer_amount, transfer_number_of_destinations=1):
destinations = []
@@ -60,7 +60,7 @@ class Wallet(object):
}
if(len(payment_id) > 0):
transfer['params'].update({'payment_id' : payment_id})
- return self.rpc.send_request(transfer)
+ return self.rpc.send_json_rpc_request(transfer)
def transfer_split(self, destinations, ringsize=7, payment_id=''):
print(destinations)
@@ -77,7 +77,7 @@ class Wallet(object):
}
if(len(payment_id) > 0):
transfer['params'].update({'payment_id' : payment_id})
- return self.rpc.send_request(transfer)
+ return self.rpc.send_json_rpc_request(transfer)
def create_wallet(self, index=''):
create_wallet = {
@@ -90,7 +90,7 @@ class Wallet(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(create_wallet)
+ return self.rpc.send_json_rpc_request(create_wallet)
def get_balance(self):
get_balance = {
@@ -98,7 +98,7 @@ class Wallet(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(get_balance)
+ return self.rpc.send_json_rpc_request(get_balance)
def sweep_dust(self):
sweep_dust = {
@@ -106,7 +106,7 @@ class Wallet(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(sweep_dust)
+ return self.rpc.send_json_rpc_request(sweep_dust)
def sweep_all(self, address):
sweep_all = {
@@ -117,4 +117,4 @@ class Wallet(object):
'jsonrpc': '2.0',
'id': '0'
}
- return self.rpc.send_request(sweep_all)
+ return self.rpc.send_json_rpc_request(sweep_all)