Skip to content

Commit 72506ed

Browse files
committed
Merge #15177: rest: Improve tests and documention of /headers and /block
7cf994d qa: Improve tests of /rest/headers and /rest/block (João Barbosa) 0825b86 doc: /rest/block responds with 404 if block does not exist (João Barbosa) be625f7 doc: Explain empty result of /rest/headers (João Barbosa) Pull request description: Follow up of #15107. Tree-SHA512: a7fdeed05216e3eda9604664db529237c2d0ddf422cfac139d6345a22b6e00bfe870d4e3f177423db7d4efb295ac2dc0ca2eb20c9c27c0719b89fd5428860d03
2 parents 9fa2b89 + 7cf994d commit 72506ed

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

doc/REST-interface.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ For full TX query capability, one must enable the transaction index via "txindex
2727
`GET /rest/block/notxdetails/<BLOCK-HASH>.<bin|hex|json>`
2828

2929
Given a block hash: returns a block, in binary, hex-encoded binary or JSON formats.
30+
Responds with 404 if the block doesn't exist.
3031

3132
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.
3233

@@ -36,6 +37,7 @@ With the /notxdetails/ option JSON response will only contain the transaction ha
3637
`GET /rest/headers/<COUNT>/<BLOCK-HASH>.<bin|hex|json>`
3738

3839
Given a block hash: returns <COUNT> amount of blockheaders in upward direction.
40+
Returns empty if the block doesn't exist or it isn't in the active chain.
3941

4042
#### Chaininfos
4143
`GET /rest/chaininfo.json`

test/functional/interface_rest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ def run_test(self):
201201
self.log.info("Test the /block and /headers URIs")
202202
bb_hash = self.nodes[0].getbestblockhash()
203203

204+
# Check result if block does not exists
205+
assert_equal(self.test_rest_request('/headers/1/0000000000000000000000000000000000000000000000000000000000000000'), [])
206+
self.test_rest_request('/block/0000000000000000000000000000000000000000000000000000000000000000', status=404, ret_type=RetType.OBJ)
207+
208+
# Check result if block is not in the active chain
209+
self.nodes[0].invalidateblock(bb_hash)
210+
assert_equal(self.test_rest_request('/headers/1/{}'.format(bb_hash)), [])
211+
self.test_rest_request('/block/{}'.format(bb_hash))
212+
self.nodes[0].reconsiderblock(bb_hash)
213+
204214
# Check binary format
205215
response = self.test_rest_request("/block/{}".format(bb_hash), req_type=ReqType.BIN, ret_type=RetType.OBJ)
206216
assert_greater_than(int(response.getheader('content-length')), 80)

0 commit comments

Comments
 (0)