Merge #15177: rest: Improve tests and documention of /headers and /block

7cf994d5cfd53dcff76ebd0e0007e3477a7570e8 qa: Improve tests of /rest/headers and /rest/block (João Barbosa)
0825b86b280c684c32c60bac9e862298c7279f27 doc: /rest/block responds with 404 if block does not exist (João Barbosa)
be625f7c5562afed517ff51d2d85268ba5ce6017 doc: Explain empty result of /rest/headers (João Barbosa)

Pull request description:

  Follow up of #15107.

Tree-SHA512: a7fdeed05216e3eda9604664db529237c2d0ddf422cfac139d6345a22b6e00bfe870d4e3f177423db7d4efb295ac2dc0ca2eb20c9c27c0719b89fd5428860d03
This commit is contained in:
Wladimir J. van der Laan 2019-01-21 17:37:18 +01:00 committed by Pasta
parent 29645d5832
commit 949f158bc1
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 12 additions and 0 deletions

View File

@ -20,6 +20,7 @@ For full TX query capability, one must enable the transaction index via "txindex
`GET /rest/block/notxdetails/<BLOCK-HASH>.<bin|hex|json>` `GET /rest/block/notxdetails/<BLOCK-HASH>.<bin|hex|json>`
Given a block hash: returns a block, in binary, hex-encoded binary or JSON formats. Given a block hash: returns a block, in binary, hex-encoded binary or JSON formats.
Responds with 404 if the block doesn't exist.
The HTTP request and response are both handled entirely in-memory, thus making maximum memory usage at least 2.66MB (1 MB max block, plus hex encoding) per request. The HTTP request and response are both handled entirely in-memory, thus making maximum memory usage at least 2.66MB (1 MB max block, plus hex encoding) per request.
@ -29,6 +30,7 @@ With the /notxdetails/ option JSON response will only contain the transaction ha
`GET /rest/headers/<COUNT>/<BLOCK-HASH>.<bin|hex|json>` `GET /rest/headers/<COUNT>/<BLOCK-HASH>.<bin|hex|json>`
Given a block hash: returns <COUNT> amount of blockheaders in upward direction. Given a block hash: returns <COUNT> amount of blockheaders in upward direction.
Returns empty if the block doesn't exist or it isn't in the active chain.
#### Chaininfos #### Chaininfos
`GET /rest/chaininfo.json` `GET /rest/chaininfo.json`

View File

@ -198,6 +198,16 @@ class RESTTest (BitcoinTestFramework):
self.log.info("Test the /block and /headers URIs") self.log.info("Test the /block and /headers URIs")
bb_hash = self.nodes[0].getbestblockhash() bb_hash = self.nodes[0].getbestblockhash()
# Check result if block does not exists
assert_equal(self.test_rest_request('/headers/1/0000000000000000000000000000000000000000000000000000000000000000'), [])
self.test_rest_request('/block/0000000000000000000000000000000000000000000000000000000000000000', status=404, ret_type=RetType.OBJ)
# Check result if block is not in the active chain
self.nodes[0].invalidateblock(bb_hash)
assert_equal(self.test_rest_request('/headers/1/{}'.format(bb_hash)), [])
self.test_rest_request('/block/{}'.format(bb_hash))
self.nodes[0].reconsiderblock(bb_hash)
# Check binary format # Check binary format
response = self.test_rest_request("/block/{}".format(bb_hash), req_type=ReqType.BIN, ret_type=RetType.OBJ) response = self.test_rest_request("/block/{}".format(bb_hash), req_type=ReqType.BIN, ret_type=RetType.OBJ)
assert_greater_than(int(response.getheader('content-length')), 80) assert_greater_than(int(response.getheader('content-length')), 80)