Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest: extend get_all_heights to return hashes as well #6369

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
block_hash = self.get_latest_block().hash
while block_hash != '11111111111111111111111111111111':
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