Skip to content

Commit

Permalink
rest: Improve tests and documention of /headers and /block
Browse files Browse the repository at this point in the history
Summary: This is a backport of Core [[bitcoin/bitcoin#15177 | PR15177]]

Test Plan: `ninja && test/functional/test_runner.py interface_rest`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8355
  • Loading branch information
promag authored and PiRK committed Nov 10, 2020
1 parent f67e38b commit d793890
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/REST-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ To query for a confirmed transaction, enable the transaction index via "txindex=
`GET /rest/block/notxdetails/<BLOCK-HASH>.<bin|hex|json>`

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.

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

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.

#### Blockhash by height
`GET /rest/blockhashbyheight/<HEIGHT>.<bin|hex|json>`
Expand Down
16 changes: 16 additions & 0 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ def run_test(self):
self.log.info("Test the /block, /blockhashbyheight and /headers URIs")
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
response = self.test_rest_request(
"/block/{}".format(bb_hash), req_type=ReqType.BIN, ret_type=RetType.OBJ)
Expand Down

0 comments on commit d793890

Please sign in to comment.