Skip to content

Commit

Permalink
Problem: no register support for payee and counterpartyPayee
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 25, 2024
1 parent 7dd3362 commit 81daa98
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 306 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func New(
evmS,
[]evmkeeper.CustomContractFn{
func(_ sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec, rules, app.Logger())
return cronosprecompiles.NewRelayerContract(app.IBCKeeper, app.IBCFeeKeeper, appCodec, rules, app.Logger())
},
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewIcaContract(ctx, app.ICAControllerKeeper, &app.CronosKeeper, appCodec, gasConfig)
Expand Down
23 changes: 21 additions & 2 deletions integration_tests/contracts/contracts/TestRelayer.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {IRelayerFunctions} from "./src/RelayerFunctions.sol";

contract TestRelayer {
address constant relayer = 0x0000000000000000000000000000000000000065;
address constant relayerContract = 0x0000000000000000000000000000000000000065;
IRelayerFunctions relayer = IRelayerFunctions(relayerContract);
address payee;
address counterpartyPayee;

function batchCall(bytes[] memory payloads) public {
for (uint256 i = 0; i < payloads.length; i++) {
(bool success,) = relayer.call(payloads[i]);
(bool success,) = relayerContract.call(payloads[i]);
require(success);
}
}

function callRegisterPayee(string calldata portID, string calldata channelID, address relayerAddr) public returns (bool) {
require(payee == address(0) || payee == msg.sender, "register fail");
bool result = relayer.registerPayee(portID, channelID, relayerAddr);
require(result, "call failed");
payee = msg.sender;
}

function callRegisterCounterpartyPayee(string calldata portID, string calldata channelID, address relayerAddr) public returns (bool) {
require(counterpartyPayee == address(0) || counterpartyPayee == msg.sender, "register fail");
bool result = relayer.registerCounterpartyPayee(portID, channelID, relayerAddr);
require(result, "call failed");
counterpartyPayee = msg.sender;
}
}
23 changes: 18 additions & 5 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def prepare_network(
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
contract = deploy_contract(w3, CONTRACTS["TestRelayer"], key=acc.key)
caller = contract.address
assert caller == RELAYER_CALLER, caller
if is_hermes:
hermes = Hermes(path.with_suffix(".toml"))
Expand All @@ -203,7 +204,19 @@ def prepare_network(
call_rly_cmd(path, connection_only, version)

if incentivized:
register_fee_payee(cronos.cosmos_cli(), chainmain.cosmos_cli())
port_id = "transfer"
channel_id = "channel-0"
register_fee_payee(
cronos.cosmos_cli(), chainmain.cosmos_cli(), port_id, channel_id
)
data = {"from": acc.address}
print("mm-contract", contract.functions)
tx = contract.functions.callRegisterPayee(
port_id, channel_id, ADDRS["signer1"]
).build_transaction(data)
receipt = send_transaction(w3, tx, acc.key)
print("mm-receipt.status", receipt.status)
# assert receipt.status == 0

port = None
if is_relay:
Expand All @@ -217,10 +230,10 @@ def prepare_network(
wait_for_port(port)


def register_fee_payee(src_chain, dst_chain):
def register_fee_payee(src_chain, dst_chain, port_id, channel_id):
rsp = dst_chain.register_counterparty_payee(
"transfer",
"channel-0",
port_id,
channel_id,
dst_chain.address("relayer"),
src_chain.address("signer1"),
from_="relayer",
Expand Down
5 changes: 3 additions & 2 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ibc_multi_transfer,
ibc_transfer,
prepare_network,
rly_transfer,
)
from .utils import (
ADDRS,
Expand Down Expand Up @@ -51,7 +52,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 @@ -235,7 +236,7 @@ def test_ibc(ibc):
w3 = ibc.cronos.w3
wait_for_new_blocks(ibc.cronos.cosmos_cli(), 1)
start = w3.eth.get_block_number()
ibc_transfer(ibc)
ibc_transfer(ibc, rly_transfer)
denom = ibc_denom(channel, src_denom)
logs = get_logs_since(w3, CONTRACT, start)
chainmain_cli = ibc.chainmain.cosmos_cli()
Expand Down
Loading

0 comments on commit 81daa98

Please sign in to comment.