Skip to content

Commit

Permalink
Problem: gravity bridge integration test fails occasionally (crypto-o…
Browse files Browse the repository at this point in the history
…rg-chain#49)

Closes crypto-org-chain#48

Solution:
- use better method to wait for message relaying
  • Loading branch information
yihuang authored Sep 6, 2021
1 parent 71577be commit 0b79cc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 9 additions & 7 deletions integration_tests/test_gravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
deploy_contract,
sign_validator,
supervisorctl,
wait_for_fn,
wait_for_new_blocks,
)

Expand Down Expand Up @@ -146,11 +147,12 @@ def test_gravity_transfer(gravity, suspend_capture):
geth.eth.wait_for_transaction_receipt(txhash)
assert erc20.caller.balanceOf(geth.eth.coinbase) == balance - amount

# TODO better way to wait?
time.sleep(20)

denom = "gravity" + erc20.address
assert cli.balance(cosmos_recipient, denom) == amount

def check():
return cli.balance(cosmos_recipient, denom) == amount

wait_for_fn("send-to-cosmos", check)

# send it back to erc20
print("send back to ethereum")
Expand All @@ -160,7 +162,7 @@ def test_gravity_transfer(gravity, suspend_capture):
assert rsp["code"] == 0, rsp["raw_log"]
assert cli.balance(cosmos_recipient, denom) == 0

# TODO better way to wait?
time.sleep(40)
def check():
return erc20.caller.balanceOf(geth.eth.coinbase) == balance

assert erc20.caller.balanceOf(geth.eth.coinbase) == balance
wait_for_fn("send-to-ethereum", check)
9 changes: 9 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
ADDRS = {name: eth_account.Account.from_key(key).address for name, key in KEYS.items()}


def wait_for_fn(name, fn, *, timeout=120, interval=1):
for i in range(int(timeout / interval)):
if fn():
break
time.sleep(interval)
else:
raise TimeoutError(f"wait for {name} timeout")


def wait_for_block(cli, height, timeout=240):
for i in range(timeout * 2):
try:
Expand Down

0 comments on commit 0b79cc9

Please sign in to comment.