Skip to content

Commit

Permalink
pytest: extend get_all_heights to return hashes as well
Browse files Browse the repository at this point in the history
Replace BaseNode.get_all_heights method with BaseNode.get_all_blocks which
returns hashes alongside heights of all the blocks known to a node.  This
feature will be used in future commit.

Issue: #6242
  • Loading branch information
mina86 committed Mar 2, 2022
1 parent ad896e7 commit d3eb402
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
30 changes: 10 additions & 20 deletions pytest/lib/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,16 @@ def get_latest_block(self, **kw) -> BlockId:
return BlockId(height=sync_info['latest_block_height'],
hash=sync_info['latest_block_hash'])

def get_all_heights(self):
hash_ = self.get_latest_block().hash
heights = []

while True:
block = self.get_block(hash_)
if 'error' in block and 'data' in block[
'error'] and 'DB Not Found Error: BLOCK:' in block['error'][
'data']:
break
elif 'result' not in block:
logger.info(block)

height = block['result']['header']['height']
if height == 0:
break
heights.append(height)
hash_ = block['result']['header']['prev_hash']

return reversed(heights)
def get_all_blocks(self) -> typing.Sequence[BlockId]:
ids = []
black_hash = self.get_latest_block().hash
while block_hash is not None:
block = self.get_block(block_hash)
assert 'result' in block, block
header = block['result']['header']
ids.append(BlockId.from_header(header)
block_hash = header.get('prev_hash')
return reversed(ids)

def get_validators(self):
return self.json_rpc('validators', [None])
Expand Down
2 changes: 1 addition & 1 deletion pytest/tests/sanity/state_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
ctx.send_moar_txs(block_hash, 3, False)
logger.info(f'Sending moar txs at height {boot_height}')

boot_heights = boot_node.get_all_heights()
boot_heights = [block_id.height for block_id in boot_node.get_all_blocks()]

assert catch_up_height in boot_heights, "%s not in %s" % (catch_up_height,
boot_heights)
Expand Down
2 changes: 1 addition & 1 deletion pytest/tests/sanity/state_sync_late.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
ctx.send_moar_txs(hash_, 3, False)
logger.info(f'Sending moar txs at height {boot_height}')

boot_heights = boot_node.get_all_heights()
boot_heights = [block_id.height for block_id in boot_node.get_all_blocks()]

assert catch_up_height in boot_heights, "%s not in %s" % (catch_up_height,
boot_heights)
Expand Down
2 changes: 1 addition & 1 deletion pytest/tests/sanity/state_sync_routed.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
logger.info(f"Sending moar txs at height {boot_height}")
time.sleep(0.1)

boot_heights = boot_node.get_all_heights()
boot_heights = [block_id.height for block_id in boot_node.get_all_blocks()]

assert catch_up_height in boot_heights, "%s not in %s" % (catch_up_height,
boot_heights)
Expand Down

0 comments on commit d3eb402

Please sign in to comment.