functional_tests: add test for mining via wallet
This commit is contained in:
parent
447268cf29
commit
a71d91cecf
|
@ -46,7 +46,8 @@ class MiningTest():
|
|||
def run_test(self):
|
||||
self.reset()
|
||||
self.create()
|
||||
self.mine()
|
||||
self.mine(True)
|
||||
self.mine(False)
|
||||
|
||||
def reset(self):
|
||||
print('Resetting blockchain')
|
||||
|
@ -62,8 +63,8 @@ class MiningTest():
|
|||
except: pass
|
||||
res = wallet.restore_deterministic_wallet(seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted')
|
||||
|
||||
def mine(self):
|
||||
print("Test mining")
|
||||
def mine(self, via_daemon):
|
||||
print("Test mining via " + ("daemon" if via_daemon else "wallet"))
|
||||
|
||||
daemon = Daemon()
|
||||
wallet = Wallet()
|
||||
|
@ -76,7 +77,10 @@ class MiningTest():
|
|||
|
||||
res_status = daemon.mining_status()
|
||||
|
||||
res = daemon.start_mining('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', threads_count = 1)
|
||||
if via_daemon:
|
||||
res = daemon.start_mining('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', threads_count = 1)
|
||||
else:
|
||||
res = wallet.start_mining(threads_count = 1)
|
||||
|
||||
res_status = daemon.mining_status()
|
||||
assert res_status.active == True
|
||||
|
@ -101,7 +105,11 @@ class MiningTest():
|
|||
timeout -= 1
|
||||
assert timeout >= 0
|
||||
|
||||
res = daemon.stop_mining()
|
||||
if via_daemon:
|
||||
res = daemon.stop_mining()
|
||||
else:
|
||||
res = wallet.stop_mining()
|
||||
|
||||
res_status = daemon.mining_status()
|
||||
assert res_status.active == False
|
||||
|
||||
|
@ -113,7 +121,10 @@ class MiningTest():
|
|||
balance = res_getbalance.balance
|
||||
assert balance >= prev_balance + (new_height - prev_height) * 600000000000
|
||||
|
||||
res = daemon.start_mining('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', threads_count = 1, do_background_mining = True)
|
||||
if via_daemon:
|
||||
res = daemon.start_mining('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', threads_count = 1, do_background_mining = True)
|
||||
else:
|
||||
res = wallet.start_mining(threads_count = 1, do_background_mining = True)
|
||||
res_status = daemon.mining_status()
|
||||
assert res_status.active == True
|
||||
assert res_status.threads_count == 1
|
||||
|
@ -122,7 +133,10 @@ class MiningTest():
|
|||
assert res_status.block_reward >= 600000000000
|
||||
|
||||
# don't wait, might be a while if the machine is busy, which it probably is
|
||||
res = daemon.stop_mining()
|
||||
if via_daemon:
|
||||
res = daemon.stop_mining()
|
||||
else:
|
||||
res = wallet.stop_mining()
|
||||
res_status = daemon.mining_status()
|
||||
assert res_status.active == False
|
||||
|
||||
|
|
|
@ -781,6 +781,29 @@ class Wallet(object):
|
|||
}
|
||||
return self.rpc.send_json_rpc_request(validate_address)
|
||||
|
||||
def start_mining(self, threads_count, do_background_mining = False, ignore_battery = False):
|
||||
start_mining = {
|
||||
'method': 'start_mining',
|
||||
'jsonrpc': '2.0',
|
||||
'params': {
|
||||
'threads_count': threads_count,
|
||||
'do_background_mining': do_background_mining,
|
||||
'ignore_battery': ignore_battery,
|
||||
},
|
||||
'id': '0'
|
||||
}
|
||||
return self.rpc.send_json_rpc_request(start_mining)
|
||||
|
||||
def stop_mining(self):
|
||||
stop_mining = {
|
||||
'method': 'stop_mining',
|
||||
'jsonrpc': '2.0',
|
||||
'params': {
|
||||
},
|
||||
'id': '0'
|
||||
}
|
||||
return self.rpc.send_json_rpc_request(stop_mining)
|
||||
|
||||
def get_version(self):
|
||||
get_version = {
|
||||
'method': 'get_version',
|
||||
|
|
Loading…
Reference in New Issue