Skip to content

Commit

Permalink
Merge branch 'main' into underlying_app_success
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Oct 14, 2024
2 parents ea0868b + 18c337a commit cdec1dd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
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)


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)
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 @@ -469,3 +470,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

0 comments on commit cdec1dd

Please sign in to comment.