Changeset View
Changeset View
Standalone View
Standalone View
test/functional/interface_rest.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | class RESTTest (BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-rest"], []] | self.extra_args = [["-rest"], []] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def test_rest_request(self, uri, http_method='GET', req_type=ReqType.JSON, body='', status=200, ret_type=RetType.JSON): | def test_rest_request(self, uri, http_method='GET', req_type=ReqType.JSON, | ||||
body='', status=200, ret_type=RetType.JSON): | |||||
rest_uri = '/rest' + uri | rest_uri = '/rest' + uri | ||||
if req_type == ReqType.JSON: | if req_type == ReqType.JSON: | ||||
rest_uri += '.json' | rest_uri += '.json' | ||||
elif req_type == ReqType.BIN: | elif req_type == ReqType.BIN: | ||||
rest_uri += '.bin' | rest_uri += '.bin' | ||||
elif req_type == ReqType.HEX: | elif req_type == ReqType.HEX: | ||||
rest_uri += '.hex' | rest_uri += '.hex' | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info("Test the /getutxos URI with and without /checkmempool") | self.log.info("Test the /getutxos URI with and without /checkmempool") | ||||
# Create a transaction, check that it's found with /checkmempool, but | # Create a transaction, check that it's found with /checkmempool, but | ||||
# not found without. Then confirm the transaction and check that it's | # not found without. Then confirm the transaction and check that it's | ||||
# found with or without /checkmempool. | # found with or without /checkmempool. | ||||
# Do a tx and don't sync | # Do a tx and don't sync | ||||
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) | txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) | ||||
json_obj = self.test_rest_request("/tx/{}".format(txid)) | json_obj = self.test_rest_request("/tx/{}".format(txid)) | ||||
# Get the spent output to later check for utxo (should be spent by then) | # Get the spent output to later check for utxo (should be spent by | ||||
# then) | |||||
spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) | spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) | ||||
# Get n of 0.1 outpoint | # Get n of 0.1 outpoint | ||||
n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1')) | n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1')) | ||||
spending = (txid, n) | spending = (txid, n) | ||||
json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spending)) | json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spending)) | ||||
assert_equal(len(json_obj['utxos']), 0) | assert_equal(len(json_obj['utxos']), 0) | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
json_obj = self.test_rest_request("/headers/1/{}".format(bb_hash)) | json_obj = self.test_rest_request("/headers/1/{}".format(bb_hash)) | ||||
# Ensure that there is one header in the json response | # Ensure that there is one header in the json response | ||||
assert_equal(len(json_obj), 1) | assert_equal(len(json_obj), 1) | ||||
# Request/response hash should be the same | # Request/response hash should be the same | ||||
assert_equal(json_obj[0]['hash'], bb_hash) | assert_equal(json_obj[0]['hash'], bb_hash) | ||||
# Compare with normal RPC block response | # Compare with normal RPC block response | ||||
rpc_block_json = self.nodes[0].getblock(bb_hash) | rpc_block_json = self.nodes[0].getblock(bb_hash) | ||||
for key in ['hash', 'confirmations', 'height', 'version', 'merkleroot', 'time', 'nonce', 'bits', 'difficulty', 'chainwork', 'previousblockhash']: | for key in ['hash', 'confirmations', 'height', 'version', 'merkleroot', | ||||
'time', 'nonce', 'bits', 'difficulty', 'chainwork', 'previousblockhash']: | |||||
assert_equal(json_obj[0][key], rpc_block_json[key]) | assert_equal(json_obj[0][key], rpc_block_json[key]) | ||||
# See if we can get 5 headers in one response | # See if we can get 5 headers in one response | ||||
self.nodes[1].generate(5) | self.nodes[1].generate(5) | ||||
self.sync_all() | self.sync_all() | ||||
json_obj = self.test_rest_request("/headers/5/{}".format(bb_hash)) | json_obj = self.test_rest_request("/headers/5/{}".format(bb_hash)) | ||||
# Now we should have 5 header objects | # Now we should have 5 header objects | ||||
assert_equal(len(json_obj), 5) | assert_equal(len(json_obj), 5) | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |