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 #1462

Merged
merged 2 commits into from
Jun 11, 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
4 changes: 2 additions & 2 deletions integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ config {
chains: [
{
id: 'cronos_777-1',
max_gas: 1000000,
max_gas: 2500000,
gas_multiplier: 1.1,
address_type: {
derivation: 'ethermint',
Expand All @@ -158,7 +158,7 @@ config {
},
},
gas_price: {
price: 10000000000000000,
price: 10000000,
denom: 'basetcro',
},
event_source: {
Expand Down
27 changes: 5 additions & 22 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def call_rly_cmd(path, connection_only, version, hostchain="chainmain-1"):
"rly",
"pth",
"new",
hostchain,
"cronos_777-1",
hostchain,
"chainmain-cronos",
"--home",
str(path),
Expand Down Expand Up @@ -267,6 +267,7 @@ def rly_transfer(ibc):
f"--home {str(path)}"
)
subprocess.run(cmd, check=True, shell=True)
return src_amount
mmsqe marked this conversation as resolved.
Show resolved Hide resolved


def assert_duplicate(base_port, height):
Expand Down Expand Up @@ -298,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 @@ -314,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["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 Down Expand Up @@ -871,5 +854,5 @@ def log_gas_records(cli):
for tx in txs:
res = tx["tx_result"]
if res["gas_used"]:
records.append(res["gas_used"])
records.append(int(res["gas_used"]))
return records
35 changes: 31 additions & 4 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 @@ -24,11 +32,30 @@ def ibc(request, tmp_path_factory):
yield from prepare_network(path, name, incentivized=incentivized)


def test_ibc_transfer_with_hermes(ibc):
def test_ibc_transfer(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["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
20 changes: 3 additions & 17 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@
assert_duplicate,
cronos_transfer_source_tokens,
cronos_transfer_source_tokens_with_proxy,
get_balance,
ibc_denom,
ibc_incentivized_transfer,
ibc_multi_transfer,
ibc_transfer,
prepare_network,
rly_transfer,
)
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 All @@ -55,7 +52,7 @@ def ibc(request, tmp_path_factory):
yield from prepare_network(
path,
name,
relayer=cluster.Relayer.RLY.value,
relayer=cluster.Relayer.HERMES.value,
)


Expand Down Expand Up @@ -233,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()
rly_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
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.15
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
26 changes: 3 additions & 23 deletions integration_tests/test_ibc_timeout.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import pytest

from .ibc_utils import (
RATIO,
assert_ready,
get_balance,
hermes_transfer,
prepare_network,
)
from .utils import ADDRS, eth_to_bech32, wait_for_fn
from .ibc_utils import RATIO, assert_ready, get_balance, ibc_transfer, prepare_network
from .utils import wait_for_fn

pytestmark = pytest.mark.ibc_timeout

Expand All @@ -21,21 +15,7 @@ def ibc(request, tmp_path_factory):


def test_ibc(ibc):
src_amount = hermes_transfer(ibc)
dst_amount = src_amount * RATIO # the decimal places difference
dst_denom = "basetcro"
dst_addr = eth_to_bech32(ADDRS["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
ibc_transfer(ibc)


def test_cronos_transfer_timeout(ibc):
Expand Down
3 changes: 3 additions & 0 deletions nix/hermes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rustPlatform.buildRustPackage rec {
];
cargoLock = {
lockFile = "${src}/Cargo.lock";
outputHashes = {
"ibc-proto-0.46.0" = "sha256-3rNlmu5jN5eRICynnT+Vib0PrlJOuaJnwbaTYJdX8/8=";
};
};
doCheck = false;
RUSTFLAGS = "--cfg ossl111 --cfg ossl110 --cfg ossl101";
Expand Down
6 changes: 3 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"homepage": "",
"owner": "informalsystems",
"repo": "ibc-rs",
"rev": "a026d661a74b93ffdefdc9f431007b1a6b4e95d0",
"sha256": "134h0s80laifd0ln1lx9ljcmq8pxpi5s7xmf1q5bz1mrrwmpmk9q",
"rev": "d54d0dcfc4fe0aaccf83e4c785538fac5af06d15",
"sha256": "13pfnjh2a5vjhgl7fnaw4gvr2qchp6a9yy2g3ln6rsasgp8qvpn0",
"type": "tarball",
"url": "https://github.com/informalsystems/hermes/archive/a026d661a74b93ffdefdc9f431007b1a6b4e95d0.tar.gz",
"url": "https://github.com/devashishdxt/hermes/archive/d54d0dcfc4fe0aaccf83e4c785538fac5af06d15.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
Expand Down
Loading