|
22 | 22 |
|
23 | 23 | from test_framework.messages import BLOCK_HEADER_SIZE
|
24 | 24 |
|
| 25 | +INVALID_PARAM = "abc" |
| 26 | +UNKNOWN_PARAM = "0000000000000000000000000000000000000000000000000000000000000000" |
| 27 | + |
| 28 | + |
25 | 29 | class ReqType(Enum):
|
26 | 30 | JSON = 1
|
27 | 31 | BIN = 2
|
@@ -103,6 +107,12 @@ def run_test(self):
|
103 | 107 | n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1'))
|
104 | 108 | spending = (txid, n)
|
105 | 109 |
|
| 110 | + # Test /tx with an invalid and an unknown txid |
| 111 | + resp = self.test_rest_request(uri=f"/tx/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) |
| 112 | + assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}") |
| 113 | + resp = self.test_rest_request(uri=f"/tx/{UNKNOWN_PARAM}", ret_type=RetType.OBJ, status=404) |
| 114 | + assert_equal(resp.read().decode('utf-8').rstrip(), f"{UNKNOWN_PARAM} not found") |
| 115 | + |
106 | 116 | self.log.info("Query an unspent TXO using the /getutxos URI")
|
107 | 117 |
|
108 | 118 | self.generatetoaddress(self.nodes[1], 1, not_related_address)
|
@@ -205,8 +215,8 @@ def run_test(self):
|
205 | 215 | bb_hash = self.nodes[0].getbestblockhash()
|
206 | 216 |
|
207 | 217 | # Check result if block does not exists
|
208 |
| - assert_equal(self.test_rest_request('/headers/1/0000000000000000000000000000000000000000000000000000000000000000'), []) |
209 |
| - self.test_rest_request('/block/0000000000000000000000000000000000000000000000000000000000000000', status=404, ret_type=RetType.OBJ) |
| 218 | + assert_equal(self.test_rest_request(f"/headers/1/{UNKNOWN_PARAM}"), []) |
| 219 | + self.test_rest_request(f"/block/{UNKNOWN_PARAM}", status=404, ret_type=RetType.OBJ) |
210 | 220 |
|
211 | 221 | # Check result if block is not in the active chain
|
212 | 222 | self.nodes[0].invalidateblock(bb_hash)
|
@@ -250,8 +260,8 @@ def run_test(self):
|
250 | 260 | assert_equal(blockhash, bb_hash)
|
251 | 261 |
|
252 | 262 | # Check invalid blockhashbyheight requests
|
253 |
| - resp = self.test_rest_request("/blockhashbyheight/abc", ret_type=RetType.OBJ, status=400) |
254 |
| - assert_equal(resp.read().decode('utf-8').rstrip(), "Invalid height: abc") |
| 263 | + resp = self.test_rest_request(f"/blockhashbyheight/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) |
| 264 | + assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid height: {INVALID_PARAM}") |
255 | 265 | resp = self.test_rest_request("/blockhashbyheight/1000000", ret_type=RetType.OBJ, status=404)
|
256 | 266 | assert_equal(resp.read().decode('utf-8').rstrip(), "Block height out of range")
|
257 | 267 | resp = self.test_rest_request("/blockhashbyheight/-1", ret_type=RetType.OBJ, status=400)
|
|
0 commit comments