Skip to content

Commit 18c337a

Browse files
yihuangmmsqe
andauthored
Problem: ica query not tested (#1635)
* Problem: ica query not tested Solution: - test module safe query * fix query * test sc * Update integration_tests/ibc_utils.py Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]> Co-authored-by: mmsqe <[email protected]>
1 parent fb902d2 commit 18c337a

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

integration_tests/configs/ibc.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ config {
111111
allow_messages: [
112112
'/cosmos.bank.v1beta1.MsgSend',
113113
'/cosmos.staking.v1beta1.MsgDelegate',
114+
'/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe',
114115
],
115116
},
116117
},

integration_tests/ibc_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import hashlib
23
import json
34
import subprocess
@@ -7,6 +8,7 @@
78
from typing import NamedTuple
89

910
import requests
11+
from cprotobuf import Field, ProtoEntity
1012
from pystarport import cluster, ports
1113

1214
from .network import Chainmain, Cronos, Hermes, setup_custom_cronos
@@ -869,3 +871,25 @@ def log_gas_records(cli):
869871
if res["gas_used"]:
870872
records.append(int(res["gas_used"]))
871873
return records
874+
875+
876+
class QueryBalanceRequest(ProtoEntity):
877+
address = Field("string", 1)
878+
denom = Field("string", 2)
879+
880+
881+
def gen_query_balance_packet(cli, ica_address):
882+
query = QueryBalanceRequest(address=ica_address, denom="basecro")
883+
data = json.dumps(
884+
{
885+
"@type": "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe",
886+
"signer": ica_address,
887+
"requests": [
888+
{
889+
"path": "/cosmos.bank.v1beta1.Query/Balance",
890+
"data": base64.b64encode(query.SerializeToString()).decode(),
891+
}
892+
],
893+
}
894+
)
895+
return cli.ica_generate_packet_data(data)

integration_tests/test_ica.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Status,
1010
deploy_contract,
1111
funds_ica,
12+
gen_query_balance_packet,
1213
gen_send_msg,
1314
ica_send_tx,
1415
parse_events_rpc,
@@ -164,3 +165,17 @@ def submit_msgs(msg_num, timeout_in_s=no_timeout, gas="200000"):
164165
balance -= amount * msg_num
165166
# check if the funds are reduced in interchain account
166167
assert cli_host.balance(ica_address, denom=denom) == balance
168+
call_module_safe_query(cli_controller, connid, signer, ica_address)
169+
170+
171+
def call_module_safe_query(cli, connid, signer, ica_address):
172+
packet = gen_query_balance_packet(cli, ica_address)
173+
timeout = 60 # in seconds
174+
rsp = cli.ica_send_tx(
175+
connid,
176+
json.dumps(packet),
177+
timeout_in_ns=int(timeout * 1e9),
178+
gas=200000,
179+
from_=signer,
180+
)
181+
assert rsp["code"] == 0, rsp

integration_tests/test_ica_precompile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .ibc_utils import (
1111
Status,
1212
funds_ica,
13+
gen_query_balance_packet,
1314
gen_send_msg,
1415
get_next_channel,
1516
prepare_network,
@@ -448,3 +449,11 @@ def submit_msgs_ro(func, str):
448449
wait_for_packet_log(start, packet_event, channel_id2, last_seq, status)
449450
balance -= diff
450451
assert cli_host.balance(ica_address, denom=denom) == balance
452+
453+
packet = gen_query_balance_packet(cli_controller, ica_address)
454+
str = base64.b64decode(packet["data"])
455+
tx = tcontract.functions.callSubmitMsgs(
456+
connid, channel_id, str, no_timeout
457+
).build_transaction(data)
458+
receipt = send_transaction(w3, tx, KEYS[signer])
459+
assert receipt.status == 1

0 commit comments

Comments
 (0)