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 2 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
16 changes: 15 additions & 1 deletion integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ 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',
mnemonic: '${USER' + i + '_MNEMONIC}',
yihuang marked this conversation as resolved.
Show resolved Hide resolved
}
for i in std.range(1, 20)
],
'app-config'+: {
'index-events': super['index-events'] + ['message.action'],
},
Expand Down Expand Up @@ -76,6 +83,13 @@ config {
coins: '10000000000000cro',
mnemonic: '${SIGNER2_MNEMONIC}',
},
] + [
{
name: 'user' + i,
coins: '10000000000000cro',
mnemonic: '${USER' + i + '_MNEMONIC}',
}
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)
20 changes: 20 additions & 0 deletions scripts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ export SIGNER2_MNEMONIC="night renew tonight dinner shaft scheme domain oppose e
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 USER1_MNEMONIC="ill hawk retreat wedding lobster decide recall public panel hint news snack excuse major glass obvious mad balance beef firm shiver century mean access"
yihuang marked this conversation as resolved.
Show resolved Hide resolved
export USER2_MNEMONIC="erupt maximum tube stomach crystal mirror luxury roof gift glow pottery grape advance unaware total stage blouse short yellow donkey galaxy hedgehog mushroom render"
export USER3_MNEMONIC="quit crush inherit magic tree rookie steel lemon junior need another immune brief genius series raccoon fringe immense view open bomb fancy hammer effort"
export USER4_MNEMONIC="topic elegant hero arena farm find step before clarify accident manage poem suffer actual winner legend gauge trap express problem obscure crucial crop knock"
export USER5_MNEMONIC="trip glory pet mention level mistake obey engage baby mountain culture lizard arrest rely bind liar honey host wink snow run artefact foot edit"
export USER6_MNEMONIC="mask ball border unaware much sketch feel cement neck impulse sun tower miss fetch shield horror shed blame bargain ride unlock weapon fold favorite"
export USER7_MNEMONIC="execute skull truth tattoo whale avoid proud print horse coin upgrade pig scatter federal token hour define verb inherit flee grit thunder town victory"
export USER8_MNEMONIC="fee endless venture glimpse fresh salad hard scrap magic state arrow color praise city noodle auto kind art promote rebel flat glove hard muffin"
export USER9_MNEMONIC="sign night wish check satoshi together husband boy gospel discover inch wealth magnet increase chalk mom begin deny found casino busy shiver letter either"
export USER10_MNEMONIC="this satoshi juice squirrel chair must shed useless pistol duty tray use annual frame game hour old sing anger discover arch mixed abuse few"
export USER11_MNEMONIC="portion found fancy solve team ill hidden scheme unaware next toward icon piano dinner hen access alter verb twin medal team dumb ball lamp"
export USER12_MNEMONIC="appear ship nation try twice smoke expose sand spirit burden bubble betray pulp coral receive civil case subway smoke foil rival horn dove myth"
export USER13_MNEMONIC="rebel fabric infant purpose toss boring crucial bone decorate input travel orphan whale rely holiday cloth split heavy soft flight unusual paddle play okay"
export USER14_MNEMONIC="keen solve version impulse wash coil mandate enrich devote one gaze cruise observe pass hospital empty stumble clip bench sock solid boost drama pluck"
export USER15_MNEMONIC="rather moon angry badge blast panic various couch roof loan infant bunker coin ahead junior hint rubber clever obvious tornado insect student trap case"
export USER16_MNEMONIC="meat crucial beauty build major shrimp tired example helmet heart account veteran innocent early gather audit wire dutch wisdom reward cube solar media canal"
export USER17_MNEMONIC="twenty author boil minor swap super once run push vibrant tower retire rain trigger indicate source armor trumpet long profit monkey bounce spell trend"
export USER18_MNEMONIC="sausage draw subway spike mix thumb begin pair inspire great squirrel tragic lazy slender bachelor pause oak celery glory feature shallow slide vendor lyrics"
export USER19_MNEMONIC="detect surprise oval quote unaware buyer ivory right maple cricket picnic unfair grab sting weather hair erosion course kiss wing ladder sure media season"
export USER20_MNEMONIC="dizzy patrol weird scatter rally furnace scatter pear smart clutch domain can tuition faculty clock friend build doctor emotion milk urge can message mix"
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
Loading