interface_rest.py
1 #!/usr/bin/env python3 2 # Copyright (c) 2014-2022 The Bitcoin Core developers 3 # Distributed under the MIT software license, see the accompanying 4 # file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 """Test the REST API.""" 6 7 from decimal import Decimal 8 from enum import Enum 9 from io import BytesIO 10 import http.client 11 import json 12 import typing 13 import urllib.parse 14 15 16 from test_framework.messages import ( 17 BLOCK_HEADER_SIZE, 18 COIN, 19 deser_block_spent_outputs, 20 ) 21 from test_framework.test_framework import BitcoinTestFramework 22 from test_framework.util import ( 23 assert_equal, 24 assert_greater_than, 25 assert_greater_than_or_equal, 26 ) 27 from test_framework.wallet import ( 28 MiniWallet, 29 getnewdestination, 30 ) 31 from typing import Optional 32 33 34 INVALID_PARAM = "abc" 35 UNKNOWN_PARAM = "0000000000000000000000000000000000000000000000000000000000000000" 36 37 38 class ReqType(Enum): 39 JSON = 1 40 BIN = 2 41 HEX = 3 42 43 class RetType(Enum): 44 OBJ = 1 45 BYTES = 2 46 JSON = 3 47 48 def filter_output_indices_by_value(vouts, value): 49 for vout in vouts: 50 if vout['value'] == value: 51 yield vout['n'] 52 53 class RESTTest (BitcoinTestFramework): 54 def set_test_params(self): 55 self.num_nodes = 2 56 self.extra_args = [["-rest", "-blockfilterindex=1"], []] 57 # whitelist peers to speed up tx relay / mempool sync 58 self.noban_tx_relay = True 59 self.supports_cli = False 60 61 def test_rest_request( 62 self, 63 uri: str, 64 http_method: str = 'GET', 65 req_type: ReqType = ReqType.JSON, 66 body: str = '', 67 status: int = 200, 68 ret_type: RetType = RetType.JSON, 69 query_params: Optional[dict[str, typing.Any]] = None, 70 ) -> typing.Union[http.client.HTTPResponse, bytes, str, None]: 71 rest_uri = '/rest' + uri 72 if req_type in ReqType: 73 rest_uri += f'.{req_type.name.lower()}' 74 if query_params: 75 rest_uri += f'?{urllib.parse.urlencode(query_params)}' 76 77 conn = http.client.HTTPConnection(self.url.hostname, self.url.port) 78 self.log.debug(f'{http_method} {rest_uri} {body}') 79 if http_method == 'GET': 80 conn.request('GET', rest_uri) 81 elif http_method == 'POST': 82 conn.request('POST', rest_uri, body) 83 resp = conn.getresponse() 84 85 assert_equal(resp.status, status) 86 87 if ret_type == RetType.OBJ: 88 return resp 89 elif ret_type == RetType.BYTES: 90 return resp.read() 91 elif ret_type == RetType.JSON: 92 return json.loads(resp.read().decode('utf-8'), parse_float=Decimal) 93 94 return None 95 96 def run_test(self): 97 self.url = urllib.parse.urlparse(self.nodes[0].url) 98 self.wallet = MiniWallet(self.nodes[0]) 99 100 self.log.info("Broadcast test transaction and sync nodes") 101 txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"] 102 self.sync_all() 103 104 self.log.info("Test the /tx URI") 105 106 json_obj = self.test_rest_request(f"/tx/{txid}") 107 assert_equal(json_obj['txid'], txid) 108 109 # Check hex format response 110 hex_response = self.test_rest_request(f"/tx/{txid}", req_type=ReqType.HEX, ret_type=RetType.OBJ) 111 assert_greater_than_or_equal(int(hex_response.getheader('content-length')), 112 json_obj['size']*2) 113 114 spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) # get the vin to later check for utxo (should be spent by then) 115 # get n of 0.1 outpoint 116 n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1')) 117 spending = (txid, n) 118 119 # Test /tx with an invalid and an unknown txid 120 resp = self.test_rest_request(uri=f"/tx/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) 121 assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}") 122 resp = self.test_rest_request(uri=f"/tx/{UNKNOWN_PARAM}", ret_type=RetType.OBJ, status=404) 123 assert_equal(resp.read().decode('utf-8').rstrip(), f"{UNKNOWN_PARAM} not found") 124 125 self.log.info("Query an unspent TXO using the /getutxos URI") 126 127 self.generate(self.wallet, 1) 128 bb_hash = self.nodes[0].getbestblockhash() 129 130 # Check chainTip response 131 json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}") 132 assert_equal(json_obj['chaintipHash'], bb_hash) 133 134 # Make sure there is one utxo 135 assert_equal(len(json_obj['utxos']), 1) 136 assert_equal(json_obj['utxos'][0]['value'], Decimal('0.1')) 137 138 self.log.info("Query a spent TXO using the /getutxos URI") 139 140 json_obj = self.test_rest_request(f"/getutxos/{spent[0]}-{spent[1]}") 141 142 # Check chainTip response 143 assert_equal(json_obj['chaintipHash'], bb_hash) 144 145 # Make sure there is no utxo in the response because this outpoint has been spent 146 assert_equal(len(json_obj['utxos']), 0) 147 148 # Check bitmap 149 assert_equal(json_obj['bitmap'], "0") 150 151 self.log.info("Query two TXOs using the /getutxos URI") 152 153 json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}/{spent[0]}-{spent[1]}") 154 155 assert_equal(len(json_obj['utxos']), 1) 156 assert_equal(json_obj['bitmap'], "10") 157 158 self.log.info("Query the TXOs using the /getutxos URI with a binary response") 159 160 bin_request = b'\x01\x02' 161 for txid, n in [spending, spent]: 162 bin_request += bytes.fromhex(txid) 163 bin_request += n.to_bytes(4, 'little') 164 165 bin_response = self.test_rest_request("/getutxos", http_method='POST', req_type=ReqType.BIN, body=bin_request, ret_type=RetType.BYTES) 166 chain_height = int.from_bytes(bin_response[0:4], 'little') 167 response_hash = bin_response[4:36][::-1].hex() 168 169 assert_equal(bb_hash, response_hash) # check if getutxo's chaintip during calculation was fine 170 assert_equal(chain_height, 201) # chain height must be 201 (pre-mined chain [200] + generated block [1]) 171 172 self.log.info("Test the /getutxos URI with and without /checkmempool") 173 # Create a transaction, check that it's found with /checkmempool, but 174 # not found without. Then confirm the transaction and check that it's 175 # found with or without /checkmempool. 176 177 # do a tx and don't sync 178 txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"] 179 json_obj = self.test_rest_request(f"/tx/{txid}") 180 # get the spent output to later check for utxo (should be spent by then) 181 spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) 182 # get n of 0.1 outpoint 183 n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1')) 184 spending = (txid, n) 185 186 json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}") 187 assert_equal(len(json_obj['utxos']), 0) 188 189 json_obj = self.test_rest_request(f"/getutxos/checkmempool/{spending[0]}-{spending[1]}") 190 assert_equal(len(json_obj['utxos']), 1) 191 192 json_obj = self.test_rest_request(f"/getutxos/{spent[0]}-{spent[1]}") 193 assert_equal(len(json_obj['utxos']), 1) 194 195 json_obj = self.test_rest_request(f"/getutxos/checkmempool/{spent[0]}-{spent[1]}") 196 assert_equal(len(json_obj['utxos']), 0) 197 198 self.generate(self.nodes[0], 1) 199 200 json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}") 201 assert_equal(len(json_obj['utxos']), 1) 202 203 json_obj = self.test_rest_request(f"/getutxos/checkmempool/{spending[0]}-{spending[1]}") 204 assert_equal(len(json_obj['utxos']), 1) 205 206 self.log.info("Check some invalid requests") 207 self.test_rest_request("/getutxos", http_method='POST', req_type=ReqType.JSON, body='{"checkmempool', status=400, ret_type=RetType.OBJ) 208 self.test_rest_request("/getutxos", http_method='POST', req_type=ReqType.BIN, body='{"checkmempool', status=400, ret_type=RetType.OBJ) 209 self.test_rest_request("/getutxos/checkmempool", http_method='POST', req_type=ReqType.JSON, status=400, ret_type=RetType.OBJ) 210 self.test_rest_request(f"/getutxos/{spending[0]}_+1", ret_type=RetType.OBJ, status=400) 211 self.test_rest_request(f"/getutxos/{spending[0]}-+1", ret_type=RetType.OBJ, status=400) 212 self.test_rest_request(f"/getutxos/{spending[0]}--1", ret_type=RetType.OBJ, status=400) 213 self.test_rest_request(f"/getutxos/{spending[0]}aa-1234", ret_type=RetType.OBJ, status=400) 214 self.test_rest_request("/getutxos/aa-1234", ret_type=RetType.OBJ, status=400) 215 216 # Test limits 217 long_uri = '/'.join([f"{txid}-{n_}" for n_ in range(20)]) 218 self.test_rest_request(f"/getutxos/checkmempool/{long_uri}", http_method='POST', status=400, ret_type=RetType.OBJ) 219 220 long_uri = '/'.join([f'{txid}-{n_}' for n_ in range(15)]) 221 self.test_rest_request(f"/getutxos/checkmempool/{long_uri}", http_method='POST', status=200) 222 223 self.generate(self.nodes[0], 1) # generate block to not affect upcoming tests 224 225 self.log.info("Test the /block, /blockhashbyheight, /headers, and /blockfilterheaders URIs") 226 bb_hash = self.nodes[0].getbestblockhash() 227 228 # Check result if block does not exists 229 assert_equal(self.test_rest_request(f"/headers/{UNKNOWN_PARAM}", query_params={"count": 1}), []) 230 self.test_rest_request(f"/block/{UNKNOWN_PARAM}", status=404, ret_type=RetType.OBJ) 231 232 # Check result if block is not in the active chain 233 self.nodes[0].invalidateblock(bb_hash) 234 assert_equal(self.test_rest_request(f'/headers/{bb_hash}', query_params={'count': 1}), []) 235 self.test_rest_request(f'/block/{bb_hash}') 236 self.nodes[0].reconsiderblock(bb_hash) 237 238 # Check binary format 239 response = self.test_rest_request(f"/block/{bb_hash}", req_type=ReqType.BIN, ret_type=RetType.OBJ) 240 assert_greater_than(int(response.getheader('content-length')), BLOCK_HEADER_SIZE) 241 response_bytes = response.read() 242 243 # Compare with block header 244 response_header = self.test_rest_request(f"/headers/{bb_hash}", req_type=ReqType.BIN, ret_type=RetType.OBJ, query_params={"count": 1}) 245 assert_equal(int(response_header.getheader('content-length')), BLOCK_HEADER_SIZE) 246 response_header_bytes = response_header.read() 247 assert_equal(response_bytes[:BLOCK_HEADER_SIZE], response_header_bytes) 248 249 # Check block hex format 250 response_hex = self.test_rest_request(f"/block/{bb_hash}", req_type=ReqType.HEX, ret_type=RetType.OBJ) 251 assert_greater_than(int(response_hex.getheader('content-length')), BLOCK_HEADER_SIZE*2) 252 response_hex_bytes = response_hex.read().strip(b'\n') 253 assert_equal(response_bytes.hex().encode(), response_hex_bytes) 254 255 # Compare with hex block header 256 response_header_hex = self.test_rest_request(f"/headers/{bb_hash}", req_type=ReqType.HEX, ret_type=RetType.OBJ, query_params={"count": 1}) 257 assert_greater_than(int(response_header_hex.getheader('content-length')), BLOCK_HEADER_SIZE*2) 258 response_header_hex_bytes = response_header_hex.read(BLOCK_HEADER_SIZE*2) 259 assert_equal(response_bytes[:BLOCK_HEADER_SIZE].hex().encode(), response_header_hex_bytes) 260 261 # Check json format 262 block_json_obj = self.test_rest_request(f"/block/{bb_hash}") 263 assert_equal(block_json_obj['hash'], bb_hash) 264 assert_equal(self.test_rest_request(f"/blockhashbyheight/{block_json_obj['height']}")['blockhash'], bb_hash) 265 266 # Check hex/bin format 267 resp_hex = self.test_rest_request(f"/blockhashbyheight/{block_json_obj['height']}", req_type=ReqType.HEX, ret_type=RetType.OBJ) 268 assert_equal(resp_hex.read().decode('utf-8').rstrip(), bb_hash) 269 resp_bytes = self.test_rest_request(f"/blockhashbyheight/{block_json_obj['height']}", req_type=ReqType.BIN, ret_type=RetType.BYTES) 270 blockhash = resp_bytes[::-1].hex() 271 assert_equal(blockhash, bb_hash) 272 273 # Check invalid blockhashbyheight requests 274 resp = self.test_rest_request(f"/blockhashbyheight/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) 275 assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid height: {INVALID_PARAM}") 276 resp = self.test_rest_request("/blockhashbyheight/+1", ret_type=RetType.OBJ, status=400) 277 assert_equal(resp.read().decode('utf-8').rstrip(), "Invalid height: +1") 278 resp = self.test_rest_request("/blockhashbyheight/1000000", ret_type=RetType.OBJ, status=404) 279 assert_equal(resp.read().decode('utf-8').rstrip(), "Block height out of range") 280 resp = self.test_rest_request("/blockhashbyheight/-1", ret_type=RetType.OBJ, status=400) 281 assert_equal(resp.read().decode('utf-8').rstrip(), "Invalid height: -1") 282 self.test_rest_request("/blockhashbyheight/", ret_type=RetType.OBJ, status=400) 283 284 # Compare with json block header 285 json_obj = self.test_rest_request(f"/headers/{bb_hash}", query_params={"count": 1}) 286 assert_equal(len(json_obj), 1) # ensure that there is one header in the json response 287 assert_equal(json_obj[0]['hash'], bb_hash) # request/response hash should be the same 288 289 # Check invalid uri (% symbol at the end of the request) 290 for invalid_uri in [f"/headers/{bb_hash}%", f"/blockfilterheaders/basic/{bb_hash}%", "/mempool/contents.json?%"]: 291 resp = self.test_rest_request(invalid_uri, ret_type=RetType.OBJ, status=400) 292 assert_equal(resp.read().decode('utf-8').rstrip(), "URI parsing failed, it likely contained RFC 3986 invalid characters") 293 294 # Compare with normal RPC block response 295 rpc_block_json = self.nodes[0].getblock(bb_hash) 296 for key in ['hash', 'confirmations', 'height', 'version', 'merkleroot', 'time', 'nonce', 'bits', 'target', 'difficulty', 'chainwork', 'previousblockhash']: 297 assert_equal(json_obj[0][key], rpc_block_json[key]) 298 299 # See if we can get 5 headers in one response 300 self.generate(self.nodes[1], 5) 301 expected_filter = { 302 'basic block filter index': {'synced': True, 'best_block_height': 208}, 303 } 304 self.wait_until(lambda: self.nodes[0].getindexinfo() == expected_filter) 305 json_obj = self.test_rest_request(f"/headers/{bb_hash}", query_params={"count": 5}) 306 assert_equal(len(json_obj), 5) # now we should have 5 header objects 307 json_obj = self.test_rest_request(f"/blockfilterheaders/basic/{bb_hash}", query_params={"count": 5}) 308 first_filter_header = json_obj[0] 309 assert_equal(len(json_obj), 5) # now we should have 5 filter header objects 310 json_obj = self.test_rest_request(f"/blockfilter/basic/{bb_hash}") 311 312 # Compare with normal RPC blockfilter response 313 rpc_blockfilter = self.nodes[0].getblockfilter(bb_hash) 314 assert_equal(first_filter_header, rpc_blockfilter['header']) 315 assert_equal(json_obj['filter'], rpc_blockfilter['filter']) 316 317 # Test blockfilterheaders with an invalid hash and filtertype 318 resp = self.test_rest_request(f"/blockfilterheaders/{INVALID_PARAM}/{bb_hash}", ret_type=RetType.OBJ, status=400) 319 assert_equal(resp.read().decode('utf-8').rstrip(), f"Unknown filtertype {INVALID_PARAM}") 320 resp = self.test_rest_request(f"/blockfilterheaders/basic/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) 321 assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}") 322 323 # Test number parsing 324 for num in ['5a', '-5', '0', '2001', '99999999999999999999999999999999999']: 325 assert_equal( 326 bytes(f'Header count is invalid or out of acceptable range (1-2000): {num}\r\n', 'ascii'), 327 self.test_rest_request(f"/headers/{bb_hash}", ret_type=RetType.BYTES, status=400, query_params={"count": num}), 328 ) 329 330 self.log.info("Test tx inclusion in the /mempool and /block URIs") 331 332 # Make 3 chained txs and mine them on node 1 333 txs = [] 334 input_txid = txid 335 for _ in range(3): 336 utxo_to_spend = self.wallet.get_utxo(txid=input_txid) 337 txs.append(self.wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['txid']) 338 input_txid = txs[-1] 339 self.sync_all() 340 341 # Check that there are exactly 3 transactions in the TX memory pool before generating the block 342 json_obj = self.test_rest_request("/mempool/info") 343 assert_equal(json_obj['size'], 3) 344 # the size of the memory pool should be greater than 3x ~100 bytes 345 assert_greater_than(json_obj['bytes'], 300) 346 347 mempool_info = self.nodes[0].getmempoolinfo() 348 # pop unstable unbroadcastcount before check 349 for obj in [json_obj, mempool_info]: 350 obj.pop("unbroadcastcount") 351 assert_equal(json_obj, mempool_info) 352 353 # Check that there are our submitted transactions in the TX memory pool 354 json_obj = self.test_rest_request("/mempool/contents") 355 raw_mempool_verbose = self.nodes[0].getrawmempool(verbose=True) 356 357 assert_equal(json_obj, raw_mempool_verbose) 358 359 for i, tx in enumerate(txs): 360 assert tx in json_obj 361 assert_equal(json_obj[tx]['spentby'], txs[i + 1:i + 2]) 362 assert_equal(json_obj[tx]['depends'], txs[i - 1:i]) 363 364 # Check the mempool response for explicit parameters 365 json_obj = self.test_rest_request("/mempool/contents", query_params={"verbose": "true", "mempool_sequence": "false"}) 366 assert_equal(json_obj, raw_mempool_verbose) 367 368 # Check the mempool response for not verbose 369 json_obj = self.test_rest_request("/mempool/contents", query_params={"verbose": "false"}) 370 raw_mempool = self.nodes[0].getrawmempool(verbose=False) 371 372 assert_equal(json_obj, raw_mempool) 373 374 # Check the mempool response for sequence 375 json_obj = self.test_rest_request("/mempool/contents", query_params={"verbose": "false", "mempool_sequence": "true"}) 376 raw_mempool = self.nodes[0].getrawmempool(verbose=False, mempool_sequence=True) 377 378 assert_equal(json_obj, raw_mempool) 379 380 # Check for error response if verbose=true and mempool_sequence=true 381 resp = self.test_rest_request("/mempool/contents", ret_type=RetType.OBJ, status=400, query_params={"verbose": "true", "mempool_sequence": "true"}) 382 assert_equal(resp.read().decode('utf-8').strip(), 'Verbose results cannot contain mempool sequence values. (hint: set "verbose=false")') 383 384 # Check for error response if verbose is not "true" or "false" 385 resp = self.test_rest_request("/mempool/contents", ret_type=RetType.OBJ, status=400, query_params={"verbose": "TRUE"}) 386 assert_equal(resp.read().decode('utf-8').strip(), 'The "verbose" query parameter must be either "true" or "false".') 387 388 # Check for error response if mempool_sequence is not "true" or "false" 389 resp = self.test_rest_request("/mempool/contents", ret_type=RetType.OBJ, status=400, query_params={"verbose": "false", "mempool_sequence": "TRUE"}) 390 assert_equal(resp.read().decode('utf-8').strip(), 'The "mempool_sequence" query parameter must be either "true" or "false".') 391 392 # Now mine the transactions 393 newblockhash = self.generate(self.nodes[1], 1) 394 395 # Check if the 3 tx show up in the new block 396 json_obj = self.test_rest_request(f"/block/{newblockhash[0]}") 397 non_coinbase_txs = {tx['txid'] for tx in json_obj['tx'] 398 if 'coinbase' not in tx['vin'][0]} 399 assert_equal(non_coinbase_txs, set(txs)) 400 401 # Verify that the non-coinbase tx has "prevout" key set 402 for tx_obj in json_obj["tx"]: 403 for vin in tx_obj["vin"]: 404 if "coinbase" not in vin: 405 assert "prevout" in vin 406 assert_equal(vin["prevout"]["generated"], False) 407 else: 408 assert "prevout" not in vin 409 410 # Check the same but without tx details 411 json_obj = self.test_rest_request(f"/block/notxdetails/{newblockhash[0]}") 412 for tx in txs: 413 assert tx in json_obj['tx'] 414 415 self.log.info("Test the /chaininfo URI") 416 417 bb_hash = self.nodes[0].getbestblockhash() 418 419 json_obj = self.test_rest_request("/chaininfo") 420 assert_equal(json_obj['bestblockhash'], bb_hash) 421 422 # Compare with normal RPC getblockchaininfo response 423 blockchain_info = self.nodes[0].getblockchaininfo() 424 assert_equal(blockchain_info, json_obj) 425 426 # Test compatibility of deprecated and newer endpoints 427 self.log.info("Test compatibility of deprecated and newer endpoints") 428 assert_equal(self.test_rest_request(f"/headers/{bb_hash}", query_params={"count": 1}), self.test_rest_request(f"/headers/1/{bb_hash}")) 429 assert_equal(self.test_rest_request(f"/blockfilterheaders/basic/{bb_hash}", query_params={"count": 1}), self.test_rest_request(f"/blockfilterheaders/basic/5/{bb_hash}")) 430 431 self.log.info("Test the /spenttxouts URI") 432 433 block_count = self.nodes[0].getblockcount() 434 for height in range(0, block_count + 1): 435 blockhash = self.nodes[0].getblockhash(height) 436 spent_bin = self.test_rest_request(f"/spenttxouts/{blockhash}", req_type=ReqType.BIN, ret_type=RetType.BYTES) 437 spent_hex = self.test_rest_request(f"/spenttxouts/{blockhash}", req_type=ReqType.HEX, ret_type=RetType.BYTES) 438 spent_json = self.test_rest_request(f"/spenttxouts/{blockhash}", req_type=ReqType.JSON, ret_type=RetType.JSON) 439 440 assert_equal(bytes.fromhex(spent_hex.decode()), spent_bin) 441 442 spent = deser_block_spent_outputs(BytesIO(spent_bin)) 443 block = self.nodes[0].getblock(blockhash, 3) # return prevout for each input 444 assert_equal(len(spent), len(block["tx"])) 445 assert_equal(len(spent_json), len(block["tx"])) 446 447 for i, tx in enumerate(block["tx"]): 448 prevouts = [txin["prevout"] for txin in tx["vin"] if "coinbase" not in txin] 449 # compare with `getblock` JSON output (coinbase tx has no prevouts) 450 actual = [(txout.scriptPubKey.hex(), Decimal(txout.nValue) / COIN) for txout in spent[i]] 451 expected = [(p["scriptPubKey"]["hex"], p["value"]) for p in prevouts] 452 assert_equal(expected, actual) 453 # also compare JSON format 454 actual = [(prevout["scriptPubKey"], prevout["value"]) for prevout in spent_json[i]] 455 expected = [(p["scriptPubKey"], p["value"]) for p in prevouts] 456 assert_equal(expected, actual) 457 458 459 self.log.info("Test the /deploymentinfo URI") 460 461 deployment_info = self.nodes[0].getdeploymentinfo() 462 assert_equal(deployment_info, self.test_rest_request('/deploymentinfo')) 463 464 previous_bb_hash = self.nodes[0].getblockhash(self.nodes[0].getblockcount() - 1) 465 deployment_info = self.nodes[0].getdeploymentinfo(previous_bb_hash) 466 assert_equal(deployment_info, self.test_rest_request(f"/deploymentinfo/{previous_bb_hash}")) 467 468 non_existing_blockhash = '42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4' 469 resp = self.test_rest_request(f'/deploymentinfo/{non_existing_blockhash}', ret_type=RetType.OBJ, status=400) 470 assert_equal(resp.read().decode('utf-8').rstrip(), "Block not found") 471 472 resp = self.test_rest_request(f"/deploymentinfo/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) 473 assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}") 474 475 if __name__ == '__main__': 476 RESTTest(__file__).main()