Changeset View
Changeset View
Standalone View
Standalone View
test/functional/interface_rest.py
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
n = 0 | n = 0 | ||||
for vout in json_obj['vout']: | for vout in json_obj['vout']: | ||||
if vout['value'] == 0.1: | if vout['value'] == 0.1: | ||||
n = vout['n'] | n = vout['n'] | ||||
# | # | ||||
# GETUTXOS: query an unspent outpoint # | # GETUTXOS: query an unspent outpoint # | ||||
# | # | ||||
json_request = '/checkmempool/' + txid + '-' + str(n) | json_request = '/' + txid + '-' + str(n) | ||||
json_string = http_get_call( | json_string = http_get_call( | ||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | ||||
json_obj = json.loads(json_string) | json_obj = json.loads(json_string) | ||||
# check chainTip response | # check chainTip response | ||||
assert_equal(json_obj['chaintipHash'], bb_hash) | assert_equal(json_obj['chaintipHash'], bb_hash) | ||||
# make sure there is one utxo | # make sure there is one utxo | ||||
assert_equal(len(json_obj['utxos']), 1) | assert_equal(len(json_obj['utxos']), 1) | ||||
assert_equal(json_obj['utxos'][0]['value'], 0.1) | assert_equal(json_obj['utxos'][0]['value'], 0.1) | ||||
# | # | ||||
# GETUTXOS: now query an already spent outpoint # | # GETUTXOS: now query an already spent outpoint # | ||||
# | # | ||||
json_request = '/checkmempool/' + vintx + '-0' | json_request = '/' + vintx + '-0' | ||||
json_string = http_get_call( | json_string = http_get_call( | ||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | ||||
json_obj = json.loads(json_string) | json_obj = json.loads(json_string) | ||||
# check chainTip response | # check chainTip response | ||||
assert_equal(json_obj['chaintipHash'], bb_hash) | assert_equal(json_obj['chaintipHash'], bb_hash) | ||||
# make sure there is no utox in the response because this oupoint has | # make sure there is no utox in the response because this oupoint has | ||||
# been spent | # been spent | ||||
assert_equal(len(json_obj['utxos']), 0) | assert_equal(len(json_obj['utxos']), 0) | ||||
# check bitmap | # check bitmap | ||||
assert_equal(json_obj['bitmap'], "0") | assert_equal(json_obj['bitmap'], "0") | ||||
# | # | ||||
# GETUTXOS: now check both with the same request # | # GETUTXOS: now check both with the same request # | ||||
# | # | ||||
json_request = '/checkmempool/' + \ | json_request = '/' + txid + '-' + str(n) + '/' + vintx + '-0' | ||||
txid + '-' + str(n) + '/' + vintx + '-0' | |||||
json_string = http_get_call( | json_string = http_get_call( | ||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | ||||
json_obj = json.loads(json_string) | json_obj = json.loads(json_string) | ||||
assert_equal(len(json_obj['utxos']), 1) | assert_equal(len(json_obj['utxos']), 1) | ||||
assert_equal(json_obj['bitmap'], "10") | assert_equal(json_obj['bitmap'], "10") | ||||
# test binary response | # test binary response | ||||
bb_hash = self.nodes[0].getbestblockhash() | bb_hash = self.nodes[0].getbestblockhash() | ||||
Show All 20 Lines | def run_test(self): | ||||
# GETUTXOS: mempool checks # | # GETUTXOS: mempool checks # | ||||
# | # | ||||
# 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_string = http_get_call( | json_string = http_get_call( | ||||
url.hostname, url.port, '/rest/tx/' + txid + self.FORMAT_SEPARATOR + "json") | url.hostname, url.port, '/rest/tx/' + txid + self.FORMAT_SEPARATOR + "json") | ||||
json_obj = json.loads(json_string) | json_obj = json.loads(json_string) | ||||
vintx = json_obj['vin'][0]['txid'] | # get the spent output to later check for utxo (should be spent by then) | ||||
# get the vin to later check for utxo (should be spent by then) | spent = '{}-{}'.format(json_obj['vin'][0] | ||||
['txid'], json_obj['vin'][0]['vout']) | |||||
# get n of 0.1 outpoint | # get n of 0.1 outpoint | ||||
n = 0 | n = 0 | ||||
for vout in json_obj['vout']: | for vout in json_obj['vout']: | ||||
if vout['value'] == 0.1: | if vout['value'] == 0.1: | ||||
n = vout['n'] | n = vout['n'] | ||||
spending = '{}-{}'.format(txid, n) | |||||
json_request = '/' + txid + '-' + str(n) | json_request = '/' + spending | ||||
json_string = http_get_call( | json_string = http_get_call( | ||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | ||||
json_obj = json.loads(json_string) | json_obj = json.loads(json_string) | ||||
# there should be an outpoint because it has just added to | # there should be no outpoint because it has just added to | ||||
# the mempool | # the mempool | ||||
assert_equal(len(json_obj['utxos']), 0) | assert_equal(len(json_obj['utxos']), 0) | ||||
json_request = '/checkmempool/' + txid + '-' + str(n) | json_request = '/checkmempool/' + spending | ||||
json_string = http_get_call( | json_string = http_get_call( | ||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | ||||
json_obj = json.loads(json_string) | json_obj = json.loads(json_string) | ||||
# there should be an outpoint because it has just added to | # there should be an outpoint because it has just added to | ||||
# the mempool | # the mempool | ||||
assert_equal(len(json_obj['utxos']), 1) | assert_equal(len(json_obj['utxos']), 1) | ||||
json_request = '/' + spent | |||||
json_string = http_get_call( | |||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | |||||
json_obj = json.loads(json_string) | |||||
# there should be an outpoint because its spending tx is not confirmed | |||||
assert_equal(len(json_obj['utxos']), 1) | |||||
json_request = '/checkmempool/' + spent | |||||
json_string = http_get_call( | |||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | |||||
json_obj = json.loads(json_string) | |||||
# there should be no outpoint because it has just spent (by mempool tx) | |||||
assert_equal(len(json_obj['utxos']), 0) | |||||
self.nodes[0].generate(1) | |||||
self.sync_all() | |||||
json_request = '/' + spending | |||||
json_string = http_get_call( | |||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | |||||
json_obj = json.loads(json_string) | |||||
# there should be an outpoint because it was mined | |||||
assert_equal(len(json_obj['utxos']), 1) | |||||
json_request = '/checkmempool/' + spending | |||||
json_string = http_get_call( | |||||
url.hostname, url.port, '/rest/getutxos' + json_request + self.FORMAT_SEPARATOR + 'json') | |||||
json_obj = json.loads(json_string) | |||||
# there should be an outpoint because it was mined | |||||
assert_equal(len(json_obj['utxos']), 1) | |||||
# do some invalid requests | # do some invalid requests | ||||
json_request = '{"checkmempool' | json_request = '{"checkmempool' | ||||
response = http_post_call( | response = http_post_call( | ||||
url.hostname, url.port, '/rest/getutxos' + self.FORMAT_SEPARATOR + 'json', json_request, True) | url.hostname, url.port, '/rest/getutxos' + self.FORMAT_SEPARATOR + 'json', json_request, True) | ||||
# must be a 400 because we send an invalid json request | # must be a 400 because we send an invalid json request | ||||
assert_equal(response.status, 400) | assert_equal(response.status, 400) | ||||
json_request = '{"checkmempool' | json_request = '{"checkmempool' | ||||
▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines |