diff --git a/integration_tests/configs/ibc.jsonnet b/integration_tests/configs/ibc.jsonnet index 42ddb56ccd..579777a4b3 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: 2000000, 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..555784a34c 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( @@ -333,7 +346,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 +426,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 +471,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 +491,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}"}, ] diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index 73b624d196..abf1fdc00a 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -7,6 +7,7 @@ from .ibc_utils import ( RATIO, + RELAYER_CALLER, assert_duplicate, cronos_transfer_source_tokens, cronos_transfer_source_tokens_with_proxy, @@ -59,6 +60,8 @@ def ibc(request, tmp_path_factory): def amount_dict(amt, denom): + if amt == 0: + return [] return [ AttributeDict( { @@ -298,8 +301,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..15ca0953a3 100644 --- a/integration_tests/test_ibc_rly_gas.py +++ b/integration_tests/test_ibc_rly_gas.py @@ -23,7 +23,7 @@ def test_ibc(ibc): cli = ibc.cronos.cosmos_cli() wait_for_new_blocks(cli, 1) rly_transfer(ibc) - diff = 0.01 + diff = 0.15 record = log_gas_records(cli) if record: records.append(record) 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