diff --git a/integration_tests/configs/ibc.jsonnet b/integration_tests/configs/ibc.jsonnet index 22a029c3b6..09e2b05359 100644 --- a/integration_tests/configs/ibc.jsonnet +++ b/integration_tests/configs/ibc.jsonnet @@ -111,6 +111,7 @@ config { allow_messages: [ '/cosmos.bank.v1beta1.MsgSend', '/cosmos.staking.v1beta1.MsgDelegate', + '/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe', ], }, }, diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index bbc0579cf1..bd88269006 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -1,3 +1,4 @@ +import base64 import hashlib import json import subprocess @@ -7,6 +8,7 @@ from typing import NamedTuple import requests +from cprotobuf import Field, ProtoEntity from pystarport import cluster, ports from .network import Chainmain, Cronos, Hermes, setup_custom_cronos @@ -869,3 +871,25 @@ def log_gas_records(cli): if res["gas_used"]: records.append(int(res["gas_used"])) return records + + +class QueryBalanceRequest(ProtoEntity): + address = Field("string", 1) + denom = Field("string", 2) + + +def gen_query_balance_packet(cli, ica_address): + query = QueryBalanceRequest(address=ica_address, denom="basecro") + data = json.dumps( + { + "@type": "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe", + "signer": ica_address, + "requests": [ + { + "path": "/cosmos.bank.v1beta1.Query/Balance", + "data": base64.b64encode(query.SerializeToString()).decode(), + } + ], + } + ) + return cli.ica_generate_packet_data(data) diff --git a/integration_tests/test_ica.py b/integration_tests/test_ica.py index 5c58cfeea3..768091dcbc 100644 --- a/integration_tests/test_ica.py +++ b/integration_tests/test_ica.py @@ -9,6 +9,7 @@ Status, deploy_contract, funds_ica, + gen_query_balance_packet, gen_send_msg, ica_send_tx, parse_events_rpc, @@ -164,3 +165,17 @@ def submit_msgs(msg_num, timeout_in_s=no_timeout, gas="200000"): balance -= amount * msg_num # check if the funds are reduced in interchain account assert cli_host.balance(ica_address, denom=denom) == balance + call_module_safe_query(cli_controller, connid, signer, ica_address) + + +def call_module_safe_query(cli, connid, signer, ica_address): + packet = gen_query_balance_packet(cli, ica_address) + timeout = 60 # in seconds + rsp = cli.ica_send_tx( + connid, + json.dumps(packet), + timeout_in_ns=int(timeout * 1e9), + gas=200000, + from_=signer, + ) + assert rsp["code"] == 0, rsp diff --git a/integration_tests/test_ica_precompile.py b/integration_tests/test_ica_precompile.py index bc8a0d3a92..bd88dae6dd 100644 --- a/integration_tests/test_ica_precompile.py +++ b/integration_tests/test_ica_precompile.py @@ -10,6 +10,7 @@ from .ibc_utils import ( Status, funds_ica, + gen_query_balance_packet, gen_send_msg, get_next_channel, prepare_network, @@ -448,3 +449,11 @@ def submit_msgs_ro(func, str): wait_for_packet_log(start, packet_event, channel_id2, last_seq, status) balance -= diff assert cli_host.balance(ica_address, denom=denom) == balance + + packet = gen_query_balance_packet(cli_controller, ica_address) + str = base64.b64decode(packet["data"]) + tx = tcontract.functions.callSubmitMsgs( + connid, channel_id, str, no_timeout + ).build_transaction(data) + receipt = send_transaction(w3, tx, KEYS[signer]) + assert receipt.status == 1