def run_test(self):
    url = urllib.parse.urlparse(self.nodes[0].url)
    self.log.info('Mining blocks...')
    self.nodes[0].generate(1)
    self.sync_all()
    self.nodes[2].generate(100)
    self.sync_all()
    assert_equal(self.nodes[0].getbalance(), 50)
    txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
    self.sync_all()
    self.nodes[2].generate(1)
    self.sync_all()
    bb_hash = self.nodes[0].getbestblockhash()
    assert_equal(self.nodes[1].getbalance(), Decimal('0.1'))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + txid) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    vintx = json_obj['vin'][0]['txid']
    n = 0
    for vout in json_obj['vout']:
        if (vout['value'] == 0.1):
            n = vout['n']
    json_request = ((('/checkmempool/' + txid) + '-') + str(n))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['chaintipHash'], bb_hash)
    assert_equal(len(json_obj['utxos']), 1)
    assert_equal(json_obj['utxos'][0]['value'], 0.1)
    json_request = (('/checkmempool/' + vintx) + '-0')
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['chaintipHash'], bb_hash)
    assert_equal(len(json_obj['utxos']), 0)
    assert_equal(json_obj['bitmap'], '0')
    json_request = (((((('/checkmempool/' + txid) + '-') + str(n)) + '/') + vintx) + '-0')
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(len(json_obj['utxos']), 1)
    assert_equal(json_obj['bitmap'], '10')
    bb_hash = self.nodes[0].getbestblockhash()
    binaryRequest = b'\x01\x02'
    binaryRequest += hex_str_to_bytes(txid)
    binaryRequest += pack('i', n)
    binaryRequest += hex_str_to_bytes(vintx)
    binaryRequest += pack('i', 0)
    bin_response = http_post_call(url.hostname, url.port, (('/rest/getutxos' + self.FORMAT_SEPARATOR) + 'bin'), binaryRequest)
    output = BytesIO()
    output.write(bin_response)
    output.seek(0)
    chainHeight = unpack('i', output.read(4))[0]
    hashFromBinResponse = hex(deser_uint256(output))[2:].zfill(64)
    assert_equal(bb_hash, hashFromBinResponse)
    assert_equal(chainHeight, 102)
    txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
    json_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + txid) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    vintx = json_obj['vin'][0]['txid']
    n = 0
    for vout in json_obj['vout']:
        if (vout['value'] == 0.1):
            n = vout['n']
    json_request = ((('/' + txid) + '-') + str(n))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(len(json_obj['utxos']), 0)
    json_request = ((('/checkmempool/' + txid) + '-') + str(n))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(len(json_obj['utxos']), 1)
    json_request = '{"checkmempool'
    response = http_post_call(url.hostname, url.port, (('/rest/getutxos' + self.FORMAT_SEPARATOR) + 'json'), json_request, True)
    assert_equal(response.status, 400)
    json_request = '{"checkmempool'
    response = http_post_call(url.hostname, url.port, (('/rest/getutxos' + self.FORMAT_SEPARATOR) + 'bin'), json_request, True)
    assert_equal(response.status, 400)
    response = http_post_call(url.hostname, url.port, (('/rest/getutxos/checkmempool' + self.FORMAT_SEPARATOR) + 'bin'), '', True)
    assert_equal(response.status, 400)
    json_request = '/checkmempool/'
    for x in range(0, 20):
        json_request += (((txid + '-') + str(n)) + '/')
    json_request = json_request.rstrip('/')
    response = http_post_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'), '', True)
    assert_equal(response.status, 400)
    json_request = '/checkmempool/'
    for x in range(0, 15):
        json_request += (((txid + '-') + str(n)) + '/')
    json_request = json_request.rstrip('/')
    response = http_post_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'), '', True)
    assert_equal(response.status, 200)
    self.nodes[0].generate(1)
    self.sync_all()
    response = http_get_call(url.hostname, url.port, ((('/rest/block/' + bb_hash) + self.FORMAT_SEPARATOR) + 'bin'), True)
    assert_equal(response.status, 200)
    assert_greater_than(int(response.getheader('content-length')), 80)
    response_str = response.read()
    response_header = http_get_call(url.hostname, url.port, ((('/rest/headers/1/' + bb_hash) + self.FORMAT_SEPARATOR) + 'bin'), True)
    assert_equal(response_header.status, 200)
    assert_equal(int(response_header.getheader('content-length')), 80)
    response_header_str = response_header.read()
    assert_equal(response_str[0:80], response_header_str)
    response_hex = http_get_call(url.hostname, url.port, ((('/rest/block/' + bb_hash) + self.FORMAT_SEPARATOR) + 'hex'), True)
    assert_equal(response_hex.status, 200)
    assert_greater_than(int(response_hex.getheader('content-length')), 160)
    response_hex_str = response_hex.read()
    assert_equal(encode(response_str, 'hex_codec')[0:160], response_hex_str[0:160])
    response_header_hex = http_get_call(url.hostname, url.port, ((('/rest/headers/1/' + bb_hash) + self.FORMAT_SEPARATOR) + 'hex'), True)
    assert_equal(response_header_hex.status, 200)
    assert_greater_than(int(response_header_hex.getheader('content-length')), 160)
    response_header_hex_str = response_header_hex.read()
    assert_equal(response_hex_str[0:160], response_header_hex_str[0:160])
    assert_equal(encode(response_header_str, 'hex_codec')[0:160], response_header_hex_str[0:160])
    block_json_string = http_get_call(url.hostname, url.port, ((('/rest/block/' + bb_hash) + self.FORMAT_SEPARATOR) + 'json'))
    block_json_obj = json.loads(block_json_string)
    assert_equal(block_json_obj['hash'], bb_hash)
    response_header_json = http_get_call(url.hostname, url.port, ((('/rest/headers/1/' + bb_hash) + self.FORMAT_SEPARATOR) + 'json'), True)
    assert_equal(response_header_json.status, 200)
    response_header_json_str = response_header_json.read().decode('utf-8')
    json_obj = json.loads(response_header_json_str, parse_float=Decimal)
    assert_equal(len(json_obj), 1)
    assert_equal(json_obj[0]['hash'], bb_hash)
    rpc_block_json = self.nodes[0].getblock(bb_hash)
    assert_equal(json_obj[0]['hash'], rpc_block_json['hash'])
    assert_equal(json_obj[0]['confirmations'], rpc_block_json['confirmations'])
    assert_equal(json_obj[0]['height'], rpc_block_json['height'])
    assert_equal(json_obj[0]['version'], rpc_block_json['version'])
    assert_equal(json_obj[0]['merkleroot'], rpc_block_json['merkleroot'])
    assert_equal(json_obj[0]['time'], rpc_block_json['time'])
    assert_equal(json_obj[0]['nonce'], rpc_block_json['nonce'])
    assert_equal(json_obj[0]['bits'], rpc_block_json['bits'])
    assert_equal(json_obj[0]['difficulty'], rpc_block_json['difficulty'])
    assert_equal(json_obj[0]['chainwork'], rpc_block_json['chainwork'])
    assert_equal(json_obj[0]['previousblockhash'], rpc_block_json['previousblockhash'])
    self.nodes[1].generate(5)
    self.sync_all()
    response_header_json = http_get_call(url.hostname, url.port, ((('/rest/headers/5/' + bb_hash) + self.FORMAT_SEPARATOR) + 'json'), True)
    assert_equal(response_header_json.status, 200)
    response_header_json_str = response_header_json.read().decode('utf-8')
    json_obj = json.loads(response_header_json_str)
    assert_equal(len(json_obj), 5)
    tx_hash = block_json_obj['tx'][0]['txid']
    json_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + tx_hash) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['txid'], tx_hash)
    hex_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + tx_hash) + self.FORMAT_SEPARATOR) + 'hex'), True)
    assert_equal(hex_string.status, 200)
    assert_greater_than(int(response.getheader('content-length')), 10)
    txs = []
    txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
    txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
    txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
    self.sync_all()
    json_string = http_get_call(url.hostname, url.port, (('/rest/mempool/info' + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['size'], 3)
    assert_greater_than(json_obj['bytes'], 300)
    json_string = http_get_call(url.hostname, url.port, (('/rest/mempool/contents' + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    for (i, tx) in enumerate(txs):
        assert_equal((tx in json_obj), True)
        assert_equal(json_obj[tx]['spentby'], txs[(i + 1):(i + 2)])
        assert_equal(json_obj[tx]['depends'], txs[(i - 1):i])
    newblockhash = self.nodes[1].generate(1)
    self.sync_all()
    json_string = http_get_call(url.hostname, url.port, ((('/rest/block/' + newblockhash[0]) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    for tx in json_obj['tx']:
        if (not ('coinbase' in tx['vin'][0])):
            assert_equal((tx['txid'] in txs), True)
    json_string = http_get_call(url.hostname, url.port, ((('/rest/block/notxdetails/' + newblockhash[0]) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    for tx in txs:
        assert_equal((tx in json_obj['tx']), True)
    bb_hash = self.nodes[0].getbestblockhash()
    json_string = http_get_call(url.hostname, url.port, '/rest/chaininfo.json')
    json_obj = json.loads(json_string)
    assert_equal(json_obj['bestblockhash'], bb_hash)
def run_test(self):
    url = urllib.parse.urlparse(self.nodes[0].url)
    self.log.info('Mining blocks...')
    self.nodes[0].generate(1)
    self.sync_all()
    self.nodes[2].generate(100)
    self.sync_all()
    assert_equal(self.nodes[0].getbalance(), 50)
    txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
    self.sync_all()
    self.nodes[2].generate(1)
    self.sync_all()
    bb_hash = self.nodes[0].getbestblockhash()
    assert_equal(self.nodes[1].getbalance(), Decimal('0.1'))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + txid) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    vintx = json_obj['vin'][0]['txid']
    n = 0
    for vout in json_obj['vout']:
        if (vout['value'] == 0.1):
            n = vout['n']
    json_request = ((('/checkmempool/' + txid) + '-') + str(n))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['chaintipHash'], bb_hash)
    assert_equal(len(json_obj['utxos']), 1)
    assert_equal(json_obj['utxos'][0]['value'], 0.1)
    json_request = (('/checkmempool/' + vintx) + '-0')
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['chaintipHash'], bb_hash)
    assert_equal(len(json_obj['utxos']), 0)
    assert_equal(json_obj['bitmap'], '0')
    json_request = (((((('/checkmempool/' + txid) + '-') + str(n)) + '/') + vintx) + '-0')
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(len(json_obj['utxos']), 1)
    assert_equal(json_obj['bitmap'], '10')
    bb_hash = self.nodes[0].getbestblockhash()
    binaryRequest = b'\x01\x02'
    binaryRequest += hex_str_to_bytes(txid)
    binaryRequest += pack('i', n)
    binaryRequest += hex_str_to_bytes(vintx)
    binaryRequest += pack('i', 0)
    bin_response = http_post_call(url.hostname, url.port, (('/rest/getutxos' + self.FORMAT_SEPARATOR) + 'bin'), binaryRequest)
    output = BytesIO()
    output.write(bin_response)
    output.seek(0)
    chainHeight = unpack('i', output.read(4))[0]
    hashFromBinResponse = hex(deser_uint256(output))[2:].zfill(64)
    assert_equal(bb_hash, hashFromBinResponse)
    assert_equal(chainHeight, 102)
    txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
    json_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + txid) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    vintx = json_obj['vin'][0]['txid']
    n = 0
    for vout in json_obj['vout']:
        if (vout['value'] == 0.1):
            n = vout['n']
    json_request = ((('/' + txid) + '-') + str(n))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(len(json_obj['utxos']), 0)
    json_request = ((('/checkmempool/' + txid) + '-') + str(n))
    json_string = http_get_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(len(json_obj['utxos']), 1)
    json_request = '{"checkmempool'
    response = http_post_call(url.hostname, url.port, (('/rest/getutxos' + self.FORMAT_SEPARATOR) + 'json'), json_request, True)
    assert_equal(response.status, 400)
    json_request = '{"checkmempool'
    response = http_post_call(url.hostname, url.port, (('/rest/getutxos' + self.FORMAT_SEPARATOR) + 'bin'), json_request, True)
    assert_equal(response.status, 400)
    response = http_post_call(url.hostname, url.port, (('/rest/getutxos/checkmempool' + self.FORMAT_SEPARATOR) + 'bin'), , True)
    assert_equal(response.status, 400)
    json_request = '/checkmempool/'
    for x in range(0, 20):
        json_request += (((txid + '-') + str(n)) + '/')
    json_request = json_request.rstrip('/')
    response = http_post_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'), , True)
    assert_equal(response.status, 400)
    json_request = '/checkmempool/'
    for x in range(0, 15):
        json_request += (((txid + '-') + str(n)) + '/')
    json_request = json_request.rstrip('/')
    response = http_post_call(url.hostname, url.port, ((('/rest/getutxos' + json_request) + self.FORMAT_SEPARATOR) + 'json'), , True)
    assert_equal(response.status, 200)
    self.nodes[0].generate(1)
    self.sync_all()
    response = http_get_call(url.hostname, url.port, ((('/rest/block/' + bb_hash) + self.FORMAT_SEPARATOR) + 'bin'), True)
    assert_equal(response.status, 200)
    assert_greater_than(int(response.getheader('content-length')), 80)
    response_str = response.read()
    response_header = http_get_call(url.hostname, url.port, ((('/rest/headers/1/' + bb_hash) + self.FORMAT_SEPARATOR) + 'bin'), True)
    assert_equal(response_header.status, 200)
    assert_equal(int(response_header.getheader('content-length')), 80)
    response_header_str = response_header.read()
    assert_equal(response_str[0:80], response_header_str)
    response_hex = http_get_call(url.hostname, url.port, ((('/rest/block/' + bb_hash) + self.FORMAT_SEPARATOR) + 'hex'), True)
    assert_equal(response_hex.status, 200)
    assert_greater_than(int(response_hex.getheader('content-length')), 160)
    response_hex_str = response_hex.read()
    assert_equal(encode(response_str, 'hex_codec')[0:160], response_hex_str[0:160])
    response_header_hex = http_get_call(url.hostname, url.port, ((('/rest/headers/1/' + bb_hash) + self.FORMAT_SEPARATOR) + 'hex'), True)
    assert_equal(response_header_hex.status, 200)
    assert_greater_than(int(response_header_hex.getheader('content-length')), 160)
    response_header_hex_str = response_header_hex.read()
    assert_equal(response_hex_str[0:160], response_header_hex_str[0:160])
    assert_equal(encode(response_header_str, 'hex_codec')[0:160], response_header_hex_str[0:160])
    block_json_string = http_get_call(url.hostname, url.port, ((('/rest/block/' + bb_hash) + self.FORMAT_SEPARATOR) + 'json'))
    block_json_obj = json.loads(block_json_string)
    assert_equal(block_json_obj['hash'], bb_hash)
    response_header_json = http_get_call(url.hostname, url.port, ((('/rest/headers/1/' + bb_hash) + self.FORMAT_SEPARATOR) + 'json'), True)
    assert_equal(response_header_json.status, 200)
    response_header_json_str = response_header_json.read().decode('utf-8')
    json_obj = json.loads(response_header_json_str, parse_float=Decimal)
    assert_equal(len(json_obj), 1)
    assert_equal(json_obj[0]['hash'], bb_hash)
    rpc_block_json = self.nodes[0].getblock(bb_hash)
    assert_equal(json_obj[0]['hash'], rpc_block_json['hash'])
    assert_equal(json_obj[0]['confirmations'], rpc_block_json['confirmations'])
    assert_equal(json_obj[0]['height'], rpc_block_json['height'])
    assert_equal(json_obj[0]['version'], rpc_block_json['version'])
    assert_equal(json_obj[0]['merkleroot'], rpc_block_json['merkleroot'])
    assert_equal(json_obj[0]['time'], rpc_block_json['time'])
    assert_equal(json_obj[0]['nonce'], rpc_block_json['nonce'])
    assert_equal(json_obj[0]['bits'], rpc_block_json['bits'])
    assert_equal(json_obj[0]['difficulty'], rpc_block_json['difficulty'])
    assert_equal(json_obj[0]['chainwork'], rpc_block_json['chainwork'])
    assert_equal(json_obj[0]['previousblockhash'], rpc_block_json['previousblockhash'])
    self.nodes[1].generate(5)
    self.sync_all()
    response_header_json = http_get_call(url.hostname, url.port, ((('/rest/headers/5/' + bb_hash) + self.FORMAT_SEPARATOR) + 'json'), True)
    assert_equal(response_header_json.status, 200)
    response_header_json_str = response_header_json.read().decode('utf-8')
    json_obj = json.loads(response_header_json_str)
    assert_equal(len(json_obj), 5)
    tx_hash = block_json_obj['tx'][0]['txid']
    json_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + tx_hash) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['txid'], tx_hash)
    hex_string = http_get_call(url.hostname, url.port, ((('/rest/tx/' + tx_hash) + self.FORMAT_SEPARATOR) + 'hex'), True)
    assert_equal(hex_string.status, 200)
    assert_greater_than(int(response.getheader('content-length')), 10)
    txs = []
    txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
    txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
    txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
    self.sync_all()
    json_string = http_get_call(url.hostname, url.port, (('/rest/mempool/info' + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    assert_equal(json_obj['size'], 3)
    assert_greater_than(json_obj['bytes'], 300)
    json_string = http_get_call(url.hostname, url.port, (('/rest/mempool/contents' + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    for (i, tx) in enumerate(txs):
        assert_equal((tx in json_obj), True)
        assert_equal(json_obj[tx]['spentby'], txs[(i + 1):(i + 2)])
        assert_equal(json_obj[tx]['depends'], txs[(i - 1):i])
    newblockhash = self.nodes[1].generate(1)
    self.sync_all()
    json_string = http_get_call(url.hostname, url.port, ((('/rest/block/' + newblockhash[0]) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    for tx in json_obj['tx']:
        if (not ('coinbase' in tx['vin'][0])):
            assert_equal((tx['txid'] in txs), True)
    json_string = http_get_call(url.hostname, url.port, ((('/rest/block/notxdetails/' + newblockhash[0]) + self.FORMAT_SEPARATOR) + 'json'))
    json_obj = json.loads(json_string)
    for tx in txs:
        assert_equal((tx in json_obj['tx']), True)
    bb_hash = self.nodes[0].getbestblockhash()
    json_string = http_get_call(url.hostname, url.port, '/rest/chaininfo.json')
    json_obj = json.loads(json_string)
    assert_equal(json_obj['bestblockhash'], bb_hash)