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 incentivized is not tested #1355

Merged
merged 2 commits into from
Mar 18, 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
37 changes: 37 additions & 0 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,43 @@ def gen_send_msg(sender, receiver, denom, amount):
}


def ica_ctrl_send_tx(
cli_host,
cli_controller,
connid,
ica_address,
msg_num,
receiver,
denom,
amount,
memo=None,
incentivized_cb=None,
**kwargs,
):
num_txs = len(cli_host.query_all_txs(ica_address)["txs"])
# generate a transaction to send to host chain
m = gen_send_msg(ica_address, receiver, denom, amount)
msgs = []
for i in range(msg_num):
msgs.append(m)
data = json.dumps(msgs)
packet = cli_controller.ica_generate_packet_data(data, json.dumps(memo))
# submit transaction on host chain on behalf of interchain account
rsp = cli_controller.ica_ctrl_send_tx(
connid,
json.dumps(packet),
from_="signer2",
**kwargs,
)
assert rsp["code"] == 0, rsp["raw_log"]
events = parse_events_rpc(rsp["events"])
seq = int(events.get("send_packet")["packet_sequence"])
if incentivized_cb:
incentivized_cb(seq)
wait_for_check_tx(cli_host, ica_address, num_txs)
return seq
mmsqe marked this conversation as resolved.
Show resolved Hide resolved


def log_gas_records(cli):
criteria = "tx.height >= 0"
txs = cli.tx_search_rpc(criteria)
Expand Down
42 changes: 13 additions & 29 deletions integration_tests/test_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
deploy_contract,
funds_ica,
gen_send_msg,
ica_ctrl_send_tx,
parse_events_rpc,
prepare_network,
register_acc,
Expand Down Expand Up @@ -45,39 +46,22 @@ def test_ica(ibc, tmp_path):
denom = "basecro"
jsonfile = CONTRACTS["TestICA"]
tcontract = deploy_contract(ibc.cronos.w3, jsonfile)
memo = {"src_callback": {"address": tcontract.address}}
timeout_in_ns = 6000000000
seq = 1

def generated_tx_packet(msg_num):
# generate a transaction to send to host chain
m = gen_send_msg(ica_address, to, denom, amount)
msgs = []
for i in range(msg_num):
msgs.append(m)
data = json.dumps(msgs)
packet = cli_controller.ica_generate_packet_data(data, json.dumps(memo))
return packet

def send_tx(msg_num, gas="200000"):
num_txs = len(cli_host.query_all_txs(ica_address)["txs"])
generated_tx = json.dumps(generated_tx_packet(msg_num))
# submit transaction on host chain on behalf of interchain account
rsp = cli_controller.ica_ctrl_send_tx(
connid,
generated_tx,
timeout_in_ns,
gas=gas,
from_="signer2",
)
assert rsp["code"] == 0, rsp["raw_log"]
events = parse_events_rpc(rsp["events"])
assert int(events.get("send_packet")["packet_sequence"]) == seq
wait_for_check_tx(cli_host, ica_address, num_txs)

msg_num = 10
assert tcontract.caller.getStatus(channel_id, seq) == Status.PENDING
send_tx(msg_num)
res = ica_ctrl_send_tx(
cli_host,
cli_controller,
connid,
ica_address,
msg_num,
to,
denom,
amount,
memo={"src_callback": {"address": tcontract.address}},
)
assert res == seq, res
balance -= amount * msg_num
assert cli_host.balance(ica_address, denom=denom) == balance
wait_for_status_change(tcontract, channel_id, seq, timeout_in_ns / 1e9)
Expand Down
99 changes: 99 additions & 0 deletions integration_tests/test_ica_incentivized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import time

import pytest

from .ibc_utils import (
funds_ica,
get_balance,
ica_ctrl_send_tx,
prepare_network,
register_acc,
)
from .utils import wait_for_fn

pytestmark = pytest.mark.ica


@pytest.fixture(scope="module")
def ibc(request, tmp_path_factory):
"prepare-network"
name = "ibc"
path = tmp_path_factory.mktemp(name)
yield from prepare_network(path, name)


def test_incentivized(ibc):
connid = "connection-0"
cli_host = ibc.chainmain.cosmos_cli()
cli_controller = ibc.cronos.cosmos_cli()
ica_address, channel_id = register_acc(cli_controller, connid)
relayer = cli_controller.address("signer1")
balance = funds_ica(cli_host, ica_address)
ibc.cronos.supervisorctl("stop", "relayer-demo")
time.sleep(3)
port_id = "icahost"
rsp = cli_host.register_counterparty_payee(
port_id,
channel_id,
cli_host.address("relayer"),
relayer,
from_="relayer",
fees="100000000basecro",
)
assert rsp["code"] == 0, rsp["raw_log"]
ibc.cronos.supervisorctl("start", "relayer-demo")
to = cli_host.address("signer2")
amount = 1000
denom = "basecro"
sender = cli_controller.address("signer2")
fee_denom = "ibcfee"
old_amt_fee = cli_controller.balance(relayer, fee_denom)
old_amt_sender_fee = cli_controller.balance(sender, fee_denom)
msg_num = 2
fee = f"10{fee_denom}"

def incentivized_cb(seq):
rsp = cli_controller.pay_packet_fee(
f"icacontroller-{sender}",
channel_id,
seq,
recv_fee=fee,
ack_fee=fee,
timeout_fee=fee,
from_=sender,
)
assert rsp["code"] == 0, rsp["raw_log"]

ica_ctrl_send_tx(
cli_host,
cli_controller,
connid,
ica_address,
msg_num,
to,
denom,
amount,
fees="0basecro",
incentivized_cb=incentivized_cb,
)
balance -= amount * msg_num

# fee is locked
assert cli_controller.balance(sender, fee_denom) == old_amt_sender_fee - 30
# check if the funds are reduced in interchain account
assert cli_host.balance(ica_address, denom=denom) == balance

# wait for relayer receive the fee
def check_fee():
amount = cli_controller.balance(relayer, fee_denom)
if amount > old_amt_fee:
assert amount == old_amt_fee + 20
return True
else:
return False

wait_for_fn("wait for relayer to receive the fee", check_fee)

# timeout fee is refunded
actual = get_balance(ibc.cronos, sender, fee_denom)
assert actual == old_amt_sender_fee - 20, actual
Loading