(self)
| 73 | return json.loads(resp.read().decode('utf-8'), parse_float=Decimal) |
| 74 | |
| 75 | def run_test(self): |
| 76 | self.url = urllib.parse.urlparse(self.nodes[0].url) |
| 77 | self.log.info("Mine blocks and send Bitcoin to node 1") |
| 78 | |
| 79 | # Random address so node1's balance doesn't increase |
| 80 | not_related_address = "2MxqoHEdNQTyYeX1mHcbrrpzgojbosTpCvJ" |
| 81 | |
| 82 | self.nodes[0].generate(1) |
| 83 | self.sync_all() |
| 84 | self.nodes[1].generatetoaddress(100, not_related_address) |
| 85 | self.sync_all() |
| 86 | |
| 87 | assert_equal(self.nodes[0].getbalance(), 50) |
| 88 | |
| 89 | txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) |
| 90 | self.sync_all() |
| 91 | self.nodes[1].generatetoaddress(1, not_related_address) |
| 92 | self.sync_all() |
| 93 | bb_hash = self.nodes[0].getbestblockhash() |
| 94 | |
| 95 | assert_equal(self.nodes[1].getbalance(), Decimal("0.1")) |
| 96 | |
| 97 | self.log.info("Load the transaction using the /tx URI") |
| 98 | |
| 99 | json_obj = self.test_rest_request("/tx/{}".format(txid)) |
| 100 | spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) # get the vin to later check for utxo (should be spent by then) |
| 101 | # get n of 0.1 outpoint |
| 102 | n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1')) |
| 103 | spending = (txid, n) |
| 104 | |
| 105 | self.log.info("Query an unspent TXO using the /getutxos URI") |
| 106 | |
| 107 | json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spending)) |
| 108 | |
| 109 | # Check chainTip response |
| 110 | assert_equal(json_obj['chaintipHash'], bb_hash) |
| 111 | |
| 112 | # Make sure there is one utxo |
| 113 | assert_equal(len(json_obj['utxos']), 1) |
| 114 | assert_equal(json_obj['utxos'][0]['value'], Decimal('0.1')) |
| 115 | |
| 116 | self.log.info("Query a spent TXO using the /getutxos URI") |
| 117 | |
| 118 | json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spent)) |
| 119 | |
| 120 | # Check chainTip response |
| 121 | assert_equal(json_obj['chaintipHash'], bb_hash) |
| 122 | |
| 123 | # Make sure there is no utxo in the response because this outpoint has been spent |
| 124 | assert_equal(len(json_obj['utxos']), 0) |
| 125 | |
| 126 | # Check bitmap |
| 127 | assert_equal(json_obj['bitmap'], "0") |
| 128 | |
| 129 | self.log.info("Query two TXOs using the /getutxos URI") |
| 130 | |
| 131 | json_obj = self.test_rest_request("/getutxos/{}-{}/{}-{}".format(*(spending + spent))) |
| 132 |
nothing calls this directly
no test coverage detected