Skip to content

Commit

Permalink
Problem: invalid ica msg is not tested (#1189)
Browse files Browse the repository at this point in the history
* Problem: invalid ica msg is not tested

* fix test sequence
  • Loading branch information
mmsqe authored Sep 28, 2023
1 parent 6c0ec8e commit 071bc21
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions integration_tests/contracts/contracts/TestICA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract TestICA {
enum Status {
NONE,
SUCCESS,
TIMEOUT
FAIL
}
mapping (uint64 => Status) public statusMap;
event OnPacketResult(uint64 seq, Status status);
Expand Down Expand Up @@ -105,7 +105,7 @@ contract TestICA {
function onPacketResultCallback(uint64 seq, bool ack) external payable returns (bool) {
// To prevent called by arbitrary user
require(msg.sender == module_address);
Status status = Status.TIMEOUT;
Status status = Status.FAIL;
if (ack) {
status = Status.SUCCESS;
}
Expand Down
31 changes: 26 additions & 5 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


class Status(IntEnum):
NONE, SUCCESS, TIMEOUT = range(3)
NONE, SUCCESS, FAIL = range(3)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -73,6 +73,8 @@ def submit_msgs(
is_multi,
expected_seq,
timeout=no_timeout,
amount=amt,
need_wait=True,
):
cli_host = ibc.chainmain.cosmos_cli()
cli_controller = ibc.cronos.cosmos_cli()
Expand All @@ -84,7 +86,7 @@ def submit_msgs(
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": ica_address,
"to_address": to,
"amount": [{"denom": denom, "amount": f"{amt}"}],
"amount": [{"denom": denom, "amount": f"{amount}"}],
}
]
if is_multi:
Expand Down Expand Up @@ -117,7 +119,8 @@ def submit_msgs(
for i, log in enumerate(logs):
method_name, args = get_topic_data(w3, method_map, contract_info, log)
assert args == AttributeDict(expected[i]), [i, method_name]
wait_for_check_tx(cli_host, ica_address, num_txs)
if need_wait:
wait_for_check_tx(cli_host, ica_address, num_txs)
return str


Expand Down Expand Up @@ -247,9 +250,27 @@ def submit_msgs_ro(func, str):
assert expected_seq == last_seq
assert status == Status.SUCCESS

expected_seq = 3
# balance should not change on fail
str = submit_msgs(
ibc,
tcontract.functions.callSubmitMsgs,
data,
ica_address,
False,
expected_seq,
amount=100000001,
need_wait=False,
)
last_seq = tcontract.caller.getLastSeq()
wait_for_status_change(tcontract, last_seq)
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.FAIL

# balance and seq should not change on timeout
expected_seq = 4
timeout = 300000
expected_seq = 3
str = submit_msgs(
ibc,
tcontract.functions.callSubmitMsgs,
Expand All @@ -263,4 +284,4 @@ def submit_msgs_ro(func, str):
wait_for_status_change(tcontract, last_seq)
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.TIMEOUT
assert status == Status.FAIL

0 comments on commit 071bc21

Please sign in to comment.