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: multi ibc transfer is not tested #1359

Merged
merged 3 commits into from
Mar 21, 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
14 changes: 13 additions & 1 deletion integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ config {
key_name: 'signer1',
accounts: super.accounts[:std.length(super.accounts) - 1] + [super.accounts[std.length(super.accounts) - 1] {
coins: super.coins + ',100000000000ibcfee',
}],
}] + [
{
name: 'user' + i,
coins: '30000000000000000000000basetcro',
}
for i in std.range(1, 20)
],
'app-config'+: {
'index-events': super['index-events'] + ['message.action'],
},
Expand Down Expand Up @@ -76,6 +82,12 @@ config {
coins: '10000000000000cro',
mnemonic: '${SIGNER2_MNEMONIC}',
},
] + [
{
name: 'user' + i,
coins: '10000000000000cro',
}
for i in std.range(1, 20)
],
genesis: {
app_state: {
Expand Down
20 changes: 19 additions & 1 deletion integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,14 @@ def ibc_transfer(
amount,
channel, # src channel
target_version, # chain version number of target chain
event_query_tx_for=False,
**kwargs,
):
default_kwargs = {
"home": self.data_dir,
"broadcast_mode": "sync",
}
return json.loads(
rsp = json.loads(
self.raw(
"tx",
"ibc-transfer",
Expand All @@ -864,6 +866,9 @@ def ibc_transfer(
**(default_kwargs | kwargs),
)
)
if rsp["code"] == 0 and event_query_tx_for:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def ibc_escrow_address(self, port, channel):
res = self.raw(
Expand All @@ -877,6 +882,19 @@ def ibc_escrow_address(self, port, channel):
).decode("utf-8")
return re.sub(r"\n", "", res)

def ibc_denom_trace(self, path, node):
denom_hash = hashlib.sha256(path.encode()).hexdigest().upper()
return json.loads(
self.raw(
"query",
"ibc-transfer",
"denom-trace",
denom_hash,
node=node,
output="json",
)
)["denom_trace"]

mmsqe marked this conversation as resolved.
Show resolved Hide resolved
def export(self):
return self.raw("export", home=self.data_dir)

Expand Down
77 changes: 77 additions & 0 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,83 @@ def get_balances(chain, addr):
return chain.cosmos_cli().balances(addr)


def ibc_multi_transfer(ibc):
chains = [ibc.cronos.cosmos_cli(), ibc.chainmain.cosmos_cli()]
users = [f"user{i}" for i in range(1, 21)]
addrs0 = [chains[0].address(user) for user in users]
addrs1 = [chains[1].address(user) for user in users]
denom0 = "basetcro"
denom1 = "basecro"
channel0 = "channel-0"
channel1 = "channel-0"
old_balance0 = 30000000000000000000000
old_balance1 = 1000000000000000000000
path = f"transfer/{channel1}/{denom0}"
denom_hash = hashlib.sha256(path.encode()).hexdigest().upper()
amount = 1000
expected = [
{"denom": denom1, "amount": f"{old_balance1}"},
{"denom": f"ibc/{denom_hash}", "amount": f"{amount}"},
]

for i, _ in enumerate(users):
rsp = chains[0].ibc_transfer(
addrs0[i],
addrs1[i],
f"{amount}{denom0}",
channel0,
1,
fees=f"1000{denom1}",
event_query_tx_for=True,
)
assert rsp["code"] == 0, rsp["raw_log"]
balance = chains[1].balance(addrs1[i], denom1)
assert balance == old_balance1, balance
balance = chains[0].balance(addrs0[i], denom0)
assert balance == old_balance0 - amount, balance

def assert_trace_balance(addr):
balance = chains[1].balances(addr)
if len(balance) > 1:
assert balance == expected, balance
return True
else:
return False

denom_trace = chains[0].ibc_denom_trace(path, ibc.chainmain.node_rpc(0))
assert denom_trace == {"path": f"transfer/{channel1}", "base_denom": denom0}
for i, _ in enumerate(users):
wait_for_fn("assert balance", lambda: assert_trace_balance(addrs1[i]))

# chainmain-1 -> cronos_777-1
amt = amount // 2

def assert_balance(addr):
balance = chains[0].balance(addr, denom0)
if balance > old_balance0 - amount:
assert balance == old_balance0 - amt, balance
return True
else:
return False

for _ in range(0, 2):
for i, _ in enumerate(users):
rsp = chains[1].ibc_transfer(
addrs1[i],
addrs0[i],
f"{amt}ibc/{denom_hash}",
channel1,
1,
fees=f"100000000{denom1}",
)
assert rsp["code"] == 0, rsp["raw_log"]

for i, _ in enumerate(users):
wait_for_fn("assert balance", lambda: assert_balance(addrs0[i]))

old_balance0 += amt


mmsqe marked this conversation as resolved.
Show resolved Hide resolved
def ibc_incentivized_transfer(ibc):
chains = [ibc.cronos.cosmos_cli(), ibc.chainmain.cosmos_cli()]
receiver = chains[1].address("signer2")
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
hermes_transfer,
ibc_denom,
ibc_incentivized_transfer,
ibc_multi_transfer,
prepare_network,
)
from .utils import (
Expand Down Expand Up @@ -368,3 +369,7 @@ def test_cronos_transfer_source_tokens(ibc):

def test_cronos_transfer_source_tokens_with_proxy(ibc):
assert_transfer_source_tokens_topics(ibc, cronos_transfer_source_tokens_with_proxy)


def test_ibc_multi(ibc):
ibc_multi_transfer(ibc)
2 changes: 1 addition & 1 deletion scripts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export SIGNER1_MNEMONIC="shed crumble dismiss loyal latin million oblige gesture
export SIGNER2_MNEMONIC="night renew tonight dinner shaft scheme domain oppose echo summer broccoli agent face guitar surface belt veteran siren poem alcohol menu custom crunch index"
export SIGNER3_MNEMONIC="step endless survey brand topic warrior merry boat metal throw tag recycle pitch animal drill jar hero library arm swift kitten proof acoustic chef"
export CRONOS_ADMIN="crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp"
export IBC_CRO_DENOM="ibc/6411AE2ADA1E73DB59DB151A8988F9B7D5E7E233D8414DB6817F8F1A01611F86"
export IBC_CRO_DENOM="ibc/6411AE2ADA1E73DB59DB151A8988F9B7D5E7E233D8414DB6817F8F1A01611F86"
Loading