Skip to content

Commit

Permalink
Problem: there are flaky integration tests (#1244)
Browse files Browse the repository at this point in the history
get packet logs within range
  • Loading branch information
mmsqe authored Nov 15, 2023
1 parent cdfb5de commit 6834ef9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def check_status():
wait_for_fn("current status", check_status)


def wait_for_packet_log(event, seq, status):
def wait_for_packet_log(start, event, seq, status):
print("wait for log arrive", seq, status)
expected = AttributeDict({"seq": seq, "status": status})

def check_log():
logs = event.getLogs()
return len(logs) > 0 and logs[0].args == expected
logs = event.getLogs(fromBlock=start)
return len(logs) > 0 and logs[-1].args == expected

wait_for_fn("packet log", check_log)

Expand Down Expand Up @@ -245,6 +245,7 @@ def submit_msgs_ro(func, str):
assert send_transaction(w3, tx, keys).status == 0

expected_seq = 1
start = w3.eth.get_block_number()
str, diff = submit_msgs(
ibc,
tcontract.functions.callSubmitMsgs,
Expand All @@ -261,11 +262,12 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.SUCCESS
wait_for_packet_log(tcontract.events.OnPacketResult, last_seq, status)
wait_for_packet_log(start, tcontract.events.OnPacketResult, last_seq, status)
balance -= diff
assert cli_host.balance(ica_address, denom=denom) == balance

expected_seq += 1
start = w3.eth.get_block_number()
str, diff = submit_msgs(
ibc,
tcontract.functions.callSubmitMsgs,
Expand All @@ -282,11 +284,12 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.SUCCESS
wait_for_packet_log(tcontract.events.OnPacketResult, last_seq, status)
wait_for_packet_log(start, tcontract.events.OnPacketResult, last_seq, status)
balance -= diff
assert cli_host.balance(ica_address, denom=denom) == balance

expected_seq += 1
start = w3.eth.get_block_number()
# balance should not change on fail
submit_msgs(
ibc,
Expand All @@ -304,11 +307,12 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.FAIL
wait_for_packet_log(tcontract.events.OnPacketResult, last_seq, status)
wait_for_packet_log(start, tcontract.events.OnPacketResult, last_seq, status)
assert cli_host.balance(ica_address, denom=denom) == balance

# balance should not change on timeout
expected_seq += 1
start = w3.eth.get_block_number()
timeout = 5000000000
data["gas"] = 800000
submit_msgs(
Expand All @@ -327,7 +331,7 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.FAIL
wait_for_packet_log(tcontract.events.OnPacketResult, last_seq, status)
wait_for_packet_log(start, tcontract.events.OnPacketResult, last_seq, status)
assert cli_host.balance(ica_address, denom=denom) == balance
wait_for_check_channel_ready(cli_controller, connid, channel_id, "STATE_CLOSED")
data["gas"] = default_gas
Expand All @@ -342,6 +346,7 @@ def submit_msgs_ro(func, str):
)
assert ica_address2 == ica_address, ica_address2
expected_seq = 1
start = w3.eth.get_block_number()
str, diff = submit_msgs(
ibc,
tcontract.functions.callSubmitMsgs,
Expand All @@ -357,6 +362,6 @@ def submit_msgs_ro(func, str):
assert expected_seq == last_seq
assert status == Status.SUCCESS
# wait for ack to add log from call evm
wait_for_packet_log(tcontract.events.OnPacketResult, last_seq, status)
wait_for_packet_log(start, tcontract.events.OnPacketResult, last_seq, status)
balance -= diff
assert cli_host.balance(ica_address, denom=denom) == balance

0 comments on commit 6834ef9

Please sign in to comment.