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

Problem: invalid ica msg is not tested #1189

Merged
merged 2 commits into from
Sep 28, 2023
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
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