(self)
| 95 | return None |
| 96 | |
| 97 | def run_test(self): |
| 98 | self.url = urllib.parse.urlparse(self.nodes[0].url) |
| 99 | self.wallet = MiniWallet(self.nodes[0]) |
| 100 | |
| 101 | self.log.info("Broadcast test transaction and sync nodes") |
| 102 | txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"] |
| 103 | self.sync_all() |
| 104 | |
| 105 | self.log.info("Test the /tx URI") |
| 106 | |
| 107 | json_obj = self.test_rest_request(f"/tx/{txid}") |
| 108 | assert_equal(json_obj['txid'], txid) |
| 109 | |
| 110 | # Check hex format response |
| 111 | hex_response = self.test_rest_request(f"/tx/{txid}", req_type=ReqType.HEX, ret_type=RetType.OBJ) |
| 112 | assert_greater_than_or_equal(int(hex_response.getheader('content-length')), |
| 113 | json_obj['size']*2) |
| 114 | |
| 115 | spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) # get the vin to later check for utxo (should be spent by then) |
| 116 | # get n of 0.1 outpoint |
| 117 | n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1')) |
| 118 | spending = (txid, n) |
| 119 | |
| 120 | # Test /tx with an invalid and an unknown txid |
| 121 | resp = self.test_rest_request(uri=f"/tx/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) |
| 122 | assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}") |
| 123 | resp = self.test_rest_request(uri=f"/tx/{UNKNOWN_PARAM}", ret_type=RetType.OBJ, status=404) |
| 124 | assert_equal(resp.read().decode('utf-8').rstrip(), f"{UNKNOWN_PARAM} not found") |
| 125 | |
| 126 | self.log.info("Query an unspent TXO using the /getutxos URI") |
| 127 | |
| 128 | self.generate(self.wallet, 1) |
| 129 | bb_hash = self.nodes[0].getbestblockhash() |
| 130 | |
| 131 | # Check chainTip response |
| 132 | json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}") |
| 133 | assert_equal(json_obj['chaintipHash'], bb_hash) |
| 134 | |
| 135 | # Make sure there is one utxo |
| 136 | assert_equal(len(json_obj['utxos']), 1) |
| 137 | assert_equal(json_obj['utxos'][0]['value'], Decimal('0.1')) |
| 138 | |
| 139 | self.log.info("Query a spent TXO using the /getutxos URI") |
| 140 | |
| 141 | json_obj = self.test_rest_request(f"/getutxos/{spent[0]}-{spent[1]}") |
| 142 | |
| 143 | # Check chainTip response |
| 144 | assert_equal(json_obj['chaintipHash'], bb_hash) |
| 145 | |
| 146 | # Make sure there is no utxo in the response because this outpoint has been spent |
| 147 | assert_equal(len(json_obj['utxos']), 0) |
| 148 | |
| 149 | # Check bitmap |
| 150 | assert_equal(json_obj['bitmap'], "0") |
| 151 | |
| 152 | self.log.info("Query two TXOs using the /getutxos URI") |
| 153 | |
| 154 | json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}/{spent[0]}-{spent[1]}") |
nothing calls this directly
no test coverage detected