Refactor wait_and_assert_operationid_status to allow returning the result
This commit is contained in:
parent
7c4ad6e298
commit
d2a584e35a
|
@ -8,7 +8,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
|
|||
from decimal import Decimal
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal, assert_true, get_coinbase_address, \
|
||||
initialize_chain_clean, start_nodes, wait_and_assert_operationid_status
|
||||
initialize_chain_clean, start_nodes, wait_and_assert_operationid_status, \
|
||||
wait_and_assert_operationid_status_result
|
||||
|
||||
|
||||
class SproutSaplingMigration(BitcoinTestFramework):
|
||||
|
@ -54,14 +55,17 @@ class SproutSaplingMigration(BitcoinTestFramework):
|
|||
|
||||
# At 495 we should have an async operation
|
||||
operationstatus = self.nodes[0].z_getoperationstatus()
|
||||
print "migration operation: {}".format(operationstatus)
|
||||
assert_equal(1, len(operationstatus), "num async operations at 495")
|
||||
assert_equal('saplingmigration', operationstatus[0]['method'])
|
||||
assert_equal(500, operationstatus[0]['target_height'])
|
||||
|
||||
print "migration operation: {}".format(operationstatus)
|
||||
migration_opid = operationstatus[0]['id']
|
||||
result = wait_and_assert_operationid_status(self.nodes[0], migration_opid)
|
||||
result = wait_and_assert_operationid_status_result(self.nodes[0], operationstatus[0]['id'])
|
||||
print "result: {}".format(result)
|
||||
assert_equal('saplingmigration', result['method'])
|
||||
assert_equal(500, result['target_height'])
|
||||
assert_equal(1, result['result']['num_tx_created'])
|
||||
|
||||
assert_equal(0, len(self.nodes[0].getrawmempool()), "mempool size at 495")
|
||||
|
||||
self.nodes[0].generate(3)
|
||||
|
|
|
@ -385,8 +385,9 @@ def assert_raises(exc, fun, *args, **kwds):
|
|||
def fail(message=""):
|
||||
raise AssertionError(message)
|
||||
|
||||
# Returns txid if operation was a success or None
|
||||
def wait_and_assert_operationid_status(node, myopid, in_status='success', in_errormsg=None, timeout=300):
|
||||
|
||||
# Returns an async operation result
|
||||
def wait_and_assert_operationid_status_result(node, myopid, in_status='success', in_errormsg=None, timeout=300):
|
||||
print('waiting for async operation {}'.format(myopid))
|
||||
result = None
|
||||
for _ in xrange(1, timeout):
|
||||
|
@ -399,29 +400,29 @@ def wait_and_assert_operationid_status(node, myopid, in_status='success', in_err
|
|||
assert_true(result is not None, "timeout occured")
|
||||
status = result['status']
|
||||
|
||||
ret = None
|
||||
debug = os.getenv("PYTHON_DEBUG", "")
|
||||
if debug:
|
||||
print('...returned status: {}'.format(status))
|
||||
|
||||
errormsg = None
|
||||
if status == "failed":
|
||||
errormsg = result['error']['message']
|
||||
elif status == "success":
|
||||
if type(result['result']) is dict and result['result'].get('txid'):
|
||||
ret = result['result']['txid']
|
||||
else:
|
||||
ret = result['result']
|
||||
|
||||
if os.getenv("PYTHON_DEBUG", ""):
|
||||
print('...returned status: {}'.format(status))
|
||||
if errormsg is not None:
|
||||
if debug:
|
||||
print('...returned error: {}'.format(errormsg))
|
||||
assert_equal(in_errormsg, errormsg)
|
||||
|
||||
assert_equal(in_status, status, "Operation returned mismatched status. Error Message: {}".format(errormsg))
|
||||
|
||||
if errormsg is not None:
|
||||
assert_true(in_errormsg is not None, "No error retured. Expected: {}".format(errormsg))
|
||||
assert_true(in_errormsg in errormsg, "Error returned: {}. Error expected: {}".format(errormsg, in_errormsg))
|
||||
return result # if there was an error return the result
|
||||
return result
|
||||
|
||||
|
||||
# Returns txid if operation was a success or None
|
||||
def wait_and_assert_operationid_status(node, myopid, in_status='success', in_errormsg=None, timeout=300):
|
||||
result = wait_and_assert_operationid_status_result(node, myopid, in_status, in_errormsg, timeout)
|
||||
if result['status'] == "success":
|
||||
return result['result']['txid']
|
||||
else:
|
||||
return ret # otherwise return the txid
|
||||
return None
|
||||
|
||||
# Find a coinbase address on the node, filtering by the number of UTXOs it has.
|
||||
# If no filter is provided, returns the coinbase address on the node containing
|
||||
|
|
|
@ -10,7 +10,7 @@ from test_framework.authproxy import JSONRPCException
|
|||
from test_framework.mininode import COIN
|
||||
from test_framework.util import assert_equal, initialize_chain_clean, \
|
||||
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status, \
|
||||
get_coinbase_address
|
||||
wait_and_assert_operationid_status_result, get_coinbase_address
|
||||
|
||||
import sys
|
||||
import timeit
|
||||
|
@ -92,7 +92,7 @@ class WalletProtectCoinbaseTest (BitcoinTestFramework):
|
|||
recipients.append({"address":myzaddr, "amount":Decimal('1.23456789')})
|
||||
|
||||
myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
|
||||
error_result = wait_and_assert_operationid_status(self.nodes[0], myopid, "failed", "wallet does not allow any change", 10)
|
||||
error_result = wait_and_assert_operationid_status_result(self.nodes[0], myopid, "failed", "wallet does not allow any change", 10)
|
||||
|
||||
# Test that the returned status object contains a params field with the operation's input parameters
|
||||
assert_equal(error_result["method"], "z_sendmany")
|
||||
|
|
Loading…
Reference in New Issue