From 630632513199127905ef00b34ec2c93c9e6d1f2c Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 13 Sep 2023 15:35:05 +0800 Subject: [PATCH 1/5] Problem: icaauth route is not registered correctly test icaauth --- CHANGELOG.md | 2 +- integration_tests/cosmoscli.py | 44 +++++++++ integration_tests/ibc_utils.py | 151 +++++++++++++++++++++++++++---- integration_tests/test_ibc.py | 161 +-------------------------------- integration_tests/test_ica.py | 77 ++++++++++++++++ x/icaauth/handler.go | 32 ------- x/icaauth/module.go | 8 +- 7 files changed, 263 insertions(+), 212 deletions(-) create mode 100644 integration_tests/test_ica.py delete mode 100644 x/icaauth/handler.go diff --git a/CHANGELOG.md b/CHANGELOG.md index b5ab07dbd3..2e0c0098bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - [cronos#997](https://github.com/crypto-org-chain/cronos/pull/997) Fix logic to support proxy contract for cronos originated crc20. - [cronos#1005](https://github.com/crypto-org-chain/cronos/pull/1005) Support specify channel id for send-to-ibc event in case of source token. - [cronos#1069](https://github.com/crypto-org-chain/cronos/pull/1069) Update ethermint to develop, go-ethereum to `v1.10.26` and ibc-go to `v6.2.0`. -- [cronos#1147](https://github.com/crypto-org-chain/cronos/pull/1147) integrate ica module. +- [cronos#1147](https://github.com/crypto-org-chain/cronos/pull/1147), [cronos#1165](https://github.com/crypto-org-chain/cronos/pull/1165) Integrate ica module. - (deps) [#1121](https://github.com/crypto-org-chain/cronos/pull/1121) Bump Cosmos-SDK to v0.47.5 and ibc-go to v7.2.0. - [cronos#1014](https://github.com/crypto-org-chain/cronos/pull/1014) Support stateful precompiled contract for relayer. diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index f3baab3336..8583dd52bc 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1276,6 +1276,28 @@ def ica_register_account(self, connid, **kwargs): rsp = self.event_query_tx_for(rsp["txhash"]) return rsp + def icaauth_register_account(self, connid, **kwargs): + "execute on host chain to attach an account to the connection" + default_kwargs = { + "home": self.data_dir, + "node": self.node_rpc, + "chain_id": self.chain_id, + "keyring_backend": "test", + } + rsp = json.loads( + self.raw( + "tx", + "icaauth", + "register-account", + connid, + "-y", + **(default_kwargs | kwargs), + ) + ) + if rsp["code"] == 0: + rsp = self.event_query_tx_for(rsp["txhash"]) + return rsp + def ica_submit_tx(self, connid, tx, **kwargs): default_kwargs = { "home": self.data_dir, @@ -1299,6 +1321,28 @@ def ica_submit_tx(self, connid, tx, **kwargs): rsp = self.event_query_tx_for(rsp["txhash"]) return rsp + def icaauth_submit_tx(self, connid, tx, **kwargs): + default_kwargs = { + "home": self.data_dir, + "node": self.node_rpc, + "chain_id": self.chain_id, + "keyring_backend": "test", + } + rsp = json.loads( + self.raw( + "tx", + "icaauth", + "submit-tx", + connid, + tx, + "-y", + **(default_kwargs | kwargs), + ) + ) + if rsp["code"] == 0: + rsp = self.event_query_tx_for(rsp["txhash"]) + return rsp + def ica_query_account(self, connid, owner, **kwargs): default_kwargs = { "node": self.node_rpc, diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index 86595fce1a..e1a62fc8ea 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -14,6 +14,7 @@ deploy_contract, eth_to_bech32, parse_events, + parse_events_rpc, send_transaction, setup_token_mapping, wait_for_fn, @@ -37,6 +38,7 @@ def prepare_network( file, incentivized=True, is_relay=True, + connection_only=False, relayer=cluster.Relayer.HERMES.value, ): is_hermes = relayer == cluster.Relayer.HERMES.value @@ -66,26 +68,41 @@ def prepare_network( path = cronos.base_dir.parent / "relayer" if is_hermes: hermes = Hermes(cronos.base_dir.parent / "relayer.toml") - subprocess.check_call( - [ - "hermes", - "--config", - hermes.configpath, - "create", - "channel", - "--a-port", - "transfer", - "--b-port", - "transfer", - "--a-chain", - "cronos_777-1", - "--b-chain", - "chainmain-1", - "--new-client-connection", - "--yes", - ] - + incentivized_args - ) + if connection_only: + subprocess.check_call( + [ + "hermes", + "--config", + hermes.configpath, + "create", + "connection", + "--a-chain", + "cronos_777-1", + "--b-chain", + "chainmain-1", + ] + ) + else: + subprocess.check_call( + [ + "hermes", + "--config", + hermes.configpath, + "create", + "channel", + "--a-port", + "transfer", + "--b-port", + "transfer", + "--a-chain", + "cronos_777-1", + "--b-chain", + "chainmain-1", + "--new-client-connection", + "--yes", + ] + + incentivized_args + ) else: cmd = [ "rly", @@ -181,6 +198,58 @@ def hermes_transfer(ibc): return src_amount +def find_duplicate(attributes): + res = set() + key = attributes[0]["key"] + for attribute in attributes: + if attribute["key"] == key: + value0 = attribute["value"] + elif attribute["key"] == "amount": + amount = attribute["value"] + value_pair = f"{value0}:{amount}" + if value_pair in res: + return value_pair + res.add(value_pair) + return None + + +def ibc_transfer_with_hermes(ibc): + src_amount = hermes_transfer(ibc) + dst_amount = src_amount * RATIO # the decimal places difference + dst_denom = "basetcro" + dst_addr = eth_to_bech32(ADDRS["signer2"]) + old_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom) + + new_dst_balance = 0 + + def check_balance_change(): + nonlocal new_dst_balance + new_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom) + return new_dst_balance != old_dst_balance + + wait_for_fn("balance change", check_balance_change) + assert old_dst_balance + dst_amount == new_dst_balance + + # assert that the relayer transactions do enables the dynamic fee extension option. + cli = ibc.cronos.cosmos_cli() + criteria = "message.action=/ibc.core.channel.v1.MsgChannelOpenInit" + tx = cli.tx_search(criteria)["txs"][0] + events = parse_events_rpc(tx["events"]) + fee = int(events["tx"]["fee"].removesuffix(dst_denom)) + gas = int(tx["gas_wanted"]) + # the effective fee is decided by the max_priority_fee (base fee is zero) + # rather than the normal gas price + assert fee == gas * 1000000 + + # check duplicate OnRecvPacket events + criteria = "message.action=/ibc.core.channel.v1.MsgRecvPacket" + tx = cli.tx_search(criteria)["txs"][0] + events = tx["logs"][1]["events"] + for event in events: + dup = find_duplicate(event["attributes"]) + assert not dup, f"duplicate {dup} in {event['type']}" + + def get_balance(chain, addr, denom): balance = chain.cosmos_cli().balance(addr, denom) print("balance", balance, addr, denom) @@ -467,3 +536,45 @@ def check_contract_balance_change(): wait_for_fn("check contract balance change", check_contract_balance_change) assert cronos_balance_after_send == amount return amount, contract.address + + +def wait_for_check_channel_ready(cli, connid, channel_id): + print("wait for channel ready") + + def check_channel_ready(): + channels = cli.ibc_query_channels(connid)["channels"] + try: + state = next( + channel["state"] + for channel in channels + if channel["channel_id"] == channel_id + ) + except StopIteration: + return False + return state == "STATE_OPEN" + + wait_for_fn("channel ready", check_channel_ready) + + +def wait_for_check_tx(cli, adr, num_txs): + print("wait for tx arrive") + + def check_tx(): + current = len(cli.query_all_txs(adr)["txs"]) + print("current", current) + return current > num_txs + + wait_for_fn("transfer tx", check_tx) + + +def funds_ica(cli, adr): + # initial balance of interchain account should be zero + assert cli.balance(adr) == 0 + + # send some funds to interchain account + rsp = cli.transfer("signer2", adr, "1cro", gas_prices="1000000basecro") + assert rsp["code"] == 0, rsp["raw_log"] + wait_for_new_blocks(cli, 1) + + # check if the funds are received in interchain account + assert cli.balance(adr, denom="basecro") == 100000000 diff --git a/integration_tests/test_ibc.py b/integration_tests/test_ibc.py index 5c8f6e6d1a..9570d0c37d 100644 --- a/integration_tests/test_ibc.py +++ b/integration_tests/test_ibc.py @@ -1,5 +1,3 @@ -import json - import pytest from .ibc_utils import ( @@ -8,20 +6,11 @@ cronos_transfer_source_tokens, cronos_transfer_source_tokens_with_proxy, get_balance, - hermes_transfer, ibc_incentivized_transfer, + ibc_transfer_with_hermes, prepare_network, ) -from .utils import ( - ADDRS, - CONTRACTS, - deploy_contract, - eth_to_bech32, - parse_events_rpc, - send_transaction, - wait_for_fn, - wait_for_new_blocks, -) +from .utils import ADDRS, CONTRACTS, deploy_contract, send_transaction, wait_for_fn @pytest.fixture(scope="module", params=[True, False]) @@ -34,63 +23,11 @@ def ibc(request, tmp_path_factory): yield from network -def get_balances(chain, addr): - return chain.cosmos_cli().balances(addr) - - -def find_duplicate(attributes): - res = set() - key = attributes[0]["key"] - for attribute in attributes: - if attribute["key"] == key: - value0 = attribute["value"] - elif attribute["key"] == "amount": - amount = attribute["value"] - value_pair = f"{value0}:{amount}" - if value_pair in res: - return value_pair - res.add(value_pair) - return None - - def test_ibc_transfer_with_hermes(ibc): """ test ibc transfer tokens with hermes cli """ - src_amount = hermes_transfer(ibc) - dst_amount = src_amount * RATIO # the decimal places difference - dst_denom = "basetcro" - dst_addr = eth_to_bech32(ADDRS["signer2"]) - old_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom) - - new_dst_balance = 0 - - def check_balance_change(): - nonlocal new_dst_balance - new_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom) - return new_dst_balance != old_dst_balance - - wait_for_fn("balance change", check_balance_change) - assert old_dst_balance + dst_amount == new_dst_balance - - # assert that the relayer transactions do enables the dynamic fee extension option. - cli = ibc.cronos.cosmos_cli() - criteria = "message.action=/ibc.core.channel.v1.MsgChannelOpenInit" - tx = cli.tx_search(criteria)["txs"][0] - events = parse_events_rpc(tx["events"]) - fee = int(events["tx"]["fee"].removesuffix("basetcro")) - gas = int(tx["gas_wanted"]) - # the effective fee is decided by the max_priority_fee (base fee is zero) - # rather than the normal gas price - assert fee == gas * 1000000 - - # check duplicate OnRecvPacket events - criteria = "message.action=/ibc.core.channel.v1.MsgRecvPacket" - tx = cli.tx_search(criteria)["txs"][0] - events = tx["logs"][1]["events"] - for event in events: - dup = find_duplicate(event["attributes"]) - assert not dup, f"duplicate {dup} in {event['type']}" + ibc_transfer_with_hermes(ibc) def test_ibc_incentivized_transfer(ibc): @@ -215,95 +152,3 @@ def test_cronos_transfer_source_tokens_with_proxy(ibc): """ assert_ready(ibc) cronos_transfer_source_tokens_with_proxy(ibc) - - -def test_ica(ibc, tmp_path): - connid = "connection-0" - cli_host = ibc.chainmain.cosmos_cli() - cli_controller = ibc.cronos.cosmos_cli() - - print("register ica account") - rsp = cli_controller.ica_register_account( - connid, from_="signer2", gas="400000", fees="100000000basetcro" - ) - assert rsp["code"] == 0, rsp["raw_log"] - port_id, channel_id = next( - ( - evt["attributes"][0]["value"], - evt["attributes"][1]["value"], - ) - for evt in rsp["events"] - if evt["type"] == "channel_open_init" - ) - print("port-id", port_id, "channel-id", channel_id) - - print("wait for ica channel ready") - - def check_channel_ready(): - channels = cli_controller.ibc_query_channels(connid)["channels"] - try: - state = next( - channel["state"] - for channel in channels - if channel["channel_id"] == channel_id - ) - except StopIteration: - return False - return state == "STATE_OPEN" - - wait_for_fn("channel ready", check_channel_ready) - - print("query ica account") - ica_address = cli_controller.ica_query_account( - connid, cli_controller.address("signer2") - )["interchain_account_address"] - print("ica address", ica_address) - - # initial balance of interchain account should be zero - assert cli_host.balance(ica_address) == 0 - - # send some funds to interchain account - rsp = cli_host.transfer("signer2", ica_address, "1cro", gas_prices="1000000basecro") - assert rsp["code"] == 0, rsp["raw_log"] - wait_for_new_blocks(cli_host, 1) - - # check if the funds are received in interchain account - assert cli_host.balance(ica_address, denom="basecro") == 100000000 - - # generate a transaction to send to host chain - generated_tx = tmp_path / "generated_tx.txt" - generated_tx_msg = { - "@type": "/cosmos.bank.v1beta1.MsgSend", - "from_address": ica_address, - "to_address": cli_host.address("signer2"), - "amount": [{"denom": "basecro", "amount": "50000000"}], - } - str = json.dumps(generated_tx_msg) - generated_packet = cli_controller.ica_generate_packet_data(str) - print(generated_packet) - generated_tx.write_text(json.dumps(generated_packet)) - - num_txs = len(cli_host.query_all_txs(ica_address)["txs"]) - - # submit transaction on host chain on behalf of interchain account - rsp = cli_controller.ica_submit_tx( - connid, - generated_tx, - from_="signer2", - ) - assert rsp["code"] == 0, rsp["raw_log"] - packet_seq = next( - int(evt["attributes"][4]["value"]) - for evt in rsp["events"] - if evt["type"] == "send_packet" - ) - print("packet sequence", packet_seq) - - def check_ica_tx(): - return len(cli_host.query_all_txs(ica_address)["txs"]) > num_txs - - print("wait for ica tx arrive") - wait_for_fn("ica transfer tx", check_ica_tx) - - # check if the funds are reduced in interchain account - assert cli_host.balance(ica_address, denom="basecro") == 50000000 diff --git a/integration_tests/test_ica.py b/integration_tests/test_ica.py new file mode 100644 index 0000000000..c04a860f94 --- /dev/null +++ b/integration_tests/test_ica.py @@ -0,0 +1,77 @@ +import json + +import pytest + +from .ibc_utils import ( + funds_ica, + prepare_network, + wait_for_check_channel_ready, + wait_for_check_tx, +) + + +@pytest.fixture(scope="module") +def ibc(request, tmp_path_factory): + "prepare-network" + name = "ibc" + path = tmp_path_factory.mktemp(name) + network = prepare_network(path, name, False) + yield from network + + +def test_ica(ibc, tmp_path): + connid = "connection-0" + cli_host = ibc.chainmain.cosmos_cli() + cli_controller = ibc.cronos.cosmos_cli() + + print("register ica account") + rsp = cli_controller.icaauth_register_account( + connid, from_="signer2", gas="400000", fees="100000000basetcro" + ) + assert rsp["code"] == 0, rsp["raw_log"] + port_id, channel_id = next( + ( + evt["attributes"][0]["value"], + evt["attributes"][1]["value"], + ) + for evt in rsp["events"] + if evt["type"] == "channel_open_init" + ) + print("port-id", port_id, "channel-id", channel_id) + + wait_for_check_channel_ready(cli_controller, connid, channel_id) + + print("query ica account") + ica_address = cli_controller.ica_query_account( + connid, cli_controller.address("signer2") + )["interchain_account_address"] + print("ica address", ica_address) + + funds_ica(cli_host, ica_address) + num_txs = len(cli_host.query_all_txs(ica_address)["txs"]) + + # generate a transaction to send to host chain + generated_tx = tmp_path / "generated_tx.txt" + generated_tx_msg = cli_host.transfer( + ica_address, cli_host.address("signer2"), "0.5cro", generate_only=True + ) + + print(generated_tx_msg) + generated_tx.write_text(json.dumps(generated_tx_msg)) + + # submit transaction on host chain on behalf of interchain account + rsp = cli_controller.icaauth_submit_tx( + connid, + generated_tx, + from_="signer2", + ) + assert rsp["code"] == 0, rsp["raw_log"] + packet_seq = next( + int(evt["attributes"][4]["value"]) + for evt in rsp["events"] + if evt["type"] == "send_packet" + ) + print("packet sequence", packet_seq) + wait_for_check_tx(cli_host, ica_address, num_txs) + # check if the funds are reduced in interchain account + assert cli_host.balance(ica_address, denom="basecro") == 50000000 diff --git a/x/icaauth/handler.go b/x/icaauth/handler.go deleted file mode 100644 index 5c96c2bc3b..0000000000 --- a/x/icaauth/handler.go +++ /dev/null @@ -1,32 +0,0 @@ -package icaauth - -import ( - "fmt" - - "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" - "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" -) - -// NewHandler ... -func NewHandler(k keeper.Keeper) sdk.Handler { - msgServer := keeper.NewMsgServerImpl(k) - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - case *types.MsgRegisterAccount: - res, err := msgServer.RegisterAccount(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgSubmitTx: - res, err := msgServer.SubmitTx(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - default: - errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - } - } -} diff --git a/x/icaauth/module.go b/x/icaauth/module.go index a8baa81fc5..b0b085e9d4 100644 --- a/x/icaauth/module.go +++ b/x/icaauth/module.go @@ -1,6 +1,7 @@ package icaauth import ( + "context" "encoding/json" "fmt" @@ -73,7 +74,11 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {} +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} // GetTxCmd returns the capability module's root tx command. func (a AppModuleBasic) GetTxCmd() *cobra.Command { @@ -115,6 +120,7 @@ func (am AppModule) Name() string { // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) } // RegisterInvariants registers the capability module's invariants. From 0bd951b1fc84f3e5cafbb3bb047745ce6abe8d21 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 14 Sep 2023 22:13:52 +0800 Subject: [PATCH 2/5] rm dup claim capability handle in https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/apps/27-interchain-accounts/controller/ibc_middleware.go#L60 --- x/icaauth/module_ibc.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/icaauth/module_ibc.go b/x/icaauth/module_ibc.go index 566de2fcd7..5aa6c30c4d 100644 --- a/x/icaauth/module_ibc.go +++ b/x/icaauth/module_ibc.go @@ -8,7 +8,6 @@ import ( icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" ) @@ -38,10 +37,6 @@ func (am IBCModule) OnChanOpenInit( counterparty channeltypes.Counterparty, version string, ) (string, error) { - // Claim channel capability passed back by IBC module - if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } return version, nil } From 9d746f663f9172c50cb15370b77b693af613b151 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 14 Sep 2023 22:15:19 +0800 Subject: [PATCH 3/5] fix submit tx https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/apps/27-interchain-accounts/controller/keeper/relay.go#L28 --- x/icaauth/keeper/keeper.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/x/icaauth/keeper/keeper.go b/x/icaauth/keeper/keeper.go index 31930f99a1..56ca31bf48 100644 --- a/x/icaauth/keeper/keeper.go +++ b/x/icaauth/keeper/keeper.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "cosmossdk.io/errors" "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -14,8 +13,6 @@ import ( "github.com/cosmos/gogoproto/proto" icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -56,16 +53,6 @@ func (k *Keeper) DoSubmitTx(ctx sdk.Context, connectionID, owner string, msgs [] return err } - channelID, found := k.icaControllerKeeper.GetActiveChannelID(ctx, connectionID, portID) - if !found { - return errors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) - } - - channelCapability, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) - if !found { - return errors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") - } - data, err := icatypes.SerializeCosmosTx(k.cdc, msgs) if err != nil { return err @@ -79,7 +66,7 @@ func (k *Keeper) DoSubmitTx(ctx sdk.Context, connectionID, owner string, msgs [] // timeoutDuration should be constraited by MinTimeoutDuration parameter. timeoutTimestamp := ctx.BlockTime().Add(timeoutDuration).UnixNano() - _, err = k.icaControllerKeeper.SendTx(ctx, channelCapability, connectionID, portID, packetData, uint64(timeoutTimestamp)) //nolint:staticcheck + _, err = k.icaControllerKeeper.SendTx(ctx, nil, connectionID, portID, packetData, uint64(timeoutTimestamp)) //nolint:staticcheck if err != nil { return err } From ee17511607d711801ddaf0dfd484d73f429c76e5 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 14 Sep 2023 23:40:13 +0800 Subject: [PATCH 4/5] Apply suggestions from code review --- CHANGELOG.md | 3 ++- integration_tests/test_ibc_rly.py | 7 ++++--- integration_tests/test_ica.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e0c0098bc..42f248170e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,9 +18,10 @@ - [cronos#997](https://github.com/crypto-org-chain/cronos/pull/997) Fix logic to support proxy contract for cronos originated crc20. - [cronos#1005](https://github.com/crypto-org-chain/cronos/pull/1005) Support specify channel id for send-to-ibc event in case of source token. - [cronos#1069](https://github.com/crypto-org-chain/cronos/pull/1069) Update ethermint to develop, go-ethereum to `v1.10.26` and ibc-go to `v6.2.0`. -- [cronos#1147](https://github.com/crypto-org-chain/cronos/pull/1147), [cronos#1165](https://github.com/crypto-org-chain/cronos/pull/1165) Integrate ica module. +- [cronos#1147](https://github.com/crypto-org-chain/cronos/pull/1147) Integrate ica module. - (deps) [#1121](https://github.com/crypto-org-chain/cronos/pull/1121) Bump Cosmos-SDK to v0.47.5 and ibc-go to v7.2.0. - [cronos#1014](https://github.com/crypto-org-chain/cronos/pull/1014) Support stateful precompiled contract for relayer. +- [cronos#1165](https://github.com/crypto-org-chain/cronos/pull/1165) Icaauth module is not adjusted correctly in ibc-go v7.2.0. ### Bug Fixes diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index 0d584ac33c..de5a31fe1a 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -49,9 +49,10 @@ def ibc(request, tmp_path_factory): for network in prepare_network( path, "ibc", - True, - True, - cluster.Relayer.RLY.value, + incentivized=True, + is_relay=True, + connection_only=False, + relayer=cluster.Relayer.RLY.value, ): if network.proc: procs.append(network.proc) diff --git a/integration_tests/test_ica.py b/integration_tests/test_ica.py index c04a860f94..ee9cedd4ca 100644 --- a/integration_tests/test_ica.py +++ b/integration_tests/test_ica.py @@ -15,7 +15,7 @@ def ibc(request, tmp_path_factory): "prepare-network" name = "ibc" path = tmp_path_factory.mktemp(name) - network = prepare_network(path, name, False) + network = prepare_network(path, name, connection_only=True) yield from network From d0ff50766bcb7a4f97e6bec72fa3c95b1dd3cc4e Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 15 Sep 2023 09:00:10 +0800 Subject: [PATCH 5/5] cleanup test --- integration_tests/cosmoscli.py | 46 ------ integration_tests/ibc_utils.py | 166 +++++++++++--------- integration_tests/test_ibc.py | 2 +- integration_tests/test_ibc_rly.py | 3 - integration_tests/test_ibc_update_client.py | 2 +- integration_tests/test_ica.py | 2 +- 6 files changed, 97 insertions(+), 124 deletions(-) diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index 8583dd52bc..a00e9b6b88 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1253,29 +1253,6 @@ def transfer_tokens(self, from_, to, amount, **kwargs): ) ) - def ica_register_account(self, connid, **kwargs): - "execute on host chain to attach an account to the connection" - default_kwargs = { - "home": self.data_dir, - "node": self.node_rpc, - "chain_id": self.chain_id, - "keyring_backend": "test", - } - rsp = json.loads( - self.raw( - "tx", - "ica", - "controller", - "register", - connid, - "-y", - **(default_kwargs | kwargs), - ) - ) - if rsp["code"] == 0: - rsp = self.event_query_tx_for(rsp["txhash"]) - return rsp - def icaauth_register_account(self, connid, **kwargs): "execute on host chain to attach an account to the connection" default_kwargs = { @@ -1298,29 +1275,6 @@ def icaauth_register_account(self, connid, **kwargs): rsp = self.event_query_tx_for(rsp["txhash"]) return rsp - def ica_submit_tx(self, connid, tx, **kwargs): - default_kwargs = { - "home": self.data_dir, - "node": self.node_rpc, - "chain_id": self.chain_id, - "keyring_backend": "test", - } - rsp = json.loads( - self.raw( - "tx", - "ica", - "controller", - "send-tx", - connid, - tx, - "-y", - **(default_kwargs | kwargs), - ) - ) - if rsp["code"] == 0: - rsp = self.event_query_tx_for(rsp["txhash"]) - return rsp - def icaauth_submit_tx(self, connid, tx, **kwargs): default_kwargs = { "home": self.data_dir, diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index e1a62fc8ea..78e203344b 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -33,6 +33,87 @@ class IBCNetwork(NamedTuple): proc: subprocess.Popen[bytes] | None +def call_hermes_cmd( + hermes, + connection_only, + incentivized, + version, +): + if connection_only: + subprocess.check_call( + [ + "hermes", + "--config", + hermes.configpath, + "create", + "connection", + "--a-chain", + "cronos_777-1", + "--b-chain", + "chainmain-1", + ] + ) + else: + subprocess.check_call( + [ + "hermes", + "--config", + hermes.configpath, + "create", + "channel", + "--a-port", + "transfer", + "--b-port", + "transfer", + "--a-chain", + "cronos_777-1", + "--b-chain", + "chainmain-1", + "--new-client-connection", + "--yes", + ] + + ( + [ + "--channel-version", + json.dumps(version), + ] + if incentivized + else [] + ) + ) + + +def call_rly_cmd(path, version): + cmd = [ + "rly", + "pth", + "new", + "chainmain-1", + "cronos_777-1", + "chainmain-cronos", + "--home", + str(path), + ] + subprocess.check_call(cmd) + cmd = [ + "rly", + "tx", + "connect", + "chainmain-cronos", + "--src-port", + "transfer", + "--dst-port", + "transfer", + "--order", + "unordered", + "--version", + json.dumps(version), + "--home", + str(path), + ] + subprocess.check_call(cmd) + + def prepare_network( tmp_path, file, @@ -41,6 +122,10 @@ def prepare_network( connection_only=False, relayer=cluster.Relayer.HERMES.value, ): + print("incentivized", incentivized) + print("is_relay", is_relay) + print("connection_only", connection_only) + print("relayer", relayer) is_hermes = relayer == cluster.Relayer.HERMES.value hermes = None file = f"configs/{file}.jsonnet" @@ -57,81 +142,18 @@ def prepare_network( wait_for_port(ports.grpc_port(cronos.base_port(0))) # cronos grpc version = {"fee_version": "ics29-1", "app_version": "ics20-1"} - incentivized_args = ( - [ - "--channel-version", - json.dumps(version), - ] - if incentivized - else [] - ) path = cronos.base_dir.parent / "relayer" if is_hermes: - hermes = Hermes(cronos.base_dir.parent / "relayer.toml") - if connection_only: - subprocess.check_call( - [ - "hermes", - "--config", - hermes.configpath, - "create", - "connection", - "--a-chain", - "cronos_777-1", - "--b-chain", - "chainmain-1", - ] - ) - else: - subprocess.check_call( - [ - "hermes", - "--config", - hermes.configpath, - "create", - "channel", - "--a-port", - "transfer", - "--b-port", - "transfer", - "--a-chain", - "cronos_777-1", - "--b-chain", - "chainmain-1", - "--new-client-connection", - "--yes", - ] - + incentivized_args - ) + hermes = Hermes(path.with_suffix(".toml")) + call_hermes_cmd( + hermes, + connection_only, + incentivized, + version, + ) else: - cmd = [ - "rly", - "pth", - "new", - "chainmain-1", - "cronos_777-1", - "chainmain-cronos", - "--home", - str(path), - ] - subprocess.check_call(cmd) - cmd = [ - "rly", - "tx", - "connect", - "chainmain-cronos", - "--src-port", - "transfer", - "--dst-port", - "transfer", - "--order", - "unordered", - "--version", - json.dumps(version), - "--home", - str(path), - ] - subprocess.check_call(cmd) + call_rly_cmd(path, version) + proc = None if incentivized: # register fee payee diff --git a/integration_tests/test_ibc.py b/integration_tests/test_ibc.py index 9570d0c37d..bd22947c39 100644 --- a/integration_tests/test_ibc.py +++ b/integration_tests/test_ibc.py @@ -19,7 +19,7 @@ def ibc(request, tmp_path_factory): incentivized = request.param name = "ibc" path = tmp_path_factory.mktemp(name) - network = prepare_network(path, name, incentivized) + network = prepare_network(path, name, incentivized=incentivized) yield from network diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index de5a31fe1a..29e37ff6f6 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -49,9 +49,6 @@ def ibc(request, tmp_path_factory): for network in prepare_network( path, "ibc", - incentivized=True, - is_relay=True, - connection_only=False, relayer=cluster.Relayer.RLY.value, ): if network.proc: diff --git a/integration_tests/test_ibc_update_client.py b/integration_tests/test_ibc_update_client.py index 4472b11a0d..cddf541dc8 100644 --- a/integration_tests/test_ibc_update_client.py +++ b/integration_tests/test_ibc_update_client.py @@ -12,7 +12,7 @@ def ibc(request, tmp_path_factory): "prepare-network" name = "ibc" path = tmp_path_factory.mktemp(name) - network = prepare_network(path, name, True, False) + network = prepare_network(path, name, is_relay=False) yield from network diff --git a/integration_tests/test_ica.py b/integration_tests/test_ica.py index ee9cedd4ca..3201a537fd 100644 --- a/integration_tests/test_ica.py +++ b/integration_tests/test_ica.py @@ -15,7 +15,7 @@ def ibc(request, tmp_path_factory): "prepare-network" name = "ibc" path = tmp_path_factory.mktemp(name) - network = prepare_network(path, name, connection_only=True) + network = prepare_network(path, name, incentivized=False, connection_only=True) yield from network