Skip to content

Commit

Permalink
Problem: batch call precompile is not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Mar 22, 2024
1 parent a7b3cc1 commit ce95382
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
4 changes: 2 additions & 2 deletions integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config {
name: 'user' + i,
coins: '30000000000000000000000basetcro',
}
for i in std.range(1, 20)
for i in std.range(1, 2)
],
'app-config'+: {
'index-events': super['index-events'] + ['message.action'],
Expand Down Expand Up @@ -87,7 +87,7 @@ config {
name: 'user' + i,
coins: '10000000000000cro',
}
for i in std.range(1, 20)
for i in std.range(1, 2)
],
genesis: {
app_state: {
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);
}
}
}
16 changes: 14 additions & 2 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 Down Expand Up @@ -180,6 +181,17 @@ def prepare_network(
version,
)
else:
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 == "0x6F1805D56bF05b7be10857F376A5b1c160C8f72C", caller
call_rly_cmd(path, connection_only, version)

if incentivized:
Expand Down Expand Up @@ -333,7 +345,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, 3)]
addrs0 = [chains[0].address(user) for user in users]
addrs1 = [chains[1].address(user) for user in users]
denom0 = "basetcro"
Expand Down Expand Up @@ -456,7 +468,7 @@ 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
assert amount == old_amt_fee + 20, amount
return True
else:
return False
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
cronos_transfer_source_tokens,
cronos_transfer_source_tokens_with_proxy,
get_balance,
hermes_transfer,
ibc_denom,
ibc_incentivized_transfer,
ibc_multi_transfer,
prepare_network,
rly_transfer,
)
from .utils import (
ADDRS,
Expand Down Expand Up @@ -54,7 +54,7 @@ def ibc(request, tmp_path_factory):
yield from prepare_network(
path,
name,
relayer=cluster.Relayer.HERMES.value,
relayer=cluster.Relayer.RLY.value,
)


Expand Down Expand Up @@ -230,7 +230,7 @@ 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)
rly_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)
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"CosmosERC20": "CosmosToken.sol",
"TestBank": "TestBank.sol",
"TestICA": "TestICA.sol",
"TestRelayer": "TestRelayer.sol",
}


Expand Down Expand Up @@ -397,6 +398,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 ce95382

Please sign in to comment.