Skip to content

Commit

Permalink
try cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Nov 10, 2023
1 parent e56cf41 commit 946eb32
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 44 deletions.
107 changes: 64 additions & 43 deletions integration_tests/test_ica.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

import pytest
from pystarport import cluster

from .ibc_utils import (
assert_channel_open_init,
Expand All @@ -15,70 +16,90 @@
@pytest.fixture(scope="module")
def ibc(request, tmp_path_factory):
"prepare-network"
name = "ibc"
name = "ibc_rly"
path = tmp_path_factory.mktemp(name)
yield from prepare_network(path, name, incentivized=False, connection_only=True)
yield from prepare_network(
path,
name,
incentivized=False,
connection_only=True,
relayer=cluster.Relayer.RLY.value,
)


def test_ica(ibc, tmp_path):
connid = "connection-0"
cli_host = ibc.chainmain.cosmos_cli()
cli_controller = ibc.cronos.cosmos_cli()

print("register ica account")
rsp = cli_controller.icaauth_register_account(
connid, from_="signer2", gas="400000", fees="100000000basetcro"
)
_, channel_id = assert_channel_open_init(rsp)
wait_for_check_channel_ready(cli_controller, connid, channel_id)
def register_acc():
print("register ica account")
rsp = cli_controller.icaauth_register_account(
connid, from_="signer2", gas="400000", fees="100000000basetcro"
)
_, channel_id = assert_channel_open_init(rsp)
wait_for_check_channel_ready(cli_controller, connid, channel_id)

print("query ica account")
ica_address = cli_controller.ica_query_account(
connid, cli_controller.address("signer2")
)["interchain_account_address"]
print("ica address", ica_address)
print("query ica account")
ica_address = cli_controller.ica_query_account(
connid, cli_controller.address("signer2")
)["interchain_account_address"]
print("ica address", ica_address, "channel_id", channel_id)
return ica_address, channel_id

ica_address, channel_id = register_acc()
balance = funds_ica(cli_host, ica_address)
num_txs = len(cli_host.query_all_txs(ica_address)["txs"])

# generate a transaction to send to host chain
generated_tx = tmp_path / "generated_tx.txt"
to = cli_host.address("signer2")
amount = 1000
denom = "basecro"
# generate msgs send to host chain
m = gen_send_msg(ica_address, to, denom, amount)
msgs = []
for i in range(2):
msgs.append(m)
balance -= amount
fee = {"denom": "basetcro", "amount": "20000000000000000"}
generated_tx_msg = {
"body": {
"messages": msgs,
},
"auth_info": {
"fee": {
"amount": [fee],
"gas_limit": "200000",

def generated_tx_txt(msg_num):
# generate a transaction to send to host chain
generated_tx = tmp_path / "generated_tx.txt"
# generate msgs send to host chain
m = gen_send_msg(ica_address, to, denom, amount)
msgs = []
for i in range(msg_num):
msgs.append(m)
fee = {"denom": "basetcro", "amount": "42000000000000000"}
generated_tx_msg = {
"body": {
"messages": msgs,
},
},
}
generated_tx.write_text(json.dumps(generated_tx_msg))
"auth_info": {
"fee": {
"amount": [fee],
"gas_limit": "300000",
},
},
}
generated_tx.write_text(json.dumps(generated_tx_msg))
return generated_tx

# submit transaction on host chain on behalf of interchain account
rsp = cli_controller.icaauth_submit_tx(
connid,
generated_tx,
timeout_duration="2h",
generated_tx_txt(140),
timeout_duration="5s",
gas="600000",
from_="signer2",
)
assert rsp["code"] == 0, rsp["raw_log"]
packet_seq = next(
int(evt["attributes"][4]["value"])
for evt in rsp["events"]
if evt["type"] == "send_packet"
print("mm-rsp", rsp["code"], rsp["gas_used"])
wait_for_check_tx(cli_host, ica_address, num_txs, 8)
assert cli_host.balance(ica_address, denom=denom) == balance
wait_for_check_channel_ready(cli_controller, connid, channel_id, "STATE_CLOSED")
ica_address2, channel_id2 = register_acc()
assert ica_address2 == ica_address, ica_address2
assert channel_id2 != channel_id, channel_id2
msg_num = 2
rsp = cli_controller.icaauth_submit_tx(
connid,
generated_tx_txt(msg_num),
timeout_duration="1h",
from_="signer2",
)
print("packet sequence", packet_seq)
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_check_tx(cli_host, ica_address, num_txs)
# check if the funds are reduced in interchain account
assert cli_host.balance(ica_address, denom=denom) == balance
assert cli_host.balance(ica_address, denom=denom) == balance - amount * msg_num
2 changes: 1 addition & 1 deletion scripts/run-integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cd ../integration_tests/contracts
HUSKY_SKIP_INSTALL=1 npm install
npm run typechain
cd ..
nix-shell --run "pytest -v -s test_ica_precompile.py::test_sc_call"
nix-shell --run "pytest -v -s test_ica.py"

0 comments on commit 946eb32

Please sign in to comment.