diff --git a/integration_tests/configs/ibc.jsonnet b/integration_tests/configs/ibc.jsonnet index 42ddb56ccd..bf1ed6d92e 100644 --- a/integration_tests/configs/ibc.jsonnet +++ b/integration_tests/configs/ibc.jsonnet @@ -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'], @@ -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: { @@ -165,7 +165,7 @@ config { chains: [ { id: 'cronos_777-1', - max_gas: 1000000, + max_gas: 2500000, gas_multiplier: 1.1, address_type: { derivation: 'ethermint', @@ -174,7 +174,7 @@ config { }, }, gas_price: { - price: 10000000000000000, + price: 10000000, denom: 'basetcro', }, event_source: { diff --git a/integration_tests/configs/ibc_rly_evm.jsonnet b/integration_tests/configs/ibc_rly_evm.jsonnet index ac77fde468..6c835a91cc 100644 --- a/integration_tests/configs/ibc_rly_evm.jsonnet +++ b/integration_tests/configs/ibc_rly_evm.jsonnet @@ -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:], }, diff --git a/integration_tests/contracts/contracts/TestRelayer.sol b/integration_tests/contracts/contracts/TestRelayer.sol new file mode 100644 index 0000000000..663b02e65f --- /dev/null +++ b/integration_tests/contracts/contracts/TestRelayer.sol @@ -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); + } + } +} diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index dc4dba0a21..dbc6134ffe 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -14,6 +14,7 @@ ADDRS, CONTRACTS, deploy_contract, + derive_new_account, eth_to_bech32, parse_events, parse_events_rpc, @@ -25,6 +26,7 @@ ) RATIO = 10**10 +RELAYER_CALLER = "0x6F1805D56bF05b7be10857F376A5b1c160C8f72C" class Status(IntEnum): @@ -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( @@ -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): @@ -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"]) @@ -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): @@ -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" @@ -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") @@ -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 @@ -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}"}, ] @@ -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 diff --git a/integration_tests/test_ibc.py b/integration_tests/test_ibc.py index 31ef42df56..a65805ca36 100644 --- a/integration_tests/test_ibc.py +++ b/integration_tests/test_ibc.py @@ -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 @@ -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): diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index 73b624d196..379f3c1a2d 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -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, ) @@ -59,6 +57,8 @@ def ibc(request, tmp_path_factory): def amount_dict(amt, denom): + if amt == 0: + return [] return [ AttributeDict( { @@ -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") @@ -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), diff --git a/integration_tests/test_ibc_rly_gas.py b/integration_tests/test_ibc_rly_gas.py index fcad133e54..ce1f206895 100644 --- a/integration_tests/test_ibc_rly_gas.py +++ b/integration_tests/test_ibc_rly_gas.py @@ -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 = [] @@ -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 diff --git a/integration_tests/test_ibc_timeout.py b/integration_tests/test_ibc_timeout.py index cbd0d7adb2..ed9a3dbe79 100644 --- a/integration_tests/test_ibc_timeout.py +++ b/integration_tests/test_ibc_timeout.py @@ -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 @@ -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): diff --git a/integration_tests/test_ica_precompile.py b/integration_tests/test_ica_precompile.py index ffc799c6a7..74666b7b41 100644 --- a/integration_tests/test_ica_precompile.py +++ b/integration_tests/test_ica_precompile.py @@ -48,7 +48,7 @@ def ibc(request, tmp_path_factory): name, incentivized=False, connection_only=True, - relayer=cluster.Relayer.RLY.value, + relayer=cluster.Relayer.HERMES.value, ) @@ -230,7 +230,7 @@ def test_sc_call(ibc): assert tcontract.functions.callQueryAccount(connid, addr).call() == ica_address # register from another user should fail - name = "signer1" + name = "community" data = {"from": ADDRS[name], "gas": default_gas} version = "" tx = tcontract.functions.callRegister(connid, version).build_transaction(data) @@ -341,6 +341,10 @@ def submit_msgs_ro(func, str): timeout, msg_num=100, ) + + # FIXME https://github.com/informalsystems/hermes/issues/3695 + return + last_seq = tcontract.caller.getLastSeq() wait_for_status_change(tcontract, channel_id, last_seq) status = tcontract.caller.getStatus(channel_id, last_seq) diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 8febe73595..e150fbcac5 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -62,6 +62,7 @@ "TestBank": "TestBank.sol", "TestICA": "TestICA.sol", "Random": "Random.sol", + "TestRelayer": "TestRelayer.sol", } @@ -421,6 +422,13 @@ def cronos_address_from_mnemonics(mnemonics, prefix=CRONOS_ADDRESS_PREFIX): return eth_to_bech32(acct.address, prefix) +def derive_new_account(n=1): + # derive a new address + account_path = f"m/44'/60'/0'/0/{n}" + mnemonic = os.getenv("COMMUNITY_MNEMONIC") + return Account.from_mnemonic(mnemonic, account_path=account_path) + + def send_to_cosmos(gravity_contract, token_contract, w3, recipient, amount, key=None): """ do approve and sendToCronos on ethereum side diff --git a/nix/sources.json b/nix/sources.json index 336932e6c3..172ce84bdb 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -78,10 +78,10 @@ "homepage": "", "owner": "informalsystems", "repo": "ibc-rs", - "rev": "0181c462486b7801d4ec720aa34f34576fcf981b", - "sha256": "1mwm0ia69wlshr5m5a8vblc6zh244rrxxm7np5df74jg330nyw7z", + "rev": "0af17d7f1b808d146d352c35e2d49803fe79a422", + "sha256": "0r5ymyy6wxk1nksbl7kgp8jc362j7gzj8mix4g305wi86pv97p66", "type": "tarball", - "url": "https://github.com/devashishdxt/hermes/archive/0181c462486b7801d4ec720aa34f34576fcf981b.tar.gz", + "url": "https://github.com/devashishdxt/hermes/archive/0af17d7f1b808d146d352c35e2d49803fe79a422.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": {