Skip to content

Commit

Permalink
[QA] add rest tests for /rest/blockhashbyheight/<HEIGHT>.<FORMAT>
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Jan 21, 2019
1 parent eb9ef04 commit 579d418
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/functional/interface_rest.py
Expand Up @@ -198,7 +198,7 @@ def run_test(self):
self.nodes[0].generate(1) # generate block to not affect upcoming tests
self.sync_all()

self.log.info("Test the /block and /headers URIs")
self.log.info("Test the /block, /blockhashbyheight and /headers URIs")
bb_hash = self.nodes[0].getbestblockhash()

# Check binary format
Expand Down Expand Up @@ -227,6 +227,23 @@ def run_test(self):
# Check json format
block_json_obj = self.test_rest_request("/block/{}".format(bb_hash))
assert_equal(block_json_obj['hash'], bb_hash)
assert_equal(self.test_rest_request("/blockhashbyheight/{}".format(block_json_obj['height']))['blockhash'], bb_hash)

# Check hex/bin format
resp_hex = self.test_rest_request("/blockhashbyheight/{}".format(block_json_obj['height']), req_type=ReqType.HEX, ret_type=RetType.OBJ)
assert_equal(resp_hex.read().decode('utf-8').rstrip(), bb_hash)
resp_bytes = self.test_rest_request("/blockhashbyheight/{}".format(block_json_obj['height']), req_type=ReqType.BIN, ret_type=RetType.BYTES)
blockhash = binascii.hexlify(resp_bytes[::-1]).decode('utf-8')
assert_equal(blockhash, bb_hash)

# Check invalid blockhashbyheight requests
resp = self.test_rest_request("/blockhashbyheight/abc", ret_type=RetType.OBJ, status=400)
assert_equal(resp.read().decode('utf-8').rstrip(), "Invalid height: abc")
resp = self.test_rest_request("/blockhashbyheight/1000000", ret_type=RetType.OBJ, status=404)
assert_equal(resp.read().decode('utf-8').rstrip(), "Block height out of range")
resp = self.test_rest_request("/blockhashbyheight/-1", ret_type=RetType.OBJ, status=400)
assert_equal(resp.read().decode('utf-8').rstrip(), "Invalid height: -1")
self.test_rest_request("/blockhashbyheight/", ret_type=RetType.OBJ, status=400)

# Compare with json block header
json_obj = self.test_rest_request("/headers/1/{}".format(bb_hash))
Expand Down

0 comments on commit 579d418

Please sign in to comment.