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

feat: add wait for next block query #143

Merged
merged 1 commit into from
Sep 20, 2022
Merged
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
9 changes: 9 additions & 0 deletions nibiru/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib.metadata as importlib_metadata
import time
from typing import Generator, List, Optional, Tuple, Union

import grpc
Expand Down Expand Up @@ -120,6 +121,14 @@ def sync_timeout_height(self):
block = self.get_latest_block()
self.timeout_height = block.block.header.height + DEFAULT_TIMEOUTHEIGHT

def wait_for_next_block(self):
"""
Wait for a block to be written
"""
current_block = self.get_latest_block().block.header.height
while self.get_latest_block().block.header.height < current_block + 1:
time.sleep(0.5)

def get_block_by_height(
self, height: int
) -> tendermint_query.GetBlockByHeightResponse:
Expand Down
8 changes: 8 additions & 0 deletions tests/chain_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_get_chain_id(val_node: Sdk):
assert val_node.network.chain_id == val_node.query.get_chain_id()


def test_wait_next_block(val_node: Sdk):
current_block_height = val_node.query.get_latest_block().block.header.height
val_node.query.wait_for_next_block()
new_block_height = val_node.query.get_latest_block().block.header.height

assert new_block_height > current_block_height


def test_version_works(val_node: Sdk):
tests = [
{"should_fail": False, "versions": ["0.3.2", "0.3.2"]},
Expand Down