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: ica query not tested #1635

Merged
merged 4 commits into from
Oct 14, 2024
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
1 change: 1 addition & 0 deletions integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ config {
allow_messages: [
'/cosmos.bank.v1beta1.MsgSend',
'/cosmos.staking.v1beta1.MsgDelegate',
'/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe',
],
},
},
Expand Down
24 changes: 24 additions & 0 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import hashlib
import json
import subprocess
Expand All @@ -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
Expand Down Expand Up @@ -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)

mmsqe marked this conversation as resolved.
Show resolved Hide resolved

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)
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions integration_tests/test_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Status,
deploy_contract,
funds_ica,
gen_query_balance_packet,
gen_send_msg,
ica_send_tx,
parse_events_rpc,
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .ibc_utils import (
Status,
funds_ica,
gen_query_balance_packet,
gen_send_msg,
get_next_channel,
prepare_network,
Expand Down Expand Up @@ -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
Loading