Skip to content

Commit 730cf08

Browse files
committed
Problem: batch call precompile is not tested (#1360)
* cleanup * Problem: batch call precompile is not tested fix test * update deps
1 parent 2995948 commit 730cf08

File tree

7 files changed

+58
-21
lines changed

7 files changed

+58
-21
lines changed

integration_tests/configs/ibc.jsonnet

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ config {
2222
name: 'user' + i,
2323
coins: '30000000000000000000000basetcro',
2424
}
25-
for i in std.range(1, 20)
25+
for i in std.range(1, 50)
2626
],
2727
'app-config'+: {
2828
'index-events': super['index-events'] + ['message.action'],
@@ -97,7 +97,7 @@ config {
9797
name: 'user' + i,
9898
coins: '10000000000000cro',
9999
}
100-
for i in std.range(1, 20)
100+
for i in std.range(1, 50)
101101
],
102102
genesis: {
103103
app_state: {
@@ -165,7 +165,7 @@ config {
165165
chains: [
166166
{
167167
id: 'cronos_777-1',
168-
max_gas: 1000000,
168+
max_gas: 2000000,
169169
gas_multiplier: 1.1,
170170
address_type: {
171171
derivation: 'ethermint',
@@ -174,7 +174,7 @@ config {
174174
},
175175
},
176176
gas_price: {
177-
price: 10000000000000000,
177+
price: 10000000,
178178
denom: 'basetcro',
179179
},
180180
event_source: {

integration_tests/configs/ibc_rly_evm.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local ibc = import 'ibc_rly.jsonnet';
33
ibc {
44
relayer+: {
55
chains: [super.chains[0] {
6-
precompiled_contract_address: '0x0000000000000000000000000000000000000065',
6+
precompiled_contract_address: '0x6F1805D56bF05b7be10857F376A5b1c160C8f72C',
77
json_rpc_address: 'http://127.0.0.1:26701',
88
}] + super.chains[1:],
99
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
contract TestRelayer {
5+
address constant relayer = 0x0000000000000000000000000000000000000065;
6+
7+
function batchCall(bytes[] memory payloads) public {
8+
for (uint256 i = 0; i < payloads.length; i++) {
9+
(bool success,) = relayer.call(payloads[i]);
10+
require(success);
11+
}
12+
}
13+
}

integration_tests/ibc_utils.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ADDRS,
1515
CONTRACTS,
1616
deploy_contract,
17+
derive_new_account,
1718
eth_to_bech32,
1819
parse_events,
1920
parse_events_rpc,
@@ -25,6 +26,7 @@
2526
)
2627

2728
RATIO = 10**10
29+
RELAYER_CALLER = "0x6F1805D56bF05b7be10857F376A5b1c160C8f72C"
2830

2931

3032
class Status(IntEnum):
@@ -171,6 +173,17 @@ def prepare_network(
171173

172174
version = {"fee_version": "ics29-1", "app_version": "ics20-1"}
173175
path = cronos.base_dir.parent / "relayer"
176+
w3 = cronos.w3
177+
acc = derive_new_account(2)
178+
sender = acc.address
179+
# fund new sender to deploy contract with same address
180+
if w3.eth.get_balance(sender, "latest") == 0:
181+
fund = 3000000000000000000
182+
tx = {"to": sender, "value": fund, "gasPrice": w3.eth.gas_price}
183+
send_transaction(w3, tx)
184+
assert w3.eth.get_balance(sender, "latest") == fund
185+
caller = deploy_contract(w3, CONTRACTS["TestRelayer"], key=acc.key).address
186+
assert caller == RELAYER_CALLER, caller
174187
if is_hermes:
175188
hermes = Hermes(path.with_suffix(".toml"))
176189
call_hermes_cmd(
@@ -333,7 +346,7 @@ def get_balances(chain, addr):
333346

334347
def ibc_multi_transfer(ibc):
335348
chains = [ibc.cronos.cosmos_cli(), ibc.chainmain.cosmos_cli()]
336-
users = [f"user{i}" for i in range(1, 21)]
349+
users = [f"user{i}" for i in range(1, 51)]
337350
addrs0 = [chains[0].address(user) for user in users]
338351
addrs1 = [chains[1].address(user) for user in users]
339352
denom0 = "basetcro"
@@ -413,10 +426,12 @@ def ibc_incentivized_transfer(ibc):
413426
receiver = chains[1].address("signer2")
414427
sender = chains[0].address("signer2")
415428
relayer = chains[0].address("signer1")
429+
relayer_caller = eth_to_bech32(RELAYER_CALLER)
416430
amount = 1000
417431
fee_denom = "ibcfee"
418432
base_denom = "basetcro"
419433
old_amt_fee = chains[0].balance(relayer, fee_denom)
434+
old_amt_fee_caller = chains[0].balance(relayer_caller, fee_denom)
420435
old_amt_sender_fee = chains[0].balance(sender, fee_denom)
421436
old_amt_sender_base = chains[0].balance(sender, base_denom)
422437
old_amt_receiver_base = chains[1].balance(receiver, "basecro")
@@ -456,7 +471,12 @@ def ibc_incentivized_transfer(ibc):
456471
def check_fee():
457472
amount = chains[0].balance(relayer, fee_denom)
458473
if amount > old_amt_fee:
459-
assert amount == old_amt_fee + 20
474+
amount_caller = chains[0].balance(relayer_caller, fee_denom)
475+
if amount_caller > 0:
476+
assert amount_caller == old_amt_fee_caller + 10, amount_caller
477+
assert amount == old_amt_fee + 10, amount
478+
else:
479+
assert amount == old_amt_fee + 20, amount
460480
return True
461481
else:
462482
return False
@@ -471,17 +491,10 @@ def check_fee():
471491
], actual
472492
path = f"transfer/{dst_channel}/{base_denom}"
473493
denom_hash = hashlib.sha256(path.encode()).hexdigest().upper()
474-
assert json.loads(
475-
chains[0].raw(
476-
"query",
477-
"ibc-transfer",
478-
"denom-trace",
479-
denom_hash,
480-
node=ibc.chainmain.node_rpc(0),
481-
output="json",
482-
)
483-
)["denom_trace"] == {"path": f"transfer/{dst_channel}", "base_denom": base_denom}
484-
assert get_balances(ibc.chainmain, receiver) == [
494+
denom_trace = chains[0].ibc_denom_trace(path, ibc.chainmain.node_rpc(0))
495+
assert denom_trace == {"path": f"transfer/{dst_channel}", "base_denom": base_denom}
496+
current = get_balances(ibc.chainmain, receiver)
497+
assert current == [
485498
{"denom": "basecro", "amount": f"{old_amt_receiver_base}"},
486499
{"denom": f"ibc/{denom_hash}", "amount": f"{amount}"},
487500
]

integration_tests/test_ibc_rly.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .ibc_utils import (
99
RATIO,
10+
RELAYER_CALLER,
1011
assert_duplicate,
1112
cronos_transfer_source_tokens,
1213
cronos_transfer_source_tokens_with_proxy,
@@ -59,6 +60,8 @@ def ibc(request, tmp_path_factory):
5960

6061

6162
def amount_dict(amt, denom):
63+
if amt == 0:
64+
return []
6265
return [
6366
AttributeDict(
6467
{
@@ -298,8 +301,8 @@ def test_ibc_incentivized_transfer(ibc):
298301
acknowledge_packet(seq0),
299302
distribute_fee(src_relayer, fee),
300303
*send_coins(feeibc_addr, src_relayer, src_amount, fee_denom),
301-
distribute_fee(src_relayer, fee),
302-
*send_coins(feeibc_addr, src_relayer, src_amount, fee_denom),
304+
distribute_fee(RELAYER_CALLER, fee),
305+
*send_coins(feeibc_addr, RELAYER_CALLER, src_amount, fee_denom),
303306
distribute_fee(cronos_signer2, fee),
304307
*send_coins(feeibc_addr, cronos_signer2, src_amount, fee_denom),
305308
fungible(checksum_dst_adr, cronos_signer2, amount, dst_denom),

integration_tests/test_ibc_rly_gas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_ibc(ibc):
2323
cli = ibc.cronos.cosmos_cli()
2424
wait_for_new_blocks(cli, 1)
2525
rly_transfer(ibc)
26-
diff = 0.01
26+
diff = 0.15
2727
record = log_gas_records(cli)
2828
if record:
2929
records.append(record)

integration_tests/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"TestBank": "TestBank.sol",
6363
"TestICA": "TestICA.sol",
6464
"Random": "Random.sol",
65+
"TestRelayer": "TestRelayer.sol",
6566
}
6667

6768

@@ -421,6 +422,13 @@ def cronos_address_from_mnemonics(mnemonics, prefix=CRONOS_ADDRESS_PREFIX):
421422
return eth_to_bech32(acct.address, prefix)
422423

423424

425+
def derive_new_account(n=1):
426+
# derive a new address
427+
account_path = f"m/44'/60'/0'/0/{n}"
428+
mnemonic = os.getenv("COMMUNITY_MNEMONIC")
429+
return Account.from_mnemonic(mnemonic, account_path=account_path)
430+
431+
424432
def send_to_cosmos(gravity_contract, token_contract, w3, recipient, amount, key=None):
425433
"""
426434
do approve and sendToCronos on ethereum side

0 commit comments

Comments
 (0)