Skip to content

Commit

Permalink
Problem: batch call precompile is not tested (crypto-org-chain#1360)
Browse files Browse the repository at this point in the history
* cleanup

* Problem: batch call precompile is not tested

fix test

* update deps
  • Loading branch information
mmsqe committed May 29, 2024
1 parent 2995948 commit 730cf08
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
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: 2000000,
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);
}
}
}
39 changes: 26 additions & 13 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 @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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}"},
]
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .ibc_utils import (
RATIO,
RELAYER_CALLER,
assert_duplicate,
cronos_transfer_source_tokens,
cronos_transfer_source_tokens_with_proxy,
Expand Down Expand Up @@ -59,6 +60,8 @@ def ibc(request, tmp_path_factory):


def amount_dict(amt, denom):
if amt == 0:
return []
return [
AttributeDict(
{
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_ibc_rly_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"TestBank": "TestBank.sol",
"TestICA": "TestICA.sol",
"Random": "Random.sol",
"TestRelayer": "TestRelayer.sol",
}


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 730cf08

Please sign in to comment.