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: latest hermes is not used in integration tests #1461

Open
wants to merge 3 commits into
base: release/v1.3.x
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config {
name: 'user' + i,
coins: '30000000000000000000000basetcro',
}
for i in std.range(1, 20)
for i in std.range(1, 50)
],
'app-config'+: {
'index-events': super['index-events'] + ['message.action'],
Expand Down Expand Up @@ -97,7 +97,7 @@ config {
name: 'user' + i,
coins: '10000000000000cro',
}
for i in std.range(1, 20)
for i in std.range(1, 50)
],
genesis: {
app_state: {
Expand Down Expand Up @@ -165,7 +165,7 @@ config {
chains: [
{
id: 'cronos_777-1',
max_gas: 1000000,
max_gas: 2500000,
gas_multiplier: 1.1,
address_type: {
derivation: 'ethermint',
Expand All @@ -174,7 +174,7 @@ config {
},
},
gas_price: {
price: 10000000000000000,
price: 10000000,
denom: 'basetcro',
},
event_source: {
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/configs/ibc_rly_evm.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local ibc = import 'ibc_rly.jsonnet';
ibc {
relayer+: {
chains: [super.chains[0] {
precompiled_contract_address: '0x0000000000000000000000000000000000000065',
precompiled_contract_address: '0x6F1805D56bF05b7be10857F376A5b1c160C8f72C',
json_rpc_address: 'http://127.0.0.1:26701',
}] + super.chains[1:],
},
Expand Down
13 changes: 13 additions & 0 deletions integration_tests/contracts/contracts/TestRelayer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract TestRelayer {
address constant relayer = 0x0000000000000000000000000000000000000065;

function batchCall(bytes[] memory payloads) public {
for (uint256 i = 0; i < payloads.length; i++) {
(bool success,) = relayer.call(payloads[i]);
require(success);
}
}
}
65 changes: 31 additions & 34 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ADDRS,
CONTRACTS,
deploy_contract,
derive_new_account,
eth_to_bech32,
parse_events,
parse_events_rpc,
Expand All @@ -25,6 +26,7 @@
)

RATIO = 10**10
RELAYER_CALLER = "0x6F1805D56bF05b7be10857F376A5b1c160C8f72C"


class Status(IntEnum):
Expand Down Expand Up @@ -171,6 +173,17 @@ def prepare_network(

version = {"fee_version": "ics29-1", "app_version": "ics20-1"}
path = cronos.base_dir.parent / "relayer"
w3 = cronos.w3
acc = derive_new_account(2)
sender = acc.address
# fund new sender to deploy contract with same address
if w3.eth.get_balance(sender, "latest") == 0:
fund = 3000000000000000000
tx = {"to": sender, "value": fund, "gasPrice": w3.eth.gas_price}
send_transaction(w3, tx)
assert w3.eth.get_balance(sender, "latest") == fund
caller = deploy_contract(w3, CONTRACTS["TestRelayer"], key=acc.key).address
assert caller == RELAYER_CALLER, caller
if is_hermes:
hermes = Hermes(path.with_suffix(".toml"))
call_hermes_cmd(
Expand Down Expand Up @@ -254,6 +267,7 @@ def rly_transfer(ibc):
f"--home {str(path)}"
)
subprocess.run(cmd, check=True, shell=True)
return src_amount


def assert_duplicate(base_port, height):
Expand Down Expand Up @@ -285,8 +299,8 @@ def find_duplicate(attributes):
return None


def ibc_transfer_with_hermes(ibc):
src_amount = hermes_transfer(ibc)
def ibc_transfer(ibc, transfer_fn=hermes_transfer):
src_amount = transfer_fn(ibc)
dst_amount = src_amount * RATIO # the decimal places difference
dst_denom = "basetcro"
dst_addr = eth_to_bech32(ADDRS["signer2"])
Expand All @@ -301,24 +315,6 @@ def check_balance_change():

wait_for_fn("balance change", check_balance_change)
assert old_dst_balance + dst_amount == new_dst_balance
# assert that the relayer transactions do enables the dynamic fee extension option.
cli = ibc.cronos.cosmos_cli()
criteria = "message.action=/ibc.core.channel.v1.MsgChannelOpenInit"
tx = cli.tx_search(criteria)["txs"][0]
events = parse_events_rpc(tx["events"])
fee = int(events["tx"]["fee"].removesuffix(dst_denom))
gas = int(tx["gas_wanted"])
# the effective fee is decided by the max_priority_fee (base fee is zero)
# rather than the normal gas price
assert fee == gas * 1000000

# check duplicate OnRecvPacket events
criteria = "message.action=/ibc.core.channel.v1.MsgRecvPacket"
tx = cli.tx_search(criteria)["txs"][0]
events = tx["logs"][1]["events"]
for event in events:
dup = find_duplicate(event["attributes"])
assert not dup, f"duplicate {dup} in {event['type']}"


def get_balance(chain, addr, denom):
Expand All @@ -333,7 +329,7 @@ def get_balances(chain, 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)]
users = [f"user{i}" for i in range(1, 51)]
addrs0 = [chains[0].address(user) for user in users]
addrs1 = [chains[1].address(user) for user in users]
denom0 = "basetcro"
Expand Down Expand Up @@ -413,10 +409,12 @@ def ibc_incentivized_transfer(ibc):
receiver = chains[1].address("signer2")
sender = chains[0].address("signer2")
relayer = chains[0].address("signer1")
relayer_caller = eth_to_bech32(RELAYER_CALLER)
amount = 1000
fee_denom = "ibcfee"
base_denom = "basetcro"
old_amt_fee = chains[0].balance(relayer, fee_denom)
old_amt_fee_caller = chains[0].balance(relayer_caller, fee_denom)
old_amt_sender_fee = chains[0].balance(sender, fee_denom)
old_amt_sender_base = chains[0].balance(sender, base_denom)
old_amt_receiver_base = chains[1].balance(receiver, "basecro")
Expand Down Expand Up @@ -456,7 +454,12 @@ def ibc_incentivized_transfer(ibc):
def check_fee():
amount = chains[0].balance(relayer, fee_denom)
if amount > old_amt_fee:
assert amount == old_amt_fee + 20
amount_caller = chains[0].balance(relayer_caller, fee_denom)
if amount_caller > 0:
assert amount_caller == old_amt_fee_caller + 10, amount_caller
assert amount == old_amt_fee + 10, amount
else:
assert amount == old_amt_fee + 20, amount
return True
else:
return False
Expand All @@ -471,17 +474,10 @@ def check_fee():
], actual
path = f"transfer/{dst_channel}/{base_denom}"
denom_hash = hashlib.sha256(path.encode()).hexdigest().upper()
assert json.loads(
chains[0].raw(
"query",
"ibc-transfer",
"denom-trace",
denom_hash,
node=ibc.chainmain.node_rpc(0),
output="json",
)
)["denom_trace"] == {"path": f"transfer/{dst_channel}", "base_denom": base_denom}
assert get_balances(ibc.chainmain, receiver) == [
denom_trace = chains[0].ibc_denom_trace(path, ibc.chainmain.node_rpc(0))
assert denom_trace == {"path": f"transfer/{dst_channel}", "base_denom": base_denom}
current = get_balances(ibc.chainmain, receiver)
assert current == [
{"denom": "basecro", "amount": f"{old_amt_receiver_base}"},
{"denom": f"ibc/{denom_hash}", "amount": f"{amount}"},
]
Expand Down Expand Up @@ -849,7 +845,8 @@ def log_gas_records(cli):
txs = cli.tx_search_rpc(criteria)
records = []
for tx in txs:
print("mm-tx", tx)
res = tx["tx_result"]
if res["gas_used"]:
records.append(res["gas_used"])
records.append(int(res["gas_used"]))
return records
33 changes: 30 additions & 3 deletions integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
assert_ready,
cronos_transfer_source_tokens,
cronos_transfer_source_tokens_with_proxy,
find_duplicate,
get_balance,
ibc_incentivized_transfer,
ibc_transfer_with_hermes,
ibc_transfer,
prepare_network,
)
from .utils import ADDRS, CONTRACTS, deploy_contract, send_transaction, wait_for_fn
from .utils import (
ADDRS,
CONTRACTS,
deploy_contract,
parse_events_rpc,
send_transaction,
wait_for_fn,
)

pytestmark = pytest.mark.ibc

Expand All @@ -28,7 +36,26 @@ def test_ibc_transfer_with_hermes(ibc):
"""
test ibc transfer tokens with hermes cli
"""
ibc_transfer_with_hermes(ibc)
ibc_transfer(ibc)
dst_denom = "basetcro"
# assert that the relayer transactions do enables the dynamic fee extension option.
cli = ibc.cronos.cosmos_cli()
criteria = "message.action=/ibc.core.channel.v1.MsgChannelOpenInit"
tx = cli.tx_search(criteria)["txs"][0]
events = parse_events_rpc(tx["events"])
fee = int(events["tx"]["fee"].removesuffix(dst_denom))
gas = int(tx["gas_wanted"])
# the effective fee is decided by the max_priority_fee (base fee is zero)
# rather than the normal gas price
assert fee == gas * 1000000

# check duplicate OnRecvPacket events
criteria = "message.action=/ibc.core.channel.v1.MsgRecvPacket"
tx = cli.tx_search(criteria)["txs"][0]
events = tx["logs"][1]["events"]
for event in events:
dup = find_duplicate(event["attributes"])
assert not dup, f"duplicate {dup} in {event['type']}"


def test_ibc_incentivized_transfer(ibc):
Expand Down
25 changes: 7 additions & 18 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@

from .ibc_utils import (
RATIO,
RELAYER_CALLER,
assert_duplicate,
cronos_transfer_source_tokens,
cronos_transfer_source_tokens_with_proxy,
get_balance,
hermes_transfer,
ibc_denom,
ibc_incentivized_transfer,
ibc_multi_transfer,
ibc_transfer,
prepare_network,
)
from .utils import (
ADDRS,
CONTRACT_ABIS,
bech32_to_eth,
eth_to_bech32,
get_logs_since,
get_method_map,
get_topic_data,
module_address,
parse_events_rpc,
wait_for_fn,
wait_for_new_blocks,
)

Expand Down Expand Up @@ -59,6 +57,8 @@ def ibc(request, tmp_path_factory):


def amount_dict(amt, denom):
if amt == 0:
return []
return [
AttributeDict(
{
Expand Down Expand Up @@ -230,19 +230,8 @@ def test_ibc(ibc):
w3 = ibc.cronos.w3
wait_for_new_blocks(ibc.cronos.cosmos_cli(), 1)
start = w3.eth.get_block_number()
hermes_transfer(ibc)
ibc_transfer(ibc)
denom = ibc_denom(channel, src_denom)
dst_addr = eth_to_bech32(cronos_signer2)
old_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom)
new_dst_balance = 0

def check_balance_change():
nonlocal new_dst_balance
new_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom)
return new_dst_balance != old_dst_balance

wait_for_fn("balance change", check_balance_change)
assert old_dst_balance + dst_amount == new_dst_balance
logs = get_logs_since(w3, CONTRACT, start)
chainmain_cli = ibc.chainmain.cosmos_cli()
relayer0 = chainmain_cli.address("relayer")
Expand Down Expand Up @@ -298,8 +287,8 @@ def test_ibc_incentivized_transfer(ibc):
acknowledge_packet(seq0),
distribute_fee(src_relayer, fee),
*send_coins(feeibc_addr, src_relayer, src_amount, fee_denom),
distribute_fee(src_relayer, fee),
*send_coins(feeibc_addr, src_relayer, src_amount, fee_denom),
distribute_fee(RELAYER_CALLER, fee),
*send_coins(feeibc_addr, RELAYER_CALLER, src_amount, fee_denom),
distribute_fee(cronos_signer2, fee),
*send_coins(feeibc_addr, cronos_signer2, src_amount, fee_denom),
fungible(checksum_dst_adr, cronos_signer2, amount, dst_denom),
Expand Down
23 changes: 15 additions & 8 deletions integration_tests/test_ibc_rly_gas.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import pytest
from pystarport import cluster

from .ibc_utils import log_gas_records, prepare_network, rly_transfer
from .ibc_utils import (
ibc_incentivized_transfer,
ibc_multi_transfer,
ibc_transfer,
log_gas_records,
prepare_network,
)
from .utils import wait_for_new_blocks

pytestmark = pytest.mark.ibc_rly_gas


@pytest.fixture(scope="module", params=["ibc_rly", "ibc_rly_evm"])
@pytest.fixture(scope="module", params=["ibc_rly_evm", "ibc_rly"])
def ibc(request, tmp_path_factory):
"prepare-network"
name = request.param
path = tmp_path_factory.mktemp(name)
yield from prepare_network(path, name, relayer=cluster.Relayer.RLY.value)
yield from prepare_network(path, name, relayer=cluster.Relayer.HERMES.value)


records = []
Expand All @@ -22,12 +28,13 @@ def test_ibc(ibc):
# chainmain-1 relayer -> cronos_777-1 signer2
cli = ibc.cronos.cosmos_cli()
wait_for_new_blocks(cli, 1)
rly_transfer(ibc)
diff = 0.01
ibc_transfer(ibc)
ibc_incentivized_transfer(ibc)
ibc_multi_transfer(ibc)
diff = 0.1
record = log_gas_records(cli)
if record:
records.append(record)
if len(records) == 2:
for e1, e2 in zip(*records):
res = float(e2) / float(e1)
assert 1 - diff <= res <= 1 + diff, res
res = float(sum(records[0]) / sum(records[1]))
assert 1 - diff <= res <= 1 + diff, res
Loading
Loading