From fa2a57233833ec4b35a35920d409200ebcbdf38d Mon Sep 17 00:00:00 2001 From: srdtrk <59252793+srdtrk@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:55:08 +0300 Subject: [PATCH 1/5] feat(ica): allow unordered ica channels (#5633) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove order check for ICA host and controller upgrade callbacks (#5561) * imp: remove the channel type = ordered checks from both host and controller (#5578) * rm checks and tests, amend docustring * rm unnecessary test * When a channel reopens the ordering and metadata must not change (#5562) * chore: require active channel be CLOSED before re-opening. (#5601) * docs: Update ICA documentation with support for unordered channels (#5607) * Allow specifying order when registering ICA account (#5608) * proto: Add Order to MsgRegisterInterchainAccount. * chore: apply proto changes to go files. * Add ordering to cli tx for Register. * Add documentation line for tx now accepting ordering. * Address feedback review. Co-authored-by: Carlos Rodriguez * Address Cian's feedback; spacing. --------- Co-authored-by: Carlos Rodriguez * docs: ICA register CLI (#5625) * imp(ica/host): removed previous version validation check (#5613) * imp: removed validation check * test: updated icahost test * docs: added godocs * docs: added godocs * chore(ica/host): require active channel be CLOSED before re-opening (#5630) * chore(ica/host): require active channel be CLOSED before re-opening * Update modules/apps/27-interchain-accounts/host/keeper/handshake_test.go Co-authored-by: DimitrisJim --------- Co-authored-by: DimitrisJim * e2e: ordered ica channel is upgraded to unordered (#5616) * E2E test where unordered channel is used with ICA (#5566) * test: add test to use an unordered ICA channel * chore: add hard coded UNORDERED channel Order * proto: Add Order to MsgRegisterInterchainAccount. * chore: apply proto changes to go files. * chore: apply proto changes to go files. * chore: e2e test passing with hard coded ordered value * Add ordering to cli tx for Register. * Add documentation line for tx now accepting ordering. * Address feedback review. Co-authored-by: Carlos Rodriguez * Address Cian's feedback; spacing. * Update e2e/tests/interchain_accounts/base_test.go Co-authored-by: Charly --------- Co-authored-by: DimitrisJim Co-authored-by: Carlos Rodriguez Co-authored-by: Charly * fix: host chan open try test (#5632) * chore: fix linter and merge main * chore: doc lint issue fix * docs: add extra information about ICA channel reopening (#5631) * docs: add extra information about ICA channel reopening * add link to active channels section * Apply suggestions from code review Co-authored-by: Damian Nolan Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com> * Update 01-overview.md --------- Co-authored-by: Damian Nolan Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com> * chore: rm order checks reintroduced after merge conflict. * e2e: comment out failing e2e * chore: lintertroubles --------- Co-authored-by: Cian Hatton Co-authored-by: Charly Co-authored-by: DimitrisJim Co-authored-by: Carlos Rodriguez Co-authored-by: Damian Nolan Co-authored-by: chatton Co-authored-by: Colin Axnér <25233464+colin-axner@users.noreply.github.com> (cherry picked from commit 617482212f0161342ae33d9930de6cb14e1303a6) # Conflicts: # docs/apps/interchain-accounts/active-channels.md # docs/apps/interchain-accounts/overview.md # e2e/tests/core/04-channel/upgrades_test.go # e2e/tests/interchain_accounts/base_test.go # e2e/tests/interchain_accounts/gov_test.go # e2e/tests/interchain_accounts/groups_test.go # e2e/tests/interchain_accounts/incentivized_test.go # e2e/tests/interchain_accounts/localhost_test.go # e2e/tests/interchain_accounts/params_test.go # e2e/tests/upgrades/genesis_test.go # e2e/testsuite/testconfig.go # modules/apps/27-interchain-accounts/controller/client/cli/tx.go # modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go # modules/apps/27-interchain-accounts/controller/keeper/handshake.go # modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go # modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go # modules/apps/27-interchain-accounts/controller/types/msgs.go # modules/apps/27-interchain-accounts/controller/types/msgs_test.go # modules/apps/27-interchain-accounts/controller/types/tx.pb.go # modules/apps/27-interchain-accounts/host/keeper/handshake.go # modules/apps/27-interchain-accounts/host/keeper/handshake_test.go # modules/apps/callbacks/callbacks_test.go # proto/ibc/applications/interchain_accounts/controller/v1/tx.proto --- .../interchain-accounts/active-channels.md | 10 + docs/apps/interchain-accounts/client.md | 19 + docs/apps/interchain-accounts/messages.md | 1 + docs/apps/interchain-accounts/overview.md | 13 + e2e/tests/core/04-channel/upgrades_test.go | 328 ++++++++ e2e/tests/interchain_accounts/base_test.go | 554 +++++++++++++ e2e/tests/interchain_accounts/gov_test.go | 122 +++ e2e/tests/interchain_accounts/groups_test.go | 215 ++++++ .../interchain_accounts/incentivized_test.go | 383 +++++++++ .../interchain_accounts/localhost_test.go | 477 ++++++++++++ e2e/tests/interchain_accounts/params_test.go | 152 ++++ e2e/tests/upgrades/genesis_test.go | 246 ++++++ e2e/testsuite/testconfig.go | 725 ++++++++++++++++++ .../controller/client/cli/tx.go | 38 +- .../controller/ibc_middleware_test.go | 381 ++++++++- .../controller/keeper/account.go | 6 +- .../controller/keeper/handshake.go | 139 +++- .../controller/keeper/handshake_test.go | 439 ++++++++++- .../controller/keeper/msg_server.go | 2 +- .../controller/keeper/msg_server_test.go | 4 + .../controller/types/msgs.go | 10 +- .../controller/types/msgs_test.go | 22 + .../controller/types/tx.pb.go | 91 +++ .../host/ibc_module_test.go | 12 +- .../host/keeper/handshake.go | 84 ++ .../host/keeper/handshake_test.go | 223 +++++- modules/apps/callbacks/callbacks_test.go | 13 +- .../controller/v1/tx.proto | 13 + 28 files changed, 4669 insertions(+), 53 deletions(-) create mode 100644 e2e/tests/core/04-channel/upgrades_test.go create mode 100644 e2e/tests/interchain_accounts/base_test.go create mode 100644 e2e/tests/interchain_accounts/gov_test.go create mode 100644 e2e/tests/interchain_accounts/groups_test.go create mode 100644 e2e/tests/interchain_accounts/incentivized_test.go create mode 100644 e2e/tests/interchain_accounts/localhost_test.go create mode 100644 e2e/tests/interchain_accounts/params_test.go create mode 100644 e2e/tests/upgrades/genesis_test.go create mode 100644 e2e/testsuite/testconfig.go diff --git a/docs/apps/interchain-accounts/active-channels.md b/docs/apps/interchain-accounts/active-channels.md index 61ab551582c..2d369a8dd55 100644 --- a/docs/apps/interchain-accounts/active-channels.md +++ b/docs/apps/interchain-accounts/active-channels.md @@ -4,7 +4,17 @@ order: 9 # Understanding Active Channels +<<<<<<< HEAD:docs/apps/interchain-accounts/active-channels.md The Interchain Accounts module uses [ORDERED channels](https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#ordering) to maintain the order of transactions when sending packets from a controller to a host chain. A limitation when using ORDERED channels is that when a packet times out the channel will be closed. +======= +The Interchain Accounts module uses either [ORDERED or UNORDERED](https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#ordering) channels. + +When using `ORDERED` channels, the order of transactions when sending packets from a controller to a host chain is maintained. + +When using `UNORDERED` channels, there is no guarantee that the order of transactions when sending packets from the controller to the host chain is maintained. + +> A limitation when using ORDERED channels is that when a packet times out the channel will be closed. +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)):docs/docs/02-apps/02-interchain-accounts/09-active-channels.md In the case of a channel closing, a controller chain needs to be able to regain access to the interchain account registered on this channel. `Active Channels` enable this functionality. diff --git a/docs/apps/interchain-accounts/client.md b/docs/apps/interchain-accounts/client.md index 09b2af7e8e0..48e24068282 100644 --- a/docs/apps/interchain-accounts/client.md +++ b/docs/apps/interchain-accounts/client.md @@ -34,6 +34,25 @@ The `tx` commands allow users to interact with the controller submodule. simd tx interchain-accounts controller --help ``` +#### `register` + +The `register` command allows users to register an interchain account on a host chain on the provided connection. + +```shell +simd tx interchain-accounts controller register [connection-id] [flags] +``` + +During registration a new channel is set up between controller and host. There are two flags available that influence the channel that is created: + +- `--version` to specify the (JSON-formatted) version string of the channel. For example: `{\"version\":\"ics27-1\",\"encoding\":\"proto3\",\"tx_type\":\"sdk_multi_msg\",\"controller_connection_id\":\"connection-0\",\"host_connection_id\":\"connection-0\"}`. Passing a custom version string is useful if you want to specify, for example, the encoding format of the interchain accounts packet data (either `proto3` or `proto3json`). If not specified the controller submodule will generate a default version string. +- `--ordering` to specify the ordering of the channel. Available options are `order_ordered` (default if not specified) and `order_unordered`. + +Example: + +```shell +simd tx interchain-accounts controller register connection-0 --ordering order_unordered --from cosmos1.. +``` + #### `send-tx` The `send-tx` command allows users to send a transaction on the provided connection to be executed using an interchain account on the host chain. diff --git a/docs/apps/interchain-accounts/messages.md b/docs/apps/interchain-accounts/messages.md index 1052f2b5081..c13a7a26930 100644 --- a/docs/apps/interchain-accounts/messages.md +++ b/docs/apps/interchain-accounts/messages.md @@ -13,6 +13,7 @@ type MsgRegisterInterchainAccount struct { Owner string ConnectionID string Version string + Order channeltypes.Order } ``` diff --git a/docs/apps/interchain-accounts/overview.md b/docs/apps/interchain-accounts/overview.md index 97133f15e94..c92dc1e02bb 100644 --- a/docs/apps/interchain-accounts/overview.md +++ b/docs/apps/interchain-accounts/overview.md @@ -30,4 +30,17 @@ SDK modules on a chain are assumed to be trustworthy. For example, there are no The implementation of ICS-27 in ibc-go uses this assumption in its security considerations. +<<<<<<< HEAD:docs/apps/interchain-accounts/overview.md The implementation assumes other IBC application modules will not bind to ports within the ICS-27 namespace. +======= +The implementation assumes other IBC application modules will not bind to ports within the ICS-27 namespace. + +## Channel Closure + +The provided interchain account host and controller implementations do not support `ChanCloseInit`. However, they do support `ChanCloseConfirm`. +This means that the host and controller modules cannot close channels, but they will confirm channel closures initiated by other implementations of ICS-27. + +In the event of a channel closing (due to a packet timeout in an ordered channel, for example), the interchain account associated with that channel can become accessible again if a new channel is created with a (JSON-formatted) version string that encodes the exact same `Metadata` information of the previous channel. The channel can be reopened using either [`MsgRegisterInterchainAccount`](./05-messages.md#msgregisterinterchainaccount) or `MsgChannelOpenInit`. If `MsgRegisterInterchainAccount` is used, then it is possible to leave the `version` field of the message empty, since it will be filled in by the controller submodule. If `MsgChannelOpenInit` is used, then the `version` field must be provided with the correct JSON-encoded `Metadata` string. See section [Understanding Active Channels](./09-active-channels.md#understanding-active-channels) for more information. + +When reopening a channel with the default controller submodule, the ordering of the channel cannot be changed. In order to change the ordering of the channel, the channel has to go through a [channel upgrade handshake](../../01-ibc/06-channel-upgrades.md) or reopen the channel with a custom controller implementation. +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)):docs/docs/02-apps/02-interchain-accounts/01-overview.md diff --git a/e2e/tests/core/04-channel/upgrades_test.go b/e2e/tests/core/04-channel/upgrades_test.go new file mode 100644 index 00000000000..b3cd671911a --- /dev/null +++ b/e2e/tests/core/04-channel/upgrades_test.go @@ -0,0 +1,328 @@ +//go:build !test_e2e + +package channel + +import ( + "context" + "testing" + + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +func TestChannelTestSuite(t *testing.T) { + testifysuite.Run(t, new(ChannelTestSuite)) +} + +type ChannelTestSuite struct { + testsuite.E2ETestSuite +} + +// TestChannelUpgrade_WithFeeMiddleware_Succeeds tests upgrading a transfer channel to wire up fee middleware +func (s *ChannelTestSuite) TestChannelUpgrade_WithFeeMiddleware_Succeeds() { + t := s.T() + ctx := context.TODO() + + relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions()) + channelB := channelA.Counterparty + chainA, chainB := s.GetChains() + + chainADenom := chainA.Config().Denom + chainBDenom := chainB.Config().Denom + chainAIBCToken := testsuite.GetIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID) + chainBIBCToken := testsuite.GetIBCToken(chainADenom, channelB.PortID, channelB.ChannelID) + + chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainAAddress := chainAWallet.FormattedAddress() + + chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + chainBAddress := chainBWallet.FormattedAddress() + + var ( + chainARelayerWallet, chainBRelayerWallet ibc.Wallet + relayerAStartingBalance int64 + testFee = testvalues.DefaultFee(chainADenom) + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") + + // trying to create some inflight packets, although they might get relayed before the upgrade starts + t.Run("create inflight transfer packets between chain A and chain B", func(t *testing.T) { + chainBWalletAmount := ibc.WalletAmount{ + Address: chainBWallet.FormattedAddress(), // destination address + Denom: chainADenom, + Amount: sdkmath.NewInt(testvalues.IBCTransferAmount), + } + + transferTxResp, err := chainA.SendIBCTransfer(ctx, channelA.ChannelID, chainAWallet.KeyName(), chainBWalletAmount, ibc.TransferOptions{}) + s.Require().NoError(err) + s.Require().NoError(transferTxResp.Validate(), "chain-a ibc transfer tx is invalid") + + chainAwalletAmount := ibc.WalletAmount{ + Address: chainAWallet.FormattedAddress(), // destination address + Denom: chainBDenom, + Amount: sdkmath.NewInt(testvalues.IBCTransferAmount), + } + + transferTxResp, err = chainB.SendIBCTransfer(ctx, channelB.ChannelID, chainBWallet.KeyName(), chainAwalletAmount, ibc.TransferOptions{}) + s.Require().NoError(err) + s.Require().NoError(transferTxResp.Validate(), "chain-b ibc transfer tx is invalid") + }) + + t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) { + chA, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + + s.initiateChannelUpgrade(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, s.createUpgradeFields(chA)) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") + + t.Run("packets are relayed between chain A and chain B", func(t *testing.T) { + // packet from chain A to chain B + s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) + actualBalance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom()) + s.Require().NoError(err) + expected := testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance.Int64()) + + // packet from chain B to chain A + s.AssertPacketRelayed(ctx, chainB, channelB.PortID, channelB.ChannelID, 1) + actualBalance, err = s.QueryBalance(ctx, chainA, chainAAddress, chainAIBCToken.IBCDenom()) + s.Require().NoError(err) + expected = testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance.Int64()) + }) + + t.Run("verify channel A upgraded and is fee enabled", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + + // check the channel version include the fee version + version, err := feetypes.MetadataFromVersion(channel.Version) + s.Require().NoError(err) + s.Require().Equal(feetypes.Version, version.FeeVersion, "the channel version did not include ics29") + + // extra check + feeEnabled, err := s.QueryFeeEnabledChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + s.Require().Equal(true, feeEnabled) + }) + + t.Run("verify channel B upgraded and is fee enabled", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainB, channelB.PortID, channelB.ChannelID) + s.Require().NoError(err) + + // check the channel version include the fee version + version, err := feetypes.MetadataFromVersion(channel.Version) + s.Require().NoError(err) + s.Require().Equal(feetypes.Version, version.FeeVersion, "the channel version did not include ics29") + + // extra check + feeEnabled, err := s.QueryFeeEnabledChannel(ctx, chainB, channelB.PortID, channelB.ChannelID) + s.Require().NoError(err) + s.Require().Equal(true, feeEnabled) + }) + + t.Run("prune packet acknowledgements", func(t *testing.T) { + // there should be one ack for the packet that we sent before the upgrade + acks, err := s.QueryPacketAcknowledgements(ctx, chainA, channelA.PortID, channelA.ChannelID, []uint64{}) + s.Require().NoError(err) + s.Require().Len(acks, 1) + s.Require().Equal(uint64(1), acks[0].Sequence) + + pruneAcksTxResponse := s.PruneAcknowledgements(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, uint64(1)) + s.AssertTxSuccess(pruneAcksTxResponse) + + // after pruning there should not be any acks + acks, err = s.QueryPacketAcknowledgements(ctx, chainA, channelA.PortID, channelA.ChannelID, []uint64{}) + s.Require().NoError(err) + s.Require().Empty(acks) + }) + + t.Run("stop relayer", func(t *testing.T) { + s.StopRelayer(ctx, relayer) + }) + + t.Run("recover relayer wallets", func(t *testing.T) { + err := s.RecoverRelayerWallets(ctx, relayer) + s.Require().NoError(err) + + chainARelayerWallet, chainBRelayerWallet, err = s.GetRelayerWallets(relayer) + s.Require().NoError(err) + + relayerAStartingBalance, err = s.GetChainANativeBalance(ctx, chainARelayerWallet) + s.Require().NoError(err) + t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") + + t.Run("register and verify counterparty payee", func(t *testing.T) { + _, chainBRelayerUser := s.GetRelayerUsers(ctx) + resp := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, chainBRelayerWallet.FormattedAddress(), chainARelayerWallet.FormattedAddress()) + s.AssertTxSuccess(resp) + + address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.FormattedAddress(), channelA.Counterparty.ChannelID) + s.Require().NoError(err) + s.Require().Equal(chainARelayerWallet.FormattedAddress(), address) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("send incentivized transfer packet", func(t *testing.T) { + // before adding fees for the packet, there should not be incentivized packets + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + s.Require().Empty(packets) + + transferAmount := testvalues.DefaultTransferAmount(chainA.Config().Denom) + + msgPayPacketFee := feetypes.NewMsgPayPacketFee(testFee, channelA.PortID, channelA.ChannelID, chainAWallet.FormattedAddress(), nil) + msgTransfer := transfertypes.NewMsgTransfer(channelA.PortID, channelA.ChannelID, transferAmount, chainAWallet.FormattedAddress(), chainBWallet.FormattedAddress(), s.GetTimeoutHeight(ctx, chainB), 0, "") + resp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgPayPacketFee, msgTransfer) + s.AssertTxSuccess(resp) + }) + + t.Run("packets are relayed", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + s.Require().Empty(packets) + }) + + t.Run("tokens are received by walletB", func(t *testing.T) { + actualBalance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom()) + s.Require().NoError(err) + + // walletB has received two IBC transfers of value testvalues.IBCTransferAmount since the start of the test. + expected := 2 * testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance.Int64()) + }) + + t.Run("timeout fee is refunded", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) + s.Require().NoError(err) + + // once the relayer has relayed the packets, the timeout fee should be refunded. + // walletA has done two IBC transfers of value testvalues.IBCTransferAmount since the start of the test. + expected := testvalues.StartingTokenAmount - (2 * testvalues.IBCTransferAmount) - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() + s.Require().Equal(expected, actualBalance) + }) + + t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerWallet) + s.Require().NoError(err) + + expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() + s.Require().Equal(expected, actualBalance) + }) +} + +// TestChannelUpgrade_WithFeeMiddleware_FailsWithTimeoutOnAck tests upgrading a transfer channel to wire up fee middleware but fails on ACK because of timeout +func (s *ChannelTestSuite) TestChannelUpgrade_WithFeeMiddleware_FailsWithTimeoutOnAck() { + t := s.T() + ctx := context.TODO() + + relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions()) + channelB := channelA.Counterparty + chainA, chainB := s.GetChains() + + chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") + + t.Run("execute gov proposal to set upgrade timeout", func(t *testing.T) { + s.setUpgradeTimeoutParam(ctx, chainB, chainBWallet) + }) + + t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) { + chA, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + + s.initiateChannelUpgrade(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, s.createUpgradeFields(chA)) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") + + t.Run("verify channel A did not upgrade", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.OPEN, channel.State, "the channel state is not OPEN") + s.Require().Equal(transfertypes.Version, channel.Version, "the channel version is not ics20-1") + + errorReceipt, err := s.QueryUpgradeError(ctx, chainA, channelA.PortID, channelA.ChannelID) + s.Require().NoError(err) + s.Require().Equal(uint64(1), errorReceipt.Sequence) + s.Require().Contains(errorReceipt.Message, "restored channel to pre-upgrade state") + }) + + t.Run("verify channel B did not upgrade", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainB, channelB.PortID, channelB.ChannelID) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.OPEN, channel.State, "the channel state is not OPEN") + s.Require().Equal(transfertypes.Version, channel.Version, "the channel version is not ics20-1") + + errorReceipt, err := s.QueryUpgradeError(ctx, chainB, channelB.PortID, channelB.ChannelID) + s.Require().NoError(err) + s.Require().Equal(uint64(1), errorReceipt.Sequence) + s.Require().Contains(errorReceipt.Message, "restored channel to pre-upgrade state") + }) +} + +// createUpgradeFields created the upgrade fields for channel +func (s *ChannelTestSuite) createUpgradeFields(channel channeltypes.Channel) channeltypes.UpgradeFields { + versionMetadata := feetypes.Metadata{ + FeeVersion: feetypes.Version, + AppVersion: transfertypes.Version, + } + versionBytes, err := feetypes.ModuleCdc.MarshalJSON(&versionMetadata) + s.Require().NoError(err) + + return channeltypes.NewUpgradeFields(channel.Ordering, channel.ConnectionHops, string(versionBytes)) +} + +// setUpgradeTimeoutParam creates and submits a governance proposal to execute the message to update 04-channel params with a timeout of 1s +func (s *ChannelTestSuite) setUpgradeTimeoutParam(ctx context.Context, chain ibc.Chain, wallet ibc.Wallet) { + const timeoutDelta = 1000000000 // use 1 second as relative timeout to force upgrade timeout on the counterparty + govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chain) + s.Require().NoError(err) + s.Require().NotNil(govModuleAddress) + + upgradeTimeout := channeltypes.NewTimeout(channeltypes.DefaultTimeout.Height, timeoutDelta) + msg := channeltypes.NewMsgUpdateChannelParams(govModuleAddress.String(), channeltypes.NewParams(upgradeTimeout)) + s.ExecuteAndPassGovV1Proposal(ctx, msg, chain, wallet) +} + +// initiateChannelUpgrade creates and submits a governance proposal to execute the message to initiate a channel upgrade +func (s *ChannelTestSuite) initiateChannelUpgrade(ctx context.Context, chain ibc.Chain, wallet ibc.Wallet, portID, channelID string, upgradeFields channeltypes.UpgradeFields) { + govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chain) + s.Require().NoError(err) + s.Require().NotNil(govModuleAddress) + + msg := channeltypes.NewMsgChannelUpgradeInit(portID, channelID, upgradeFields, govModuleAddress.String()) + s.ExecuteAndPassGovV1Proposal(ctx, msg, chain, wallet) +} diff --git a/e2e/tests/interchain_accounts/base_test.go b/e2e/tests/interchain_accounts/base_test.go new file mode 100644 index 00000000000..1199e0f35b8 --- /dev/null +++ b/e2e/tests/interchain_accounts/base_test.go @@ -0,0 +1,554 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +// orderMapping is a mapping from channel ordering to the string representation of the ordering. +// the representation can be different depending on the relayer implementation. +var orderMapping = map[channeltypes.Order][]string{ + channeltypes.ORDERED: {channeltypes.ORDERED.String(), "Ordered"}, + channeltypes.UNORDERED: {channeltypes.UNORDERED.String(), "Unordered"}, +} + +func TestInterchainAccountsTestSuite(t *testing.T) { + testifysuite.Run(t, new(InterchainAccountsTestSuite)) +} + +type InterchainAccountsTestSuite struct { + testsuite.E2ETestSuite +} + +// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain. +func (s *InterchainAccountsTestSuite) RegisterInterchainAccount(ctx context.Context, chain ibc.Chain, user ibc.Wallet, msgRegisterAccount *controllertypes.MsgRegisterInterchainAccount) { + txResp := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount) + s.AssertTxSuccess(txResp) +} + +func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer() { + s.testMsgSendTxSuccessfulTransfer(channeltypes.ORDERED) +} + +func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_UnorderedChannel() { + s.testMsgSendTxSuccessfulTransfer(channeltypes.UNORDERED) +} + +func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order channeltypes.Order) { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + var hostAccount string + + t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, order) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify interchain account", func(t *testing.T) { + var err error + hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(hostAccount)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) + icaChannel := channels[0] + s.Require().Contains(orderMapping[order], icaChannel.Ordering) + }) + + t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) { + t.Run("fund interchain account wallet", func(t *testing.T) { + // fund the host account so it has some $$ to send + err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + Address: hostAccount, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainB.Config().Denom, + }) + s.Require().NoError(err) + }) + + t.Run("broadcast MsgSendTx", func(t *testing.T) { + // assemble bank transfer message from host account to user account on host chain + msgSend := &banktypes.MsgSend{ + FromAddress: hostAccount, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + resp := s.BroadcastMessages( + ctx, + chainA, + controllerAccount, + msgSendTx, + ) + + s.AssertTxSuccess(resp) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + _, err = s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + }) +} + +func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientFunds() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + var hostAccount string + + t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify interchain account", func(t *testing.T) { + var err error + hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(hostAccount)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) + }) + + t.Run("fail to execute bank transfer over ICA", func(t *testing.T) { + t.Run("verify empty host wallet", func(t *testing.T) { + hostAccountBalance, err := s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom) + + s.Require().NoError(err) + s.Require().Zero(hostAccountBalance.Int64()) + }) + + t.Run("broadcast MsgSendTx", func(t *testing.T) { + // assemble bank transfer message from host account to user account on host chain + msgSend := &banktypes.MsgSend{ + FromAddress: hostAccount, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp := s.BroadcastMessages( + ctx, + chainA, + controllerAccount, + msgSendTx, + ) + + s.AssertTxSuccess(txResp) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) + }) + + t.Run("verify balance is the same", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + }) +} + +func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReopeningICA() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + var ( + portID string + hostAccount string + + initialChannelID = "channel-1" + channelIDAfterReopening = "channel-2" + ) + + t.Run("register interchain account", func(t *testing.T) { + var err error + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) + s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount) + portID, err = icatypes.NewControllerPortID(controllerAddress) + s.Require().NoError(err) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify interchain account", func(t *testing.T) { + var err error + hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(hostAccount)) + + _, err = s.QueryChannel(ctx, chainA, portID, initialChannelID) + s.Require().NoError(err) + }) + + // stop the relayer to let the submit tx message time out + t.Run("stop relayer", func(t *testing.T) { + s.StopRelayer(ctx, relayer) + }) + + t.Run("submit tx message with bank transfer message times out", func(t *testing.T) { + t.Run("fund interchain account wallet", func(t *testing.T) { + // fund the host account account so it has some $$ to send + err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + Address: hostAccount, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainB.Config().Denom, + }) + s.Require().NoError(err) + }) + + t.Run("broadcast MsgSendTx", func(t *testing.T) { + // assemble bank transfer message from host account to user account on host chain + msgSend := &banktypes.MsgSend{ + FromAddress: hostAccount, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(1), packetData) + + resp := s.BroadcastMessages( + ctx, + chainA, + controllerAccount, + msgSendTx, + ) + + s.AssertTxSuccess(resp) + + // this sleep is to allow the packet to timeout + time.Sleep(1 * time.Second) + }) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify channel is closed due to timeout on ordered channel", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainA, portID, initialChannelID) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.CLOSED, channel.State, "the channel was not in an expected state") + }) + + t.Run("verify tokens not transferred", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + _, err = s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + + // re-register interchain account to reopen the channel now that it has been closed due to timeout + // on an ordered channel + t.Run("register interchain account", func(t *testing.T) { + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) + s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) + }) + + t.Run("verify new channel is now open and interchain account has been reregistered with the same portID", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainA, portID, channelIDAfterReopening) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.OPEN, channel.State, "the channel was not in an expected state") + }) + + t.Run("broadcast MsgSendTx", func(t *testing.T) { + // assemble bank transfer message from host account to user account on host chain + msgSend := &banktypes.MsgSend{ + FromAddress: hostAccount, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(5*time.Minute), packetData) + + resp := s.BroadcastMessages( + ctx, + chainA, + controllerAccount, + msgSendTx, + ) + + s.AssertTxSuccess(resp) + + // time for the packet to be relayed + s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB)) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) +} + +/* +TODO: uncomment when hermes works with upgrades, https://github.com/cosmos/ibc-go/issues/5644 +func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterUpgradingOrdertoUnordered() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, _ := s.GetChains() + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + // chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + var ( + portID string + hostAccount string + + initialChannelID = "channel-1" + ) + + t.Run("register interchain account", func(t *testing.T) { + var err error + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) + s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount) + portID, err = icatypes.NewControllerPortID(controllerAddress) + s.Require().NoError(err) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify interchain account", func(t *testing.T) { + var err error + hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(hostAccount)) + + _, err = s.QueryChannel(ctx, chainA, portID, initialChannelID) + s.Require().NoError(err) + }) + + // t.Run("fund interchain account wallet", func(t *testing.T) { + // // fund the host account account so it has some $$ to send + // err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + // Address: hostAccount, + // Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + // Denom: chainB.Config().Denom, + // }) + // s.Require().NoError(err) + // }) + + // t.Run("broadcast MsgSendTx", func(t *testing.T) { + // // assemble bank transfer message from host account to user account on host chain + // msgSend := &banktypes.MsgSend{ + // FromAddress: hostAccount, + // ToAddress: chainBAccount.FormattedAddress(), + // Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + // } + + // cdc := testsuite.Codec() + + // bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + // s.Require().NoError(err) + + // packetData := icatypes.InterchainAccountPacketData{ + // Type: icatypes.EXECUTE_TX, + // Data: bz, + // Memo: "e2e", + // } + + // msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(5*time.Minute), packetData) + + // resp := s.BroadcastMessages( + // ctx, + // chainA, + // controllerAccount, + // msgSendTx, + // ) + + // s.AssertTxSuccess(resp) + + // // time for the packet to be relayed + // s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB)) + // }) + + // t.Run("verify tokens transferred", func(t *testing.T) { + // balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + // s.Require().NoError(err) + + // expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + // s.Require().Equal(expected, balance.Int64()) + // }) + + channel, err := s.QueryChannel(ctx, chainA, portID, initialChannelID) + s.Require().NoError(err) + + // upgrade the channel ordering to UNORDERED + upgradeFields := channeltypes.NewUpgradeFields(channeltypes.UNORDERED, channel.ConnectionHops, channel.Version) + + t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) { + govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA) + s.Require().NoError(err) + s.Require().NotNil(govModuleAddress) + + msg := channeltypes.NewMsgChannelUpgradeInit(portID, initialChannelID, upgradeFields, govModuleAddress.String()) + s.ExecuteAndPassGovV1Proposal(ctx, msg, chainA, controllerAccount) + }) + + t.Run("verify channel A upgraded and is now unordered", func(t *testing.T) { + var channel channeltypes.Channel + waitErr := test.WaitForCondition(time.Minute*2, time.Second*5, func() (bool, error) { + channel, err = s.QueryChannel(ctx, chainA, portID, initialChannelID) + if err != nil { + return false, err + } + return channel.Ordering == channeltypes.UNORDERED, nil + }) + s.Require().NoErrorf(waitErr, "channel was not upgraded: expected %s got %s", channeltypes.UNORDERED, channel.Ordering) + }) +} +*/ diff --git a/e2e/tests/interchain_accounts/gov_test.go b/e2e/tests/interchain_accounts/gov_test.go new file mode 100644 index 00000000000..212b5d173f4 --- /dev/null +++ b/e2e/tests/interchain_accounts/gov_test.go @@ -0,0 +1,122 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func TestInterchainAccountsGovTestSuite(t *testing.T) { + testifysuite.Run(t, new(InterchainAccountsGovTestSuite)) +} + +type InterchainAccountsGovTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *InterchainAccountsGovTestSuite) TestInterchainAccountsGovIntegration() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + chainBAddress := chainBAccount.FormattedAddress() + + govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA) + s.Require().NoError(err) + s.Require().NotNil(govModuleAddress) + + t.Run("execute proposal for MsgRegisterInterchainAccount", func(t *testing.T) { + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, govModuleAddress.String(), version, channeltypes.ORDERED) + s.ExecuteAndPassGovV1Proposal(ctx, msgRegisterAccount, chainA, controllerAccount) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) + + var interchainAccAddr string + t.Run("verify interchain account registration success", func(t *testing.T) { + var err error + interchainAccAddr, err = s.QueryInterchainAccount(ctx, chainA, govModuleAddress.String(), ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddr)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) + }) + + t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) { + t.Run("fund interchain account wallet", func(t *testing.T) { + // fund the host account, so it has some $$ to send + err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + Address: interchainAccAddr, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainB.Config().Denom, + }) + s.Require().NoError(err) + }) + + t.Run("execute proposal for MsgSendTx", func(t *testing.T) { + msgBankSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddr, + ToAddress: chainBAddress, + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(govModuleAddress.String(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + s.ExecuteAndPassGovV1Proposal(ctx, msgSendTx, chainA, controllerAccount) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + _, err = s.QueryBalance(ctx, chainB, interchainAccAddr, chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + }) +} diff --git a/e2e/tests/interchain_accounts/groups_test.go b/e2e/tests/interchain_accounts/groups_test.go new file mode 100644 index 00000000000..43faca17a3f --- /dev/null +++ b/e2e/tests/interchain_accounts/groups_test.go @@ -0,0 +1,215 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + interchaintest "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + grouptypes "github.com/cosmos/cosmos-sdk/x/group" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +const ( + // DefaultGroupMemberWeight is the members voting weight. + // A group members weight is used in the sum of `YES` votes required to meet a decision policy threshold. + DefaultGroupMemberWeight = "1" + + // DefaultGroupThreshold is the minimum weighted sum of `YES` votes that must be met or + // exceeded for a proposal to succeed. + DefaultGroupThreshold = "1" + + // DefaultMetadata defines a reusable metadata string for testing purposes + DefaultMetadata = "custom metadata" + + // DefaultMinExecutionPeriod is the minimum duration after the proposal submission + // where members can start sending MsgExec. This means that the window for + // sending a MsgExec transaction is: + // `[ submission + min_execution_period ; submission + voting_period + max_execution_period]` + // where max_execution_period is a app-specific config, defined in the keeper. + // If not set, min_execution_period will default to 0. + DefaultMinExecutionPeriod = time.Duration(0) + + // DefaultVotingPeriod is the duration from submission of a proposal to the end of voting period + // Within this times votes can be submitted with MsgVote. + DefaultVotingPeriod = time.Minute + + // InitialGroupID is the first group ID generated by x/group + InitialGroupID = 1 + + // InitialProposalID is the first group proposal ID generated by x/group + InitialProposalID = 1 +) + +func TestInterchainAccountsGroupsTestSuite(t *testing.T) { + testifysuite.Run(t, new(InterchainAccountsGroupsTestSuite)) +} + +type InterchainAccountsGroupsTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *InterchainAccountsGroupsTestSuite) QueryGroupPolicyAddress(ctx context.Context, chain ibc.Chain) string { + queryClient := s.GetChainGRCPClients(chain).GroupsQueryClient + res, err := queryClient.GroupPoliciesByGroup(ctx, &grouptypes.QueryGroupPoliciesByGroupRequest{ + GroupId: InitialGroupID, // always use the initial group id + }) + s.Require().NoError(err) + + return res.GroupPolicies[0].Address +} + +func (s *InterchainAccountsGroupsTestSuite) TestInterchainAccountsGroupsIntegration() { + t := s.T() + ctx := context.TODO() + + var ( + groupPolicyAddr string + interchainAccAddr string + err error + ) + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainAAddress := chainAWallet.FormattedAddress() + + chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + chainBAddress := chainBWallet.FormattedAddress() + + t.Run("create group with new threshold decision policy", func(t *testing.T) { + members := []grouptypes.MemberRequest{ + { + Address: chainAAddress, + Weight: DefaultGroupMemberWeight, + }, + } + + decisionPolicy := grouptypes.NewThresholdDecisionPolicy(DefaultGroupThreshold, DefaultVotingPeriod, DefaultMinExecutionPeriod) + msgCreateGroupWithPolicy, err := grouptypes.NewMsgCreateGroupWithPolicy(chainAAddress, members, DefaultMetadata, DefaultMetadata, true, decisionPolicy) + s.Require().NoError(err) + + txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgCreateGroupWithPolicy) + s.AssertTxSuccess(txResp) + }) + + t.Run("submit proposal for MsgRegisterInterchainAccount", func(t *testing.T) { + groupPolicyAddr = s.QueryGroupPolicyAddress(ctx, chainA) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, groupPolicyAddr, icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID), channeltypes.ORDERED) + + msgSubmitProposal, err := grouptypes.NewMsgSubmitProposal(groupPolicyAddr, []string{chainAAddress}, []sdk.Msg{msgRegisterAccount}, DefaultMetadata, grouptypes.Exec_EXEC_UNSPECIFIED, "e2e groups proposal: for MsgRegisterInterchainAccount", "e2e groups proposal: for MsgRegisterInterchainAccount") + s.Require().NoError(err) + + txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgSubmitProposal) + s.AssertTxSuccess(txResp) + }) + + t.Run("vote and exec proposal", func(t *testing.T) { + msgVote := &grouptypes.MsgVote{ + ProposalId: InitialProposalID, + Voter: chainAAddress, + Option: grouptypes.VOTE_OPTION_YES, + Exec: grouptypes.Exec_EXEC_TRY, + } + + txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgVote) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify interchain account registration success", func(t *testing.T) { + interchainAccAddr, err = s.QueryInterchainAccount(ctx, chainA, groupPolicyAddr, ibctesting.FirstConnectionID) + s.Require().NotEmpty(interchainAccAddr) + s.Require().NoError(err) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) // 1 transfer (created by default), 1 interchain-accounts + }) + + t.Run("fund interchain account wallet", func(t *testing.T) { + err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + Address: interchainAccAddr, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainB.Config().Denom, + }) + s.Require().NoError(err) + }) + + t.Run("submit proposal for MsgSendTx", func(t *testing.T) { + msgBankSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddr, + ToAddress: chainBAddress, + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSubmitTx := controllertypes.NewMsgSendTx(groupPolicyAddr, ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + msgSubmitProposal, err := grouptypes.NewMsgSubmitProposal(groupPolicyAddr, []string{chainAAddress}, []sdk.Msg{msgSubmitTx}, DefaultMetadata, grouptypes.Exec_EXEC_UNSPECIFIED, "e2e groups proposal: for MsgRegisterInterchainAccount", "e2e groups proposal: for MsgRegisterInterchainAccount") + s.Require().NoError(err) + + txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgSubmitProposal) + s.AssertTxSuccess(txResp) + }) + + t.Run("vote and exec proposal", func(t *testing.T) { + msgVote := &grouptypes.MsgVote{ + ProposalId: InitialProposalID + 1, + Voter: chainAAddress, + Option: grouptypes.VOTE_OPTION_YES, + Exec: grouptypes.Exec_EXEC_TRY, + } + + txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgVote) + s.AssertTxSuccess(txResp) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") + balance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainB.Config().Denom) + + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + + balance, err = s.QueryBalance(ctx, chainB, interchainAccAddr, chainB.Config().Denom) + s.Require().NoError(err) + + expected = testvalues.StartingTokenAmount - testvalues.IBCTransferAmount + s.Require().Equal(expected, balance.Int64()) + }) +} diff --git a/e2e/tests/interchain_accounts/incentivized_test.go b/e2e/tests/interchain_accounts/incentivized_test.go new file mode 100644 index 00000000000..309a8e92b8f --- /dev/null +++ b/e2e/tests/interchain_accounts/incentivized_test.go @@ -0,0 +1,383 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + interchaintest "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func TestIncentivizedInterchainAccountsTestSuite(t *testing.T) { + testifysuite.Run(t, new(IncentivizedInterchainAccountsTestSuite)) +} + +type IncentivizedInterchainAccountsTestSuite struct { + InterchainAccountsTestSuite +} + +func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_SuccessfulBankSend_Incentivized() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + var ( + chainADenom = chainA.Config().Denom + interchainAcc = "" + testFee = testvalues.DefaultFee(chainADenom) + ) + + t.Run("relayer wallets recovered", func(t *testing.T) { + err := s.RecoverRelayerWallets(ctx, relayer) + s.Require().NoError(err) + }) + + chainARelayerWallet, chainBRelayerWallet, err := s.GetRelayerWallets(relayer) + t.Run("relayer wallets fetched", func(t *testing.T) { + s.Require().NoError(err) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") + + chainARelayerUser, chainBRelayerUser := s.GetRelayerUsers(ctx) + relayerAStartingBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) + s.Require().NoError(err) + t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) + + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + version := "" // allow version to be specified by the controller chain since both chains should support incentivized channels + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + var channelOutput ibc.ChannelOutput + t.Run("verify interchain account", func(t *testing.T) { + var err error + interchainAcc, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAcc)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) + + // interchain accounts channel at index: 0 + channelOutput = channels[0] + + s.Require().NoError(test.WaitForBlocks(ctx, 2, chainA, chainB)) + }) + + t.Run("execute interchain account bank send through controller", func(t *testing.T) { + t.Run("fund interchain account wallet on host chainB", func(t *testing.T) { + // fund the interchain account so it has some $$ to send + err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + Address: interchainAcc, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainB.Config().Denom, + }) + s.Require().NoError(err) + }) + + t.Run("register counterparty payee", func(t *testing.T) { + resp := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelOutput.Counterparty.PortID, channelOutput.Counterparty.ChannelID, chainBRelayerWallet.FormattedAddress(), chainARelayerWallet.FormattedAddress()) + s.AssertTxSuccess(resp) + }) + + t.Run("verify counterparty payee", func(t *testing.T) { + address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.FormattedAddress(), channelOutput.Counterparty.ChannelID) + s.Require().NoError(err) + s.Require().Equal(chainARelayerWallet.FormattedAddress(), address) + }) + + t.Run("no incentivized packets", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) + s.Require().NoError(err) + s.Require().Empty(packets) + }) + + t.Run("stop relayer", func(t *testing.T) { + s.StopRelayer(ctx, relayer) + }) + + t.Run("broadcast incentivized MsgSendTx", func(t *testing.T) { + msgPayPacketFee := &feetypes.MsgPayPacketFee{ + Fee: testvalues.DefaultFee(chainADenom), + SourcePortId: channelOutput.PortID, + SourceChannelId: channelOutput.ChannelID, + Signer: controllerAccount.FormattedAddress(), + } + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAcc, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + resp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgPayPacketFee, msgSendTx) + s.AssertTxSuccess(resp) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB)) + }) + + t.Run("there should be incentivized packets", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) + s.Require().NoError(err) + s.Require().Len(packets, 1) + actualFee := packets[0].PacketFees[0].Fee + + s.Require().True(actualFee.RecvFee.Equal(testFee.RecvFee)) + s.Require().True(actualFee.AckFee.Equal(testFee.AckFee)) + s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee)) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("packets are relayed", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) + s.Require().NoError(err) + s.Require().Empty(packets) + }) + + t.Run("verify interchain account sent tokens", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + _, err = s.QueryBalance(ctx, chainB, interchainAcc, chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + + t.Run("timeout fee is refunded", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, controllerAccount) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() + s.Require().Equal(expected, actualBalance) + }) + + t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) + s.Require().NoError(err) + + expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() + s.Require().Equal(expected, actualBalance) + }) + }) +} + +func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_FailedBankSend_Incentivized() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + var ( + chainADenom = chainA.Config().Denom + interchainAcc = "" + testFee = testvalues.DefaultFee(chainADenom) + ) + + t.Run("relayer wallets recovered", func(t *testing.T) { + err := s.RecoverRelayerWallets(ctx, relayer) + s.Require().NoError(err) + }) + + chainARelayerWallet, chainBRelayerWallet, err := s.GetRelayerWallets(relayer) + t.Run("relayer wallets fetched", func(t *testing.T) { + s.Require().NoError(err) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") + + chainARelayerUser, chainBRelayerUser := s.GetRelayerUsers(ctx) + relayerAStartingBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) + s.Require().NoError(err) + t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) + + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + version := "" // allow version to be specified by the controller chain since both chains should support incentivized channels + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + var channelOutput ibc.ChannelOutput + t.Run("verify interchain account", func(t *testing.T) { + var err error + interchainAcc, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAcc)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) + + // interchain accounts channel at index: 0 + channelOutput = channels[0] + + s.Require().NoError(test.WaitForBlocks(ctx, 2, chainA, chainB)) + }) + + t.Run("execute interchain account bank send through controller", func(t *testing.T) { + t.Run("register counterparty payee", func(t *testing.T) { + resp := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelOutput.Counterparty.PortID, channelOutput.Counterparty.ChannelID, chainBRelayerWallet.FormattedAddress(), chainARelayerWallet.FormattedAddress()) + s.AssertTxSuccess(resp) + }) + + t.Run("verify counterparty payee", func(t *testing.T) { + address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.FormattedAddress(), channelOutput.Counterparty.ChannelID) + s.Require().NoError(err) + s.Require().Equal(chainARelayerWallet.FormattedAddress(), address) + }) + + t.Run("no incentivized packets", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) + s.Require().NoError(err) + s.Require().Empty(packets) + }) + + t.Run("stop relayer", func(t *testing.T) { + err := relayer.StopRelayer(ctx, s.GetRelayerExecReporter()) + s.Require().NoError(err) + }) + + t.Run("broadcast incentivized MsgSendTx", func(t *testing.T) { + msgPayPacketFee := &feetypes.MsgPayPacketFee{ + Fee: testvalues.DefaultFee(chainADenom), + SourcePortId: channelOutput.PortID, + SourceChannelId: channelOutput.ChannelID, + Signer: controllerAccount.FormattedAddress(), + } + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAcc, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + resp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgPayPacketFee, msgSendTx) + s.AssertTxSuccess(resp) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB)) + }) + + t.Run("there should be incentivized packets", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) + s.Require().NoError(err) + s.Require().Len(packets, 1) + actualFee := packets[0].PacketFees[0].Fee + + s.Require().True(actualFee.RecvFee.Equal(testFee.RecvFee)) + s.Require().True(actualFee.AckFee.Equal(testFee.AckFee)) + s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee)) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("packets are relayed", func(t *testing.T) { + packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) + s.Require().NoError(err) + s.Require().Empty(packets) + }) + + t.Run("verify interchain account did not send tokens", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + _, err = s.QueryBalance(ctx, chainB, interchainAcc, chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64(), "tokens should not have been sent as interchain account was not funded") + }) + + t.Run("timeout fee is refunded", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, controllerAccount) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() + s.Require().Equal(expected, actualBalance) + }) + + t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) + s.Require().NoError(err) + + expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() + s.Require().Equal(expected, actualBalance) + }) + }) +} diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go new file mode 100644 index 00000000000..d486041de2e --- /dev/null +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -0,0 +1,477 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v8/modules/core/exported" + localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func TestInterchainAccountsLocalhostTestSuite(t *testing.T) { + testifysuite.Run(t, new(LocalhostInterchainAccountsTestSuite)) +} + +type LocalhostInterchainAccountsTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { + t := s.T() + ctx := context.TODO() + + _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, _ := s.GetChains() + + chainADenom := chainA.Config().Denom + + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte + packet channeltypes.Packet + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + version := icatypes.NewDefaultMetadataString(exported.LocalhostConnectionID, exported.LocalhostConnectionID) + controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) + s.Require().NoError(err) + + t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.AssertTxSuccess(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, + controllerPortID, msgChanOpenInitRes.ChannelId, + version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.AssertTxSuccess(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.ChannelId, + msgChanOpenTryRes.ChannelId, msgChanOpenTryRes.Version, + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.AssertTxSuccess(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.ChannelId, + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.AssertTxSuccess(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + walletAmount := ibc.WalletAmount{ + Address: interchainAccAddress, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainADenom, + } + + s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) + }) + + t.Run("send packet localhost interchain accounts", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertTxSuccess(txResp) + + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("recv packet localhost interchain accounts", func(t *testing.T) { + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.AssertTxSuccess(txResp) + + ack, err = ibctesting.ParseAckFromEvents(txResp.Events) + s.Require().NoError(err) + s.Require().NotNil(ack) + }) + + t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.AssertTxSuccess(txResp) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := s.QueryBalance(ctx, chainA, userBWallet.FormattedAddress(), chainADenom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) +} + +func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChannel_Localhost() { + t := s.T() + ctx := context.TODO() + + // relayer and channel output is discarded, only a single chain is required + _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, _ := s.GetChains() + + chainADenom := chainA.Config().Denom + + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte + packet channeltypes.Packet + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + version := icatypes.NewDefaultMetadataString(exported.LocalhostConnectionID, exported.LocalhostConnectionID) + controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) + s.Require().NoError(err) + + t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.AssertTxSuccess(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, + controllerPortID, msgChanOpenInitRes.ChannelId, + version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.AssertTxSuccess(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.ChannelId, + msgChanOpenTryRes.ChannelId, msgChanOpenTryRes.Version, + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.AssertTxSuccess(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.ChannelId, + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.AssertTxSuccess(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + walletAmount := ibc.WalletAmount{ + Address: interchainAccAddress, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainADenom, + } + + s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) + }) + + t.Run("send localhost interchain accounts packet with timeout", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(1), packetData) + + txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertTxSuccess(txResp) + + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("timeout localhost interchain accounts packet", func(t *testing.T) { + msgTimeout := channeltypes.NewMsgTimeout(packet, 1, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgTimeout) + s.AssertTxSuccess(txResp) + }) + + t.Run("close interchain accounts host channel end", func(t *testing.T) { + // Pass in zero for counterpartyUpgradeSequence given that channel has not undergone any upgrades. + msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), 0) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgCloseConfirm) + s.AssertTxSuccess(txResp) + }) + + t.Run("verify localhost interchain accounts channel is closed", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.CLOSED, channelEndA.State, "the channel was not in an expected state") + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) + s.Require().NoError(err) + + s.Require().Equal(channeltypes.CLOSED, channelEndB.State, "the channel was not in an expected state") + }) + + t.Run("channel open init localhost: create new channel for existing account", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.AssertTxSuccess(txResp) + + // note: response values are updated here in msgChanOpenInitRes + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, + controllerPortID, msgChanOpenInitRes.ChannelId, + version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.AssertTxSuccess(txResp) + + // note: response values are updated here in msgChanOpenTryRes + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.ChannelId, + msgChanOpenTryRes.ChannelId, msgChanOpenTryRes.Version, + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.AssertTxSuccess(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.ChannelId, + localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.AssertTxSuccess(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) + + t.Run("verify interchain account and existing balance", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + balance, err := s.QueryBalance(ctx, chainA, interchainAccAddress, chainADenom) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + + t.Run("send packet localhost interchain accounts", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertTxSuccess(txResp) + + packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("recv packet localhost interchain accounts", func(t *testing.T) { + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.AssertTxSuccess(txResp) + + ack, err = ibctesting.ParseAckFromEvents(txResp.Events) + s.Require().NoError(err) + s.Require().NotNil(ack) + }) + + t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.AssertTxSuccess(txResp) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId, 1) + + balance, err := s.QueryBalance(ctx, chainA, userBWallet.FormattedAddress(), chainADenom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) +} diff --git a/e2e/tests/interchain_accounts/params_test.go b/e2e/tests/interchain_accounts/params_test.go new file mode 100644 index 00000000000..4cdc64fa371 --- /dev/null +++ b/e2e/tests/interchain_accounts/params_test.go @@ -0,0 +1,152 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "testing" + + "github.com/strangelove-ventures/interchaintest/v8/ibc" + testifysuite "github.com/stretchr/testify/suite" + + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + hosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func TestInterchainAccountsParamsTestSuite(t *testing.T) { + testifysuite.Run(t, new(InterchainAccountsParamsTestSuite)) +} + +type InterchainAccountsParamsTestSuite struct { + testsuite.E2ETestSuite +} + +// QueryControllerParams queries the params for the controller +func (s *InterchainAccountsParamsTestSuite) QueryControllerParams(ctx context.Context, chain ibc.Chain) controllertypes.Params { + queryClient := s.GetChainGRCPClients(chain).ICAControllerQueryClient + res, err := queryClient.Params(ctx, &controllertypes.QueryParamsRequest{}) + s.Require().NoError(err) + + return *res.Params +} + +// QueryHostParams queries the host chain for the params +func (s *InterchainAccountsParamsTestSuite) QueryHostParams(ctx context.Context, chain ibc.Chain) hosttypes.Params { + queryClient := s.GetChainGRCPClients(chain).ICAHostQueryClient + res, err := queryClient.Params(ctx, &hosttypes.QueryParamsRequest{}) + s.Require().NoError(err) + + return *res.Params +} + +// TestControllerEnabledParam tests that changing the ControllerEnabled param works as expected +func (s *InterchainAccountsParamsTestSuite) TestControllerEnabledParam() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, _ := s.GetChains() + chainAVersion := chainA.Config().Images[0].Version + + // setup controller account on chainA + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + + t.Run("ensure the controller is enabled", func(t *testing.T) { + params := s.QueryControllerParams(ctx, chainA) + s.Require().True(params.ControllerEnabled) + }) + + t.Run("disable the controller", func(t *testing.T) { + if testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion) { + authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA) + s.Require().NoError(err) + s.Require().NotNil(authority) + + msg := controllertypes.MsgUpdateParams{ + Signer: authority.String(), + Params: controllertypes.NewParams(false), + } + s.ExecuteAndPassGovV1Proposal(ctx, &msg, chainA, controllerAccount) + } else { + changes := []paramsproposaltypes.ParamChange{ + paramsproposaltypes.NewParamChange(controllertypes.StoreKey, string(controllertypes.KeyControllerEnabled), "false"), + } + + proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes) + s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainA, controllerAccount, proposal) + } + }) + + t.Run("ensure controller is disabled", func(t *testing.T) { + params := s.QueryControllerParams(ctx, chainA) + s.Require().False(params.ControllerEnabled) + }) + + t.Run("ensure that broadcasting a MsgRegisterInterchainAccount fails", func(t *testing.T) { + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxFailure(txResp, controllertypes.ErrControllerSubModuleDisabled) + }) +} + +func (s *InterchainAccountsParamsTestSuite) TestHostEnabledParam() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) + _, chainB := s.GetChains() + chainBVersion := chainB.Config().Images[0].Version + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + chainBUser := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + // Assert that default value for enabled is true. + t.Run("ensure the host is enabled", func(t *testing.T) { + params := s.QueryHostParams(ctx, chainB) + s.Require().True(params.HostEnabled) + s.Require().Equal([]string{hosttypes.AllowAllHostMsgs}, params.AllowMessages) + }) + + t.Run("disable the host", func(t *testing.T) { + if testvalues.SelfParamsFeatureReleases.IsSupported(chainBVersion) { + authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainB) + s.Require().NoError(err) + s.Require().NotNil(authority) + + msg := hosttypes.MsgUpdateParams{ + Signer: authority.String(), + Params: hosttypes.NewParams(false, []string{hosttypes.AllowAllHostMsgs}), + } + s.ExecuteAndPassGovV1Proposal(ctx, &msg, chainB, chainBUser) + } else { + changes := []paramsproposaltypes.ParamChange{ + paramsproposaltypes.NewParamChange(hosttypes.StoreKey, string(hosttypes.KeyHostEnabled), "false"), + } + + proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes) + s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainB, chainBUser, proposal) + } + }) + + t.Run("ensure the host is disabled", func(t *testing.T) { + params := s.QueryHostParams(ctx, chainB) + s.Require().False(params.HostEnabled) + }) +} diff --git a/e2e/tests/upgrades/genesis_test.go b/e2e/tests/upgrades/genesis_test.go new file mode 100644 index 00000000000..4b387bb128b --- /dev/null +++ b/e2e/tests/upgrades/genesis_test.go @@ -0,0 +1,246 @@ +//go:build !test_e2e + +package upgrades + +import ( + "context" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + "github.com/strangelove-ventures/interchaintest/v8" + cosmos "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + test "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/suite" + "go.uber.org/zap" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func TestGenesisTestSuite(t *testing.T) { + suite.Run(t, new(GenesisTestSuite)) +} + +type GenesisTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *GenesisTestSuite) TestIBCGenesis() { + t := s.T() + + configFileOverrides := make(map[string]any) + appTomlOverrides := make(test.Toml) + + appTomlOverrides["halt-height"] = haltHeight + configFileOverrides["config/app.toml"] = appTomlOverrides + chainOpts := func(options *testsuite.ChainOptions) { + options.ChainASpec.ConfigFileOverrides = configFileOverrides + } + + // create chains with specified chain configuration options + chainA, chainB := s.GetChains(chainOpts) + + ctx := context.Background() + relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, nil) + var ( + chainADenom = chainA.Config().Denom + chainBIBCToken = testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID) // IBC token sent to chainB + + ) + + chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainAAddress := chainAWallet.FormattedAddress() + + chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + chainBAddress := chainBWallet.FormattedAddress() + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") + + t.Run("ics20: native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) { + transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "") + s.AssertTxSuccess(transferTxResp) + }) + + t.Run("ics20: tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + var hostAccount string + + t.Run("ics27: broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("ics20: packets are relayed", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) + + actualBalance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom()) + + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance.Int64()) + }) + + t.Run("ics27: verify interchain account", func(t *testing.T) { + var err error + hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(hostAccount)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Equal(len(channels), 2) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") + + t.Run("Halt chain and export genesis", func(t *testing.T) { + s.HaltChainAndExportGenesis(ctx, chainA.(*cosmos.CosmosChain), relayer, int64(haltHeight)) + }) + + t.Run("ics20: native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) { + transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "") + s.AssertTxSuccess(transferTxResp) + }) + + t.Run("ics20: tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - 2*testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) + + t.Run("ics27: interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) { + t.Run("fund interchain account wallet", func(t *testing.T) { + // fund the host account so it has some $$ to send + err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ + Address: hostAccount, + Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), + Denom: chainB.Config().Denom, + }) + s.Require().NoError(err) + }) + + t.Run("broadcast MsgSendTx", func(t *testing.T) { + // assemble bank transfer message from host account to user account on host chain + msgSend := &banktypes.MsgSend{ + FromAddress: hostAccount, + ToAddress: chainBAccount.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + resp := s.BroadcastMessages( + ctx, + chainA, + controllerAccount, + msgSendTx, + ) + + s.AssertTxSuccess(resp) + + s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) + }) + }) + + s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") +} + +func (s *GenesisTestSuite) HaltChainAndExportGenesis(ctx context.Context, chain *cosmos.CosmosChain, relayer ibc.Relayer, haltHeight int64) { + timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Minute*2) + defer timeoutCtxCancel() + + err := test.WaitForBlocks(timeoutCtx, int(haltHeight), chain) + s.Require().Error(err, "chain did not halt at halt height") + + err = chain.StopAllNodes(ctx) + s.Require().NoError(err, "error stopping node(s)") + + state, err := chain.ExportState(ctx, haltHeight) + s.Require().NoError(err) + + appTomlOverrides := make(test.Toml) + + appTomlOverrides["halt-height"] = 0 + + for _, node := range chain.Nodes() { + err := node.OverwriteGenesisFile(ctx, []byte(state)) + s.Require().NoError(err) + } + + for _, node := range chain.Nodes() { + err := test.ModifyTomlConfigFile( + ctx, + zap.NewExample(), + node.DockerClient, + node.TestName, + node.VolumeName, + "config/app.toml", + appTomlOverrides, + ) + s.Require().NoError(err) + + _, _, err = node.ExecBin(ctx, "comet", "unsafe-reset-all") + s.Require().NoError(err) + } + + err = chain.StartAllNodes(ctx) + s.Require().NoError(err) + + // we are reinitializing the clients because we need to update the hostGRPCAddress after + // the upgrade and subsequent restarting of nodes + s.InitGRPCClients(chain) + + timeoutCtx, timeoutCtxCancel = context.WithTimeout(ctx, time.Minute*2) + defer timeoutCtxCancel() + + err = test.WaitForBlocks(timeoutCtx, int(blocksAfterUpgrade), chain) + s.Require().NoError(err, "chain did not produce blocks after halt") + + height, err := chain.Height(ctx) + s.Require().NoError(err, "error fetching height after halt") + + s.Require().Greater(int64(height), haltHeight, "height did not increment after halt") +} diff --git a/e2e/testsuite/testconfig.go b/e2e/testsuite/testconfig.go new file mode 100644 index 00000000000..ea759ba1322 --- /dev/null +++ b/e2e/testsuite/testconfig.go @@ -0,0 +1,725 @@ +package testsuite + +import ( + "bytes" + "encoding/json" + "fmt" + "os" + "path" + "strings" + "time" + + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + interchaintestutil "github.com/strangelove-ventures/interchaintest/v8/testutil" + "gopkg.in/yaml.v2" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module/testutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + cmtjson "github.com/cometbft/cometbft/libs/json" + + "github.com/cosmos/ibc-go/e2e/relayer" + "github.com/cosmos/ibc-go/e2e/semverutil" + "github.com/cosmos/ibc-go/e2e/testvalues" + wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + ibctypes "github.com/cosmos/ibc-go/v8/modules/core/types" +) + +const ( + // ChainImageEnv specifies the image that the chains will use. If left unspecified, it will + // default to being determined based on the specified binary. E.g. ghcr.io/cosmos/ibc-go-simd + ChainImageEnv = "CHAIN_IMAGE" + // ChainATagEnv specifies the tag that Chain A will use. + ChainATagEnv = "CHAIN_A_TAG" + // ChainBTagEnv specifies the tag that Chain B will use. If unspecified + // the value will default to the same value as Chain A. + ChainBTagEnv = "CHAIN_B_TAG" + // RelayerIDEnv specifies the ID of the relayer to use. + RelayerIDEnv = "RELAYER_ID" + // ChainBinaryEnv binary is the binary that will be used for both chains. + ChainBinaryEnv = "CHAIN_BINARY" + // ChainUpgradeTagEnv specifies the upgrade version tag + ChainUpgradeTagEnv = "CHAIN_UPGRADE_TAG" + // ChainUpgradePlanEnv specifies the upgrade plan name + ChainUpgradePlanEnv = "CHAIN_UPGRADE_PLAN" + // E2EConfigFilePathEnv allows you to specify a custom path for the config file to be used. + E2EConfigFilePathEnv = "E2E_CONFIG_PATH" + + // defaultBinary is the default binary that will be used by the chains. + defaultBinary = "simd" + // defaultRlyTag is the tag that will be used if no relayer tag is specified. + // all images are here https://github.com/cosmos/relayer/pkgs/container/relayer/versions + defaultRlyTag = "latest" + + // TODO: https://github.com/cosmos/ibc-go/issues/4965 + defaultHyperspaceTag = "20231122v39" + // defaultHermesTag is the tag that will be used if no relayer tag is specified for hermes. + defaultHermesTag = "luca_joss-channel-upgrade-authority" + // defaultChainTag is the tag that will be used for the chains if none is specified. + defaultChainTag = "main" + // defaultConfigFileName is the default filename for the config file that can be used to configure + // e2e tests. See sample.config.yaml as an example for what this should look like. + defaultConfigFileName = ".ibc-go-e2e-config.yaml" +) + +func getChainImage(binary string) string { + if binary == "" { + binary = defaultBinary + } + return fmt.Sprintf("ghcr.io/cosmos/ibc-go-%s", binary) +} + +// TestConfig holds configuration used throughout the different e2e tests. +type TestConfig struct { + // ChainConfigs holds configuration values related to the chains used in the tests. + ChainConfigs []ChainConfig `yaml:"chains"` + // RelayerConfig holds all known relayer configurations that can be used in the tests. + RelayerConfigs []relayer.Config `yaml:"relayers"` + // ActiveRelayer specifies the relayer that will be used. It must match the ID of one of the entries in RelayerConfigs. + ActiveRelayer string `yaml:"activeRelayer"` + // UpgradeConfig holds values used only for the upgrade tests. + UpgradeConfig UpgradeConfig `yaml:"upgrade"` + // CometBFTConfig holds values for configuring CometBFT. + CometBFTConfig CometBFTConfig `yaml:"cometbft"` + // DebugConfig holds configuration for miscellaneous options. + DebugConfig DebugConfig `yaml:"debug"` +} + +// Validate validates the test configuration is valid for use within the tests. +// this should be called before using the configuration. +func (tc TestConfig) Validate() error { + if err := tc.validateChains(); err != nil { + return fmt.Errorf("invalid chain configuration: %w", err) + } + + if err := tc.validateRelayers(); err != nil { + return fmt.Errorf("invalid relayer configuration: %w", err) + } + return nil +} + +// validateChains validates the chain configurations. +func (tc TestConfig) validateChains() error { + for _, cfg := range tc.ChainConfigs { + if cfg.Binary == "" { + return fmt.Errorf("chain config missing binary: %+v", cfg) + } + if cfg.Image == "" { + return fmt.Errorf("chain config missing image: %+v", cfg) + } + if cfg.Tag == "" { + return fmt.Errorf("chain config missing tag: %+v", cfg) + } + + // TODO: validate chainID in https://github.com/cosmos/ibc-go/issues/4697 + // these are not passed in the CI at the moment. Defaults are used. + if !IsCI() { + if cfg.ChainID == "" { + return fmt.Errorf("chain config missing chainID: %+v", cfg) + } + } + + // TODO: validate number of nodes in https://github.com/cosmos/ibc-go/issues/4697 + // these are not passed in the CI at the moment. + if !IsCI() { + if cfg.NumValidators == 0 && cfg.NumFullNodes == 0 { + return fmt.Errorf("chain config missing number of validators or full nodes: %+v", cfg) + } + } + } + return nil +} + +// validateRelayers validates relayer configuration. +func (tc TestConfig) validateRelayers() error { + if len(tc.RelayerConfigs) < 1 { + return fmt.Errorf("no relayer configurations specified") + } + + for _, r := range tc.RelayerConfigs { + if r.ID == "" { + return fmt.Errorf("relayer config missing ID: %+v", r) + } + if r.Image == "" { + return fmt.Errorf("relayer config missing image: %+v", r) + } + if r.Tag == "" { + return fmt.Errorf("relayer config missing tag: %+v", r) + } + } + + if tc.GetActiveRelayerConfig() == nil { + return fmt.Errorf("active relayer %s not found in relayer configs: %+v", tc.ActiveRelayer, tc.RelayerConfigs) + } + + return nil +} + +// GetActiveRelayerConfig returns the currently specified relayer config. +func (tc TestConfig) GetActiveRelayerConfig() *relayer.Config { + for _, r := range tc.RelayerConfigs { + if r.ID == tc.ActiveRelayer { + return &r + } + } + return nil +} + +// GetChainNumValidators returns the number of validators for the specific chain index. +// default 1 +func (tc TestConfig) GetChainNumValidators(idx int) int { + if tc.ChainConfigs[idx].NumValidators > 0 { + return tc.ChainConfigs[idx].NumValidators + } + return 1 +} + +// GetChainNumFullNodes returns the number of full nodes for the specific chain index. +// default 0 +func (tc TestConfig) GetChainNumFullNodes(idx int) int { + if tc.ChainConfigs[idx].NumFullNodes > 0 { + return tc.ChainConfigs[idx].NumFullNodes + } + return 0 +} + +// GetChainAID returns the chain-id for chain A. +func (tc TestConfig) GetChainAID() string { + if tc.ChainConfigs[0].ChainID != "" { + return tc.ChainConfigs[0].ChainID + } + return "chainA-1" +} + +// GetChainBID returns the chain-id for chain B. +func (tc TestConfig) GetChainBID() string { + if tc.ChainConfigs[1].ChainID != "" { + return tc.ChainConfigs[1].ChainID + } + return "chainB-1" +} + +// UpgradeConfig holds values relevant to upgrade tests. +type UpgradeConfig struct { + PlanName string `yaml:"planName"` + Tag string `yaml:"tag"` +} + +// ChainConfig holds information about an individual chain used in the tests. +type ChainConfig struct { + ChainID string `yaml:"chainId"` + Image string `yaml:"image"` + Tag string `yaml:"tag"` + Binary string `yaml:"binary"` + NumValidators int `yaml:"numValidators"` + NumFullNodes int `yaml:"numFullNodes"` +} + +type CometBFTConfig struct { + LogLevel string `yaml:"logLevel"` +} + +type DebugConfig struct { + // DumpLogs forces the logs to be collected before removing test containers. + DumpLogs bool `yaml:"dumpLogs"` +} + +// LoadConfig attempts to load a atest configuration from the default file path. +// if any environment variables are specified, they will take precedence over the individual configuration +// options. +func LoadConfig() TestConfig { + tc := getConfig() + if err := tc.Validate(); err != nil { + panic(err) + } + return tc +} + +// getConfig returns the TestConfig with any environment variable overrides. +func getConfig() TestConfig { + fileTc, foundFile := fromFile() + if !foundFile { + return fromEnv() + } + + return applyEnvironmentVariableOverrides(fileTc) +} + +// fromFile returns a TestConfig from a json file and a boolean indicating if the file was found. +func fromFile() (TestConfig, bool) { + var tc TestConfig + bz, err := os.ReadFile(getConfigFilePath()) + if err != nil { + return TestConfig{}, false + } + + if err := yaml.Unmarshal(bz, &tc); err != nil { + panic(err) + } + + return tc, true +} + +// applyEnvironmentVariableOverrides applies all environment variable changes to the config +// loaded from a file. +func applyEnvironmentVariableOverrides(fromFile TestConfig) TestConfig { + envTc := fromEnv() + + if os.Getenv(ChainATagEnv) != "" { + fromFile.ChainConfigs[0].Tag = envTc.ChainConfigs[0].Tag + } + + if os.Getenv(ChainBTagEnv) != "" { + fromFile.ChainConfigs[1].Tag = envTc.ChainConfigs[1].Tag + } + + if os.Getenv(ChainBinaryEnv) != "" { + for i := range fromFile.ChainConfigs { + fromFile.ChainConfigs[i].Binary = envTc.ChainConfigs[i].Binary + } + } + + if os.Getenv(ChainImageEnv) != "" { + for i := range fromFile.ChainConfigs { + fromFile.ChainConfigs[i].Image = envTc.ChainConfigs[i].Image + } + } + + if os.Getenv(RelayerIDEnv) != "" { + fromFile.ActiveRelayer = envTc.ActiveRelayer + } + + if os.Getenv(ChainUpgradePlanEnv) != "" { + fromFile.UpgradeConfig.PlanName = envTc.UpgradeConfig.PlanName + } + + if os.Getenv(ChainUpgradeTagEnv) != "" { + fromFile.UpgradeConfig.Tag = envTc.UpgradeConfig.Tag + } + + return fromFile +} + +// fromEnv returns a TestConfig constructed from environment variables. +func fromEnv() TestConfig { + return TestConfig{ + ChainConfigs: getChainConfigsFromEnv(), + UpgradeConfig: getUpgradePlanConfigFromEnv(), + ActiveRelayer: os.Getenv(RelayerIDEnv), + + // TODO: we can remove this, and specify these values in a config file for the CI + // in https://github.com/cosmos/ibc-go/issues/4697 + RelayerConfigs: []relayer.Config{ + getDefaultRlyRelayerConfig(), + getDefaultHermesRelayerConfig(), + getDefaultHyperspaceRelayerConfig(), + }, + CometBFTConfig: CometBFTConfig{LogLevel: "info"}, + } +} + +// getChainConfigsFromEnv returns the chain configs from environment variables. +func getChainConfigsFromEnv() []ChainConfig { + chainBinary, ok := os.LookupEnv(ChainBinaryEnv) + if !ok { + chainBinary = defaultBinary + } + + chainATag, ok := os.LookupEnv(ChainATagEnv) + if !ok { + chainATag = defaultChainTag + } + + chainBTag, ok := os.LookupEnv(ChainBTagEnv) + if !ok { + chainBTag = chainATag + } + + chainAImage := getChainImage(chainBinary) + specifiedChainImage, ok := os.LookupEnv(ChainImageEnv) + if ok { + chainAImage = specifiedChainImage + } + + numValidators := 4 + numFullNodes := 1 + + chainBImage := chainAImage + return []ChainConfig{ + { + Image: chainAImage, + Tag: chainATag, + Binary: chainBinary, + NumValidators: numValidators, + NumFullNodes: numFullNodes, + }, + { + Image: chainBImage, + Tag: chainBTag, + Binary: chainBinary, + NumValidators: numValidators, + NumFullNodes: numFullNodes, + }, + } +} + +// getConfigFilePath returns the absolute path where the e2e config file should be. +func getConfigFilePath() string { + if absoluteConfigPath := os.Getenv(E2EConfigFilePathEnv); absoluteConfigPath != "" { + return absoluteConfigPath + } + + homeDir, err := os.UserHomeDir() + if err != nil { + panic(err) + } + return path.Join(homeDir, defaultConfigFileName) +} + +// TODO: remove in https://github.com/cosmos/ibc-go/issues/4697 +// getDefaultHermesRelayerConfig returns the default config for the hermes relayer. +func getDefaultHermesRelayerConfig() relayer.Config { + return relayer.Config{ + Tag: defaultHermesTag, + ID: relayer.Hermes, + Image: relayer.HermesRelayerRepository, + } +} + +// TODO: remove in https://github.com/cosmos/ibc-go/issues/4697 +// getDefaultRlyRelayerConfig returns the default config for the golang relayer. +func getDefaultRlyRelayerConfig() relayer.Config { + return relayer.Config{ + Tag: defaultRlyTag, + ID: relayer.Rly, + Image: relayer.RlyRelayerRepository, + } +} + +// TODO: remove in https://github.com/cosmos/ibc-go/issues/4697 +// getDefaultHyperspaceRelayerConfig returns the default config for the hyperspace relayer. +func getDefaultHyperspaceRelayerConfig() relayer.Config { + return relayer.Config{ + Tag: defaultHyperspaceTag, + ID: relayer.Hyperspace, + Image: relayer.HyperspaceRelayerRepository, + } +} + +// getUpgradePlanConfigFromEnv returns the upgrade config from environment variables. +func getUpgradePlanConfigFromEnv() UpgradeConfig { + upgradeTag, ok := os.LookupEnv(ChainUpgradeTagEnv) + if !ok { + upgradeTag = "" + } + + upgradePlan, ok := os.LookupEnv(ChainUpgradePlanEnv) + if !ok { + upgradePlan = "" + } + return UpgradeConfig{ + PlanName: upgradePlan, + Tag: upgradeTag, + } +} + +func GetChainATag() string { + return LoadConfig().ChainConfigs[0].Tag +} + +func GetChainBTag() string { + if chainBTag := LoadConfig().ChainConfigs[1].Tag; chainBTag != "" { + return chainBTag + } + return GetChainATag() +} + +// IsCI returns true if the tests are running in CI, false is returned +// if the tests are running locally. +// Note: github actions passes a CI env value of true by default to all runners. +func IsCI() bool { + return strings.ToLower(os.Getenv("CI")) == "true" +} + +// IsFork returns true if the tests are running in fork mode, false is returned otherwise. +func IsFork() bool { + return strings.ToLower(os.Getenv("FORK")) == "true" +} + +// ChainOptions stores chain configurations for the chains that will be +// created for the tests. They can be modified by passing ChainOptionConfiguration +// to E2ETestSuite.GetChains. +type ChainOptions struct { + ChainASpec *interchaintest.ChainSpec + ChainBSpec *interchaintest.ChainSpec + SkipPathCreation bool +} + +// ChainOptionConfiguration enables arbitrary configuration of ChainOptions. +type ChainOptionConfiguration func(options *ChainOptions) + +// DefaultChainOptions returns the default configuration for the chains. +// These options can be configured by passing configuration functions to E2ETestSuite.GetChains. +func DefaultChainOptions() ChainOptions { + tc := LoadConfig() + + chainACfg := newDefaultSimappConfig(tc.ChainConfigs[0], "simapp-a", tc.GetChainAID(), "atoma", tc.CometBFTConfig) + chainBCfg := newDefaultSimappConfig(tc.ChainConfigs[1], "simapp-b", tc.GetChainBID(), "atomb", tc.CometBFTConfig) + + chainAVal, chainAFn := getValidatorsAndFullNodes(0) + chainBVal, chainBFn := getValidatorsAndFullNodes(1) + + return ChainOptions{ + ChainASpec: &interchaintest.ChainSpec{ + ChainConfig: chainACfg, + NumFullNodes: &chainAFn, + NumValidators: &chainAVal, + }, + ChainBSpec: &interchaintest.ChainSpec{ + ChainConfig: chainBCfg, + NumFullNodes: &chainBFn, + NumValidators: &chainBVal, + }, + } +} + +// newDefaultSimappConfig creates an ibc configuration for simd. +func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string, cometCfg CometBFTConfig) ibc.ChainConfig { + configFileOverrides := make(map[string]any) + tmTomlOverrides := make(interchaintestutil.Toml) + + tmTomlOverrides["log_level"] = cometCfg.LogLevel // change to debug in ~/.ibc-go-e2e-config.json to increase cometbft logging. + configFileOverrides["config/config.toml"] = tmTomlOverrides + + return ibc.ChainConfig{ + Type: "cosmos", + Name: name, + ChainID: chainID, + Images: []ibc.DockerImage{ + { + Repository: cc.Image, + Version: cc.Tag, + UidGid: "1000:1000", + }, + }, + Bin: cc.Binary, + Bech32Prefix: "cosmos", + CoinType: fmt.Sprint(sdk.GetConfig().GetCoinType()), + Denom: denom, + EncodingConfig: SDKEncodingConfig(), + GasPrices: fmt.Sprintf("0.00%s", denom), + GasAdjustment: 1.3, + TrustingPeriod: "508h", + NoHostMount: false, + ModifyGenesis: getGenesisModificationFunction(cc), + ConfigFileOverrides: configFileOverrides, + } +} + +// getGenesisModificationFunction returns a genesis modification function that handles the GenesisState type +// correctly depending on if the govv1beta1 gov module is used or if govv1 is being used. +func getGenesisModificationFunction(cc ChainConfig) func(ibc.ChainConfig, []byte) ([]byte, error) { + binary := cc.Binary + version := cc.Tag + + simdSupportsGovV1Genesis := binary == defaultBinary && testvalues.GovGenesisFeatureReleases.IsSupported(version) + + if simdSupportsGovV1Genesis { + return defaultGovv1ModifyGenesis(version) + } + + return defaultGovv1Beta1ModifyGenesis(version) +} + +// defaultGovv1ModifyGenesis will only modify governance params to ensure the voting period and minimum deposit +// are functional for e2e testing purposes. +func defaultGovv1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([]byte, error) { + stdlibJSONMarshalling := semverutil.FeatureReleases{MajorVersion: "v8"} + return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { + appGenesis, err := genutiltypes.AppGenesisFromReader(bytes.NewReader(genbz)) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err) + } + + var appState genutiltypes.AppMap + if err := json.Unmarshal(appGenesis.AppState, &appState); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis bytes into app state: %w", err) + } + + govGenBz, err := modifyGovV1AppState(chainConfig, appState[govtypes.ModuleName]) + if err != nil { + return nil, err + } + appState[govtypes.ModuleName] = govGenBz + + if !testvalues.AllowAllClientsWildcardFeatureReleases.IsSupported(version) { + ibcGenBz, err := modifyClientGenesisAppState(appState[ibcexported.ModuleName]) + if err != nil { + return nil, err + } + appState[ibcexported.ModuleName] = ibcGenBz + } + + appGenesis.AppState, err = json.Marshal(appState) + if err != nil { + return nil, err + } + + // in older version < v8, tmjson marshal must be used. + // regular json marshalling must be used for v8 and above as the + // sdk is de-coupled from comet. + marshalIndentFn := cmtjson.MarshalIndent + if stdlibJSONMarshalling.IsSupported(version) { + marshalIndentFn = json.MarshalIndent + } + + bz, err := marshalIndentFn(appGenesis, "", " ") + if err != nil { + return nil, err + } + + return bz, nil + } +} + +// defaultGovv1Beta1ModifyGenesis will only modify governance params to ensure the voting period and minimum deposit +// // are functional for e2e testing purposes. +func defaultGovv1Beta1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([]byte, error) { + const appStateKey = "app_state" + return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { + genesisDocMap := map[string]interface{}{} + err := json.Unmarshal(genbz, &genesisDocMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err) + } + + appStateMap, ok := genesisDocMap[appStateKey].(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("failed to extract to app_state") + } + + govModuleBytes, err := json.Marshal(appStateMap[govtypes.ModuleName]) + if err != nil { + return nil, fmt.Errorf("failed to extract gov genesis bytes: %s", err) + } + + govModuleGenesisBytes, err := modifyGovv1Beta1AppState(chainConfig, govModuleBytes) + if err != nil { + return nil, err + } + + govModuleGenesisMap := map[string]interface{}{} + err = json.Unmarshal(govModuleGenesisBytes, &govModuleGenesisMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal gov genesis bytes into map: %w", err) + } + + if !testvalues.AllowAllClientsWildcardFeatureReleases.IsSupported(version) { + ibcModuleBytes, err := json.Marshal(appStateMap[ibcexported.ModuleName]) + if err != nil { + return nil, fmt.Errorf("failed to extract ibc genesis bytes: %s", err) + } + + ibcGenesisBytes, err := modifyClientGenesisAppState(ibcModuleBytes) + if err != nil { + return nil, err + } + + ibcModuleGenesisMap := map[string]interface{}{} + err = json.Unmarshal(ibcGenesisBytes, &ibcModuleGenesisMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal gov genesis bytes into map: %w", err) + } + } + + appStateMap[govtypes.ModuleName] = govModuleGenesisMap + genesisDocMap[appStateKey] = appStateMap + + finalGenesisDocBytes, err := json.MarshalIndent(genesisDocMap, "", " ") + if err != nil { + return nil, err + } + + return finalGenesisDocBytes, nil + } +} + +// modifyGovV1AppState takes the existing gov app state and marshals it to a govv1 GenesisState. +func modifyGovV1AppState(chainConfig ibc.ChainConfig, govAppState []byte) ([]byte, error) { + cfg := testutil.MakeTestEncodingConfig() + + cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) + govv1.RegisterInterfaces(cfg.InterfaceRegistry) + + govGenesisState := &govv1.GenesisState{} + + if err := cdc.UnmarshalJSON(govAppState, govGenesisState); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis bytes into gov genesis state: %w", err) + } + + if govGenesisState.Params == nil { + govGenesisState.Params = &govv1.Params{} + } + + govGenesisState.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(chainConfig.Denom, govv1beta1.DefaultMinDepositTokens)) + maxDep := time.Second * 10 + govGenesisState.Params.MaxDepositPeriod = &maxDep + vp := testvalues.VotingPeriod + govGenesisState.Params.VotingPeriod = &vp + + govGenBz := MustProtoMarshalJSON(govGenesisState) + + return govGenBz, nil +} + +// modifyGovv1Beta1AppState takes the existing gov app state and marshals it to a govv1beta1 GenesisState. +func modifyGovv1Beta1AppState(chainConfig ibc.ChainConfig, govAppState []byte) ([]byte, error) { + cfg := testutil.MakeTestEncodingConfig() + + cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) + govv1beta1.RegisterInterfaces(cfg.InterfaceRegistry) + + govGenesisState := &govv1beta1.GenesisState{} + if err := cdc.UnmarshalJSON(govAppState, govGenesisState); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis bytes into govv1beta1 genesis state: %w", err) + } + + govGenesisState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(chainConfig.Denom, govv1beta1.DefaultMinDepositTokens)) + govGenesisState.VotingParams.VotingPeriod = testvalues.VotingPeriod + + govGenBz, err := cdc.MarshalJSON(govGenesisState) + if err != nil { + return nil, fmt.Errorf("failed to marshal gov genesis state: %w", err) + } + + return govGenBz, nil +} + +// modifyClientGenesisAppState takes the existing ibc app state and marshals it to an ibc GenesisState. +func modifyClientGenesisAppState(ibcAppState []byte) ([]byte, error) { + cfg := testutil.MakeTestEncodingConfig() + + cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) + clienttypes.RegisterInterfaces(cfg.InterfaceRegistry) + + ibcGenesisState := &ibctypes.GenesisState{} + if err := cdc.UnmarshalJSON(ibcAppState, ibcGenesisState); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis bytes into client genesis state: %w", err) + } + + ibcGenesisState.ClientGenesis.Params.AllowedClients = append(ibcGenesisState.ClientGenesis.Params.AllowedClients, wasmtypes.Wasm) + ibcGenBz, err := cdc.MarshalJSON(ibcGenesisState) + if err != nil { + return nil, fmt.Errorf("failed to marshal gov genesis state: %w", err) + } + + return ibcGenBz, nil +} diff --git a/modules/apps/27-interchain-accounts/controller/client/cli/tx.go b/modules/apps/27-interchain-accounts/controller/client/cli/tx.go index 44094f7b152..95a1fd42988 100644 --- a/modules/apps/27-interchain-accounts/controller/client/cli/tx.go +++ b/modules/apps/27-interchain-accounts/controller/client/cli/tx.go @@ -11,13 +11,22 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/cobra" +<<<<<<< HEAD "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" +======= + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) const ( // The controller chain channel version - flagVersion = "version" + flagVersion = "version" + // The channel ordering + flagOrdering = "ordering" flagRelativePacketTimeout = "relative-packet-timeout" ) @@ -28,8 +37,8 @@ func newRegisterInterchainAccountCmd() *cobra.Command { Long: strings.TrimSpace(`Register an account on the counterparty chain via the connection id from the source chain. Connection identifier should be for the source chain and the interchain account will be created on the counterparty chain. Callers are expected to -provide the appropriate application version string via {version} flag. Generates a new -port identifier using the provided owner string, binds to the port identifier and claims +provide the appropriate application version string via {version} flag and the desired ordering +via the {ordering} flag. Generates a new port identifier using the provided owner string, binds to the port identifier and claims the associated capability.`), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -45,13 +54,19 @@ the associated capability.`), return err } - msg := types.NewMsgRegisterInterchainAccount(connectionID, owner, version) + order, err := parseOrder(cmd) + if err != nil { + return err + } + + msg := types.NewMsgRegisterInterchainAccount(connectionID, owner, version, order) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } cmd.Flags().String(flagVersion, "", "Controller chain channel version") + cmd.Flags().String(flagOrdering, channeltypes.ORDERED.String(), fmt.Sprintf("Channel ordering, can be one of: %s", strings.Join(connectiontypes.SupportedOrderings, ", "))) flags.AddTxFlagsToCmd(cmd) return cmd @@ -107,3 +122,18 @@ appropriate relative timeoutTimestamp must be provided with flag {relative-packe return cmd } + +// parseOrder gets the channel ordering from the flags. +func parseOrder(cmd *cobra.Command) (channeltypes.Order, error) { + orderString, err := cmd.Flags().GetString(flagOrdering) + if err != nil { + return channeltypes.NONE, err + } + + order, found := channeltypes.Order_value[strings.ToUpper(orderString)] + if !found { + return channeltypes.NONE, fmt.Errorf("invalid channel ordering: %s", orderString) + } + + return channeltypes.Order(order), nil +} diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go index ef4089ed5b3..d4d24a54b02 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -160,11 +160,6 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false)) }, false, }, - { - "ICA OnChanOpenInit fails - UNORDERED channel", func() { - channel.Ordering = channeltypes.UNORDERED - }, false, - }, { "ICA auth module callback fails", func() { suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string, @@ -759,6 +754,376 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { } } +<<<<<<< HEAD +======= +func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() { + var ( + path *ibctesting.Path + isNilApp bool + version string + channelOrder channeltypes.Order + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success w/ ORDERED channel", func() {}, nil, + }, + { + "success w/ UNORDERED channel", func() { + channelOrder = channeltypes.UNORDERED + }, nil, + }, + { + "success: nil underlying app", + func() { + isNilApp = true + }, + nil, + }, + { + "controller submodule disabled", func() { + suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false)) + }, types.ErrControllerSubModuleDisabled, + }, + { + "ICA OnChanUpgradeInit fails - invalid version", func() { + version = invalidVersion + }, icatypes.ErrUnknownDataType, + }, + { + "ICA auth module callback fails", func() { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { + return "", ibcmock.MockApplicationCallbackError + } + }, ibcmock.MockApplicationCallbackError, + }, + { + "middleware disabled", func() { + suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { + return "", ibcmock.MockApplicationCallbackError + } + }, nil, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + isNilApp = false + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress) + suite.Require().NoError(err) + + metadata := icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) + version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + + tc.malleate() // malleate mutates test data + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + suite.Require().NoError(err) + + app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + cbs, ok := app.(porttypes.UpgradableModule) + suite.Require().True(ok) + + if isNilApp { + cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) + } + + channelOrder = channeltypes.ORDERED + + version, err = cbs.OnChanUpgradeInit( + suite.chainA.GetContext(), + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + channelOrder, + []string{path.EndpointA.ConnectionID}, + version, + ) + + if tc.expError == nil { + suite.Require().NoError(err) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Empty(version) + } + }) + } +} + +// OnChanUpgradeTry callback returns error on controller chains +func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeTry() { + suite.SetupTest() // reset + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + // call application callback directly + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + suite.Require().NoError(err) + + app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + cbs, ok := app.(porttypes.UpgradableModule) + suite.Require().True(ok) + + version, err := cbs.OnChanUpgradeTry( + suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, + path.EndpointA.ChannelConfig.Order, []string{path.EndpointA.ConnectionID}, path.EndpointB.ChannelConfig.Version, + ) + suite.Require().Error(err) + suite.Require().ErrorIs(err, icatypes.ErrInvalidChannelFlow) + suite.Require().Equal("", version) +} + +func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() { + var ( + path *ibctesting.Path + isNilApp bool + counterpartyVersion string + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", func() {}, nil, + }, + { + "success: nil underlying app", + func() { + isNilApp = true + }, + nil, + }, + { + "controller submodule disabled", func() { + suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false)) + }, types.ErrControllerSubModuleDisabled, + }, + { + "ICA OnChanUpgradeAck fails - invalid version", func() { + counterpartyVersion = invalidVersion + }, icatypes.ErrUnknownDataType, + }, + { + "ICA auth module callback fails", func() { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + return ibcmock.MockApplicationCallbackError + } + }, ibcmock.MockApplicationCallbackError, + }, + { + "middleware disabled", func() { + suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + return ibcmock.MockApplicationCallbackError + } + }, nil, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + isNilApp = false + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + counterpartyVersion = path.EndpointB.GetChannel().Version + + tc.malleate() // malleate mutates test data + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + suite.Require().NoError(err) + + app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + cbs, ok := app.(porttypes.UpgradableModule) + suite.Require().True(ok) + + if isNilApp { + cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) + } + + err = cbs.OnChanUpgradeAck( + suite.chainA.GetContext(), + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + counterpartyVersion, + ) + + if tc.expError == nil { + suite.Require().NoError(err) + } else { + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + +func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeOpen() { + var ( + path *ibctesting.Path + isNilApp bool + counterpartyVersion string + channelOrder channeltypes.Order + ) + + testCases := []struct { + name string + malleate func() + }{ + { + "success w/ ORDERED channel", func() {}, + }, + { + "success w/ UNORDERED channel", func() { + channelOrder = channeltypes.UNORDERED + }, + }, + { + "success: nil app", + func() { + isNilApp = true + }, + }, + { + "middleware disabled", func() { + suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + return ibcmock.MockApplicationCallbackError + } + }, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + isNilApp = false + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + counterpartyVersion = path.EndpointB.GetChannel().Version + + tc.malleate() // malleate mutates test data + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + suite.Require().NoError(err) + + app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + cbs, ok := app.(porttypes.UpgradableModule) + suite.Require().True(ok) + + if isNilApp { + cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) + } + + channelOrder = channeltypes.ORDERED + + cbs.OnChanUpgradeOpen( + suite.chainA.GetContext(), + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + channelOrder, + []string{path.EndpointA.ConnectionID}, + counterpartyVersion, + ) + }) + } +} + +func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeRestore() { + var ( + path *ibctesting.Path + isNilApp bool + ) + + testCases := []struct { + name string + malleate func() + }{ + { + "success", func() {}, + }, + { + "success: nil app", + func() { + isNilApp = true + }, + }, + { + "middleware disabled", func() { + suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + return ibcmock.MockApplicationCallbackError + } + }, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + isNilApp = false + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + tc.malleate() // malleate mutates test data + + module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + suite.Require().NoError(err) + + app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) + suite.Require().True(ok) + cbs, ok := app.(porttypes.UpgradableModule) + suite.Require().True(ok) + + if isNilApp { + cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) + } + + cbs.OnChanUpgradeRestore(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + }) + } +} + +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() { var ( pathAToB *ibctesting.Path @@ -855,7 +1220,7 @@ func (suite *InterchainAccountsTestSuite) TestInFlightHandshakeRespectsGoAPICall // attempt to start a second handshake via the controller msg server msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion) + msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion, channeltypes.ORDERED) res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount) suite.Require().Error(err) @@ -868,7 +1233,7 @@ func (suite *InterchainAccountsTestSuite) TestInFlightHandshakeRespectsMsgServer // initiate a channel handshake such that channel.State == INIT msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion) + msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion, channeltypes.ORDERED) res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount) suite.Require().NotNil(res) @@ -901,7 +1266,7 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer( // route a new MsgRegisterInterchainAccount in order to reopen the msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), path.EndpointA.ChannelConfig.Version) + msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), path.EndpointA.ChannelConfig.Version, channeltypes.ORDERED) res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount) suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index c1418595508..1c31f349525 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -39,7 +39,7 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, k.SetMiddlewareEnabled(ctx, portID, connectionID) - _, err = k.registerInterchainAccount(ctx, connectionID, portID, version) + _, err = k.registerInterchainAccount(ctx, connectionID, portID, version, channeltypes.ORDERED) if err != nil { return err } @@ -49,7 +49,7 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, // registerInterchainAccount registers an interchain account, returning the channel id of the MsgChannelOpenInitResponse // and an error if one occurred. -func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, version string) (string, error) { +func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, version string, order channeltypes.Order) (string, error) { // if there is an active channel for this portID / connectionID return an error activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if found { @@ -66,7 +66,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, } } - msg := channeltypes.NewMsgChannelOpenInit(portID, version, channeltypes.ORDERED, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) + msg := channeltypes.NewMsgChannelOpenInit(portID, version, order, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) handler := k.msgRouter.Handler(msg) res, err := handler(ctx, msg) if err != nil { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 51644e4050e..4d6c625762a 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -13,8 +13,7 @@ import ( ) // OnChanOpenInit performs basic validation of channel initialization. -// The channel order must be ORDERED, the counterparty port identifier -// must be the host chain representation as defined in the types package, +// The counterparty port identifier must be the host chain representation as defined in the types package, // the channel version must be equal to the version in the types package, // there must not be an active channel for the specfied port identifier, // and the interchain accounts module must be able to claim the channel @@ -29,10 +28,13 @@ func (k Keeper) OnChanOpenInit( counterparty channeltypes.Counterparty, version string, ) (string, error) { +<<<<<<< HEAD if order != channeltypes.ORDERED { return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) } +======= +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) if !strings.HasPrefix(portID, icatypes.ControllerPortPrefix) { return "", sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) } @@ -66,8 +68,17 @@ func (k Keeper) OnChanOpenInit( panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } +<<<<<<< HEAD if channel.State == channeltypes.OPEN { return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) +======= + if channel.State != channeltypes.CLOSED { + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s must be %s", activeChannelID, portID, channeltypes.CLOSED) + } + + if channel.Ordering != order { + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "order cannot change when reopening a channel expected %s, got %s", channel.Ordering, order) +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) @@ -135,3 +146,127 @@ func (k Keeper) OnChanCloseConfirm( ) error { return nil } +<<<<<<< HEAD +======= + +// OnChanUpgradeInit performs the upgrade init step of the channel upgrade handshake. +// The upgrade init callback must verify the proposed changes to the order, connectionHops, and version. +// Within the version we have the tx type, encoding, interchain account address, host/controller connectionID's +// and the ICS27 protocol version. +// +// The following may be changed: +// - tx type (must be supported) +// - encoding (must be supported) +// - order +// +// The following may not be changed: +// - connectionHops (and subsequently host/controller connectionIDs) +// - interchain account address +// - ICS27 protocol version +func (k Keeper) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedversion string) (string, error) { + // verify connection hops has not changed + connectionID, err := k.GetConnectionID(ctx, portID, channelID) + if err != nil { + return "", err + } + + if len(proposedConnectionHops) != 1 || proposedConnectionHops[0] != connectionID { + return "", errorsmod.Wrapf(channeltypes.ErrInvalidUpgrade, "expected connection hops %s, got %s", []string{connectionID}, proposedConnectionHops) + } + + // verify proposed version only modifies tx type or encoding + if strings.TrimSpace(proposedversion) == "" { + return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "version cannot be empty") + } + + proposedMetadata, err := icatypes.MetadataFromVersion(proposedversion) + if err != nil { + return "", err + } + + currentMetadata, err := k.getAppMetadata(ctx, portID, channelID) + if err != nil { + return "", err + } + + // ValidateControllerMetadata will ensure the ICS27 protocol version has not changed and that the + // tx type and encoding are supported + if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, proposedConnectionHops, proposedMetadata); err != nil { + return "", errorsmod.Wrap(err, "invalid upgrade metadata") + } + + // the interchain account address on the host chain + // must remain the same after the upgrade. + if currentMetadata.Address != proposedMetadata.Address { + return "", errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be changed") + } + + if currentMetadata.ControllerConnectionId != proposedMetadata.ControllerConnectionId { + return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change") + } + + if currentMetadata.HostConnectionId != proposedMetadata.HostConnectionId { + return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed host connection ID must not change") + } + + return proposedversion, nil +} + +// OnChanUpgradeAck implements the ack setup of the channel upgrade handshake. +// The upgrade ack callback must verify the proposed changes to the channel version. +// Within the channel version we have the tx type, encoding, interchain account address, host/controller connectionID's +// and the ICS27 protocol version. +// +// The following may be changed: +// - tx type (must be supported) +// - encoding (must be supported) +// +// The following may not be changed: +// - controller connectionID +// - host connectionID +// - interchain account address +// - ICS27 protocol version +func (k Keeper) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { + if strings.TrimSpace(counterpartyVersion) == "" { + return errorsmod.Wrap(channeltypes.ErrInvalidChannelVersion, "counterparty version cannot be empty") + } + + proposedMetadata, err := icatypes.MetadataFromVersion(counterpartyVersion) + if err != nil { + return err + } + + currentMetadata, err := k.getAppMetadata(ctx, portID, channelID) + if err != nil { + return err + } + + channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) + if !found { + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) + } + + // ValidateControllerMetadata will ensure the ICS27 protocol version has not changed and that the + // tx type and encoding are supported. Note, we pass in the current channel connection hops. The upgrade init + // step will verify that the proposed connection hops will not change. + if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, channel.ConnectionHops, proposedMetadata); err != nil { + return errorsmod.Wrap(err, "invalid upgrade metadata") + } + + // the interchain account address on the host chain + // must remain the same after the upgrade. + if currentMetadata.Address != proposedMetadata.Address { + return errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "address cannot be changed") + } + + if currentMetadata.ControllerConnectionId != proposedMetadata.ControllerConnectionId { + return errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change") + } + + if currentMetadata.HostConnectionId != proposedMetadata.HostConnectionId { + return errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed host connection ID must not change") + } + + return nil +} +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index 79df5aadad6..347a7642b32 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -20,12 +20,12 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { testCases := []struct { name string malleate func() - expPass bool + expError error }{ { "success", func() {}, - true, + nil, }, { "success: previous active channel closed", @@ -43,14 +43,14 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { path.EndpointA.SetChannel(channel) }, - true, + nil, }, { "success: empty channel version returns default metadata JSON string", func() { channel.Version = "" }, - true, + nil, }, { "success: channel reopening", @@ -67,7 +67,25 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { path.EndpointA.ChannelID = "" path.EndpointB.ChannelID = "" }, - true, + nil, + }, + { + "failure: different ordering from previous channel", + func() { + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + + counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + channel := channeltypes.Channel{ + State: channeltypes.CLOSED, + Ordering: channeltypes.UNORDERED, + Counterparty: counterparty, + ConnectionHops: []string{path.EndpointA.ConnectionID}, + Version: TestVersion, + } + + path.EndpointA.SetChannel(channel) + }, + channeltypes.ErrInvalidChannelOrdering, }, { "invalid metadata - previous metadata is different", @@ -91,21 +109,14 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { } path.EndpointA.SetChannel(closedChannel) }, - false, - }, - { - "invalid order - UNORDERED", - func() { - channel.Ordering = channeltypes.UNORDERED - }, - false, + icatypes.ErrInvalidVersion, }, { "invalid port ID", func() { path.EndpointA.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst }, - false, + icatypes.ErrInvalidControllerPort, }, { "invalid counterparty port ID", @@ -113,7 +124,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { path.EndpointA.SetChannel(*channel) channel.Counterparty.PortId = "invalid-port-id" }, - false, + icatypes.ErrInvalidHostPort, }, { "invalid metadata bytestring", @@ -121,7 +132,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { path.EndpointA.SetChannel(*channel) channel.Version = "invalid-metadata-bytestring" }, - false, + icatypes.ErrUnknownDataType, }, { "unsupported encoding format", @@ -134,7 +145,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.Version = string(versionBytes) path.EndpointA.SetChannel(*channel) }, - false, + icatypes.ErrInvalidCodec, }, { "unsupported transaction type", @@ -147,7 +158,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.Version = string(versionBytes) path.EndpointA.SetChannel(*channel) }, - false, + icatypes.ErrUnknownDataType, }, { "connection not found", @@ -155,7 +166,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.ConnectionHops = []string{"invalid-connnection-id"} path.EndpointA.SetChannel(*channel) }, - false, + connectiontypes.ErrConnectionNotFound, }, { "connection not found with default empty channel version", @@ -163,7 +174,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.ConnectionHops = []string{"connection-10"} channel.Version = "" }, - false, + connectiontypes.ErrConnectionNotFound, }, { "invalid controller connection ID", @@ -176,7 +187,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.Version = string(versionBytes) path.EndpointA.SetChannel(*channel) }, - false, + connectiontypes.ErrInvalidConnection, }, { "invalid host connection ID", @@ -189,7 +200,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.Version = string(versionBytes) path.EndpointA.SetChannel(*channel) }, - false, + connectiontypes.ErrInvalidConnection, }, { "invalid version", @@ -202,10 +213,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { channel.Version = string(versionBytes) path.EndpointA.SetChannel(*channel) }, - false, + icatypes.ErrInvalidVersion, }, { - "channel is already active", + "channel is already active (OPEN state)", func() { suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) @@ -219,7 +230,24 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { } suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) }, - false, + icatypes.ErrActiveChannelAlreadySet, + }, + { + "channel is already active (FLUSHING state)", + func() { + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + + counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + channel := channeltypes.Channel{ + State: channeltypes.FLUSHING, + Ordering: channeltypes.ORDERED, + Counterparty: counterparty, + ConnectionHops: []string{path.EndpointA.ConnectionID}, + Version: TestVersion, + } + suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) + }, + icatypes.ErrActiveChannelAlreadySet, }, } @@ -263,11 +291,13 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.Version, ) - if tc.expPass { + expPass := tc.expError == nil + if expPass { suite.Require().NoError(err) suite.Require().Equal(string(versionBytes), version) } else { suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expError) } }) } @@ -470,3 +500,360 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { }) } } +<<<<<<< HEAD +======= + +func (suite *KeeperTestSuite) TestOnChanUpgradeInit() { + const ( + invalidVersion = "invalid-version" + ) + + var ( + path *ibctesting.Path + metadata icatypes.Metadata + version string + order channeltypes.Order + ) + + // updateMetadata is a helper function which modifies the metadata stored in the channel version + // and marshals it into a string to pass to OnChanUpgradeInit as the version string. + updateMetadata := func(modificationFn func(*icatypes.Metadata)) { + metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) + suite.Require().NoError(err) + modificationFn(&metadata) + version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + } + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + name: "success: change order", + malleate: func() { + order = channeltypes.UNORDERED + }, + expError: nil, + }, + { + name: "failure: connectionID not found", + malleate: func() { + // channelID is provided via the endpoint channelID + path.EndpointA.ChannelID = "invalid channel" + }, + expError: channeltypes.ErrChannelNotFound, + }, + { + name: "failure: invalid proposed connectionHops", + malleate: func() { + // connection hops is provided via endpoint connectionID + path.EndpointA.ConnectionID = differentConnectionID + }, + expError: channeltypes.ErrInvalidUpgrade, + }, + { + name: "failure: empty version", + malleate: func() { + version = "" + }, + expError: icatypes.ErrInvalidVersion, + }, + { + name: "failure: cannot decode version string", + malleate: func() { + version = invalidVersion + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: cannot decode self version string", + malleate: func() { + ch := path.EndpointA.GetChannel() + ch.Version = invalidVersion + path.EndpointA.SetChannel(ch) + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: failed controller metadata validation, invalid encoding", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Encoding = "invalid-encoding" + }) + }, + expError: icatypes.ErrInvalidCodec, + }, + { + name: "failure: failed controller metadata validation, invalid tx type", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.TxType = "invalid-tx-type" + }) + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: failed controller metadata validation, invalid interchain account version", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Version = "invalid-interchain-account-version" + }) + }, + expError: icatypes.ErrInvalidVersion, + }, + { + name: "failure: interchain account address changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Address = TestOwnerAddress // use valid address + }) + }, + expError: icatypes.ErrInvalidAccountAddress, + }, + { + name: "failure: controller connection ID has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.ControllerConnectionId = differentConnectionID + }) + }, + expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller connection identifier are unreachable + }, + { + name: "failure: host connection ID has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.HostConnectionId = differentConnectionID + }) + }, + expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host connection identifier are unreachable + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + currentMetadata, err := suite.chainA.GetSimApp().ICAControllerKeeper.GetAppMetadata(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + suite.Require().NoError(err) + + order = channeltypes.ORDERED + metadata = icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) + // use the same address as the previous metadata. + metadata.Address = currentMetadata.Address + + // this is the actual change to the version. + metadata.Encoding = icatypes.EncodingProto3JSON + + path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + + version = path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version + + tc.malleate() // malleate mutates test data + + upgradeVersion, err := path.EndpointA.Chain.GetSimApp().ICAControllerKeeper.OnChanUpgradeInit( + path.EndpointA.Chain.GetContext(), + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + order, + []string{path.EndpointA.ConnectionID}, + version, + ) + + expPass := tc.expError == nil + + if expPass { + suite.Require().NoError(err) + suite.Require().Equal(upgradeVersion, version) + } else { + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + +func (suite *KeeperTestSuite) TestOnChanUpgradeAck() { + const ( + invalidVersion = "invalid-version" + ) + + var ( + path *ibctesting.Path + metadata icatypes.Metadata + counterpartyVersion string + ) + + // updateMetadata is a helper function which modifies the metadata stored in the channel version + // and marshals it into a string to pass to OnChanUpgradeAck as the counterpartyVersion string. + updateMetadata := func(modificationFn func(*icatypes.Metadata)) { + metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) + suite.Require().NoError(err) + modificationFn(&metadata) + counterpartyVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + } + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + name: "failure: empty counterparty version", + malleate: func() { + counterpartyVersion = "" + }, + expError: channeltypes.ErrInvalidChannelVersion, + }, + { + name: "failure: invalid counterparty version", + malleate: func() { + counterpartyVersion = invalidVersion + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: cannot decode self version string", + malleate: func() { + channel := path.EndpointA.GetChannel() + channel.Version = invalidVersion + path.EndpointA.SetChannel(channel) + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: channel not found", + malleate: func() { + // channelID is provided via the endpoint channelID + path.EndpointA.ChannelID = "invalid channel" + }, + expError: ibcerrors.ErrNotFound, // GetChannel error is unreachable + }, + { + name: "failure: failed controller metadata validation, invalid encoding", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Encoding = "invalid-encoding" + }) + }, + expError: icatypes.ErrInvalidCodec, + }, + { + name: "failure: failed controller metadata validation, invalid tx type", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.TxType = "invalid-tx-type" + }) + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: failed controller metadata validation, invalid interchain account version", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Version = "invalid-interchain-account-version" + }) + }, + expError: icatypes.ErrInvalidVersion, + }, + { + name: "failure: interchain account address changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Address = TestOwnerAddress // use valid address + }) + }, + expError: icatypes.ErrInvalidAccountAddress, + }, + { + name: "failure: controller connection ID has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.ControllerConnectionId = differentConnectionID + }) + }, + expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller identifier are unreachable + }, + { + name: "failure: host connection ID has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.HostConnectionId = differentConnectionID + }) + }, + expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host identifier are unreachable + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + currentMetadata, err := suite.chainA.GetSimApp().ICAControllerKeeper.GetAppMetadata(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + suite.Require().NoError(err) + + metadata = icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) + // use the same address as the previous metadata. + metadata.Address = currentMetadata.Address + + // this is the actual change to the version. + metadata.Encoding = icatypes.EncodingProto3JSON + + path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + + err = path.EndpointA.ChanUpgradeInit() + suite.Require().NoError(err) + + err = path.EndpointB.ChanUpgradeTry() + suite.Require().NoError(err) + + counterpartyVersion = path.EndpointB.GetChannel().Version + + tc.malleate() // malleate mutates test data + + err = suite.chainA.GetSimApp().ICAControllerKeeper.OnChanUpgradeAck( + suite.chainA.GetContext(), + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + counterpartyVersion, + ) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().Equal(path.EndpointA.GetChannel().Version, counterpartyVersion) + } else { + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go index fe0535c7022..43cc5d427dc 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -37,7 +37,7 @@ func (s msgServer) RegisterInterchainAccount(goCtx context.Context, msg *types.M s.SetMiddlewareDisabled(ctx, portID, msg.ConnectionId) - channelID, err := s.registerInterchainAccount(ctx, msg.ConnectionId, portID, msg.Version) + channelID, err := s.registerInterchainAccount(ctx, msg.ConnectionId, portID, msg.Version, msg.Order) if err != nil { s.Logger(ctx).Error("error registering interchain account", "error", err.Error()) return nil, err diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go index 44585b2eea4..43f7b476a45 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go @@ -71,7 +71,11 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount_MsgServer() { msg = types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") +<<<<<<< HEAD tc.malleate() +======= + msg = types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "", channeltypes.ORDERED) +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ctx := suite.chainA.GetContext() msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index e01a3798203..13fe111822f 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -6,18 +6,26 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +<<<<<<< HEAD icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" +======= + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) var _ sdk.Msg = &MsgRegisterInterchainAccount{} // NewMsgRegisterInterchainAccount creates a new instance of MsgRegisterInterchainAccount -func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRegisterInterchainAccount { +func NewMsgRegisterInterchainAccount(connectionID, owner, version string, order channeltypes.Order) *MsgRegisterInterchainAccount { return &MsgRegisterInterchainAccount{ ConnectionId: connectionID, Owner: owner, Version: version, + Order: order, } } diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index e5afa00c93e..a6462ae1a7a 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -8,11 +8,24 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" +<<<<<<< HEAD "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/cosmos/ibc-go/v7/testing/simapp" +======= + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { @@ -70,6 +83,7 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { ibctesting.FirstConnectionID, ibctesting.TestAccAddress, icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID), + channeltypes.ORDERED, ) tc.malleate() @@ -87,8 +101,16 @@ func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) require.NoError(t, err) +<<<<<<< HEAD msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners()) +======= + msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "", channeltypes.ORDERED) + encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) + require.NoError(t, err) + require.Equal(t, expSigner.Bytes(), signers[0]) +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } func TestMsgSendTxValidateBasic(t *testing.T) { diff --git a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go index b15979a713e..6d091375dc7 100644 --- a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go +++ b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go @@ -9,7 +9,12 @@ import ( _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" +<<<<<<< HEAD types "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" +======= + types1 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + types "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -31,9 +36,16 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgRegisterInterchainAccount defines the payload for Msg/RegisterAccount type MsgRegisterInterchainAccount struct { +<<<<<<< HEAD Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` +======= + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + Order types.Order `protobuf:"varint,4,opt,name=order,proto3,enum=ibc.core.channel.v1.Order" json:"order,omitempty"` +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } func (m *MsgRegisterInterchainAccount) Reset() { *m = MsgRegisterInterchainAccount{} } @@ -124,9 +136,15 @@ func (m *MsgRegisterInterchainAccountResponse) GetPortId() string { // MsgSendTx defines the payload for Msg/SendTx type MsgSendTx struct { +<<<<<<< HEAD Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` PacketData types.InterchainAccountPacketData `protobuf:"bytes,3,opt,name=packet_data,json=packetData,proto3" json:"packet_data" yaml:"packet_data"` +======= + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + PacketData types1.InterchainAccountPacketData `protobuf:"bytes,3,opt,name=packet_data,json=packetData,proto3" json:"packet_data"` +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) // Relative timeout timestamp provided will be added to the current block time during transaction execution. // The timeout timestamp must be non-zero. RelativeTimeout uint64 `protobuf:"varint,4,opt,name=relative_timeout,json=relativeTimeout,proto3" json:"relative_timeout,omitempty" yaml:"relative_timeout"` @@ -222,6 +240,7 @@ func init() { } var fileDescriptor_7def041328c84a30 = []byte{ +<<<<<<< HEAD // 570 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xbf, 0x6f, 0xd3, 0x40, 0x14, 0xc7, 0xed, 0x34, 0xa4, 0xcd, 0x95, 0x5f, 0xb5, 0x82, 0x30, 0x06, 0xd9, 0x95, 0xc5, 0x50, @@ -259,6 +278,51 @@ var fileDescriptor_7def041328c84a30 = []byte{ 0xf1, 0x16, 0x1c, 0x72, 0x6f, 0x14, 0x10, 0x91, 0xae, 0x18, 0x01, 0x9b, 0x5b, 0xf5, 0x45, 0xea, 0xfa, 0x59, 0x4b, 0x4e, 0x1e, 0x84, 0x44, 0xf4, 0x2b, 0xd9, 0x96, 0x79, 0xf8, 0x3d, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x81, 0x7c, 0xb2, 0x24, 0x05, 0x00, 0x00, +======= + // 668 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x4f, 0x13, 0x4f, + 0x14, 0xef, 0xfe, 0x29, 0xe5, 0xcf, 0x80, 0xa0, 0x1b, 0x22, 0x65, 0xa3, 0x05, 0xab, 0x07, 0x24, + 0x61, 0xc6, 0x56, 0x8d, 0xa6, 0xc6, 0x83, 0x80, 0x87, 0xc6, 0x34, 0x36, 0x2b, 0x26, 0xc4, 0x4b, + 0x33, 0x9d, 0x9d, 0x2c, 0x23, 0xdd, 0x99, 0x75, 0x66, 0xba, 0xe2, 0xcd, 0x78, 0x32, 0x1e, 0x8c, + 0x07, 0x3f, 0x00, 0x1f, 0x81, 0x8b, 0x9f, 0x41, 0x8e, 0x1c, 0x3d, 0x19, 0x03, 0x07, 0x6e, 0x7e, + 0x06, 0xb3, 0x3b, 0xdb, 0x2d, 0x0a, 0x12, 0x2c, 0xdc, 0xf6, 0xbd, 0x99, 0xf7, 0x7b, 0xbf, 0xdf, + 0x6f, 0xde, 0x3e, 0xf0, 0x80, 0xb5, 0x09, 0xc2, 0x61, 0xd8, 0x61, 0x04, 0x6b, 0x26, 0xb8, 0x42, + 0x8c, 0x6b, 0x2a, 0xc9, 0x3a, 0x66, 0xbc, 0x85, 0x09, 0x11, 0x5d, 0xae, 0x15, 0x22, 0x82, 0x6b, + 0x29, 0x3a, 0x1d, 0x2a, 0x51, 0x54, 0x41, 0x7a, 0x13, 0x86, 0x52, 0x68, 0x61, 0x57, 0x59, 0x9b, + 0xc0, 0xc3, 0xc5, 0xf0, 0x98, 0x62, 0xd8, 0x2f, 0x86, 0x51, 0xc5, 0x99, 0xf2, 0x85, 0x2f, 0x92, + 0x72, 0x14, 0x7f, 0x19, 0x24, 0xe7, 0xce, 0xa9, 0x68, 0x44, 0x15, 0x14, 0x62, 0xb2, 0x41, 0x75, + 0x5a, 0xb5, 0x3c, 0x00, 0xf9, 0x43, 0x6c, 0x0c, 0xc8, 0x34, 0x11, 0x2a, 0x10, 0x0a, 0x05, 0xca, + 0x8f, 0xcf, 0x03, 0xe5, 0xa7, 0x07, 0xd7, 0x62, 0x74, 0x22, 0x24, 0x45, 0x64, 0x1d, 0x73, 0x4e, + 0x3b, 0x49, 0xb9, 0xf9, 0x34, 0x57, 0xca, 0x5f, 0x2c, 0x70, 0xa5, 0xa1, 0x7c, 0x97, 0xfa, 0x4c, + 0x69, 0x2a, 0xeb, 0x59, 0xf7, 0x47, 0xa6, 0xb9, 0x3d, 0x05, 0x86, 0xc5, 0x6b, 0x4e, 0x65, 0xd1, + 0x9a, 0xb3, 0xe6, 0x47, 0x5d, 0x13, 0xd8, 0xd7, 0xc1, 0x05, 0x22, 0x38, 0xa7, 0x24, 0x26, 0xdd, + 0x62, 0x5e, 0xf1, 0xbf, 0xe4, 0x74, 0xbc, 0x9f, 0xac, 0x7b, 0x76, 0x11, 0x8c, 0x44, 0x54, 0x2a, + 0x26, 0x78, 0x71, 0x28, 0x39, 0xee, 0x85, 0xf6, 0x2d, 0x30, 0x2c, 0xa4, 0x47, 0x65, 0x31, 0x3f, + 0x67, 0xcd, 0x4f, 0x54, 0x1d, 0x18, 0x3f, 0x43, 0x4c, 0x14, 0xf6, 0xd8, 0x45, 0x15, 0xf8, 0x34, + 0xbe, 0xe1, 0x9a, 0x8b, 0xb5, 0x89, 0xf7, 0x5b, 0xb3, 0xb9, 0x77, 0x07, 0xdb, 0x0b, 0x86, 0x40, + 0xd9, 0x03, 0x37, 0x4e, 0xa2, 0xed, 0x52, 0x15, 0x0a, 0xae, 0xa8, 0x7d, 0x15, 0x80, 0x14, 0x32, + 0x66, 0x69, 0x34, 0x8c, 0xa6, 0x99, 0xba, 0x67, 0x4f, 0x83, 0x91, 0x50, 0x48, 0xdd, 0x57, 0x50, + 0x88, 0xc3, 0xba, 0x57, 0xcb, 0xc7, 0xfd, 0xca, 0x3f, 0x2d, 0x30, 0xda, 0x50, 0xfe, 0x33, 0xca, + 0xbd, 0xd5, 0xcd, 0xb3, 0x58, 0xb1, 0x01, 0xc6, 0xcc, 0xbb, 0xb7, 0x3c, 0xac, 0x71, 0x62, 0xc7, + 0x58, 0x75, 0x05, 0x9e, 0x6a, 0xfa, 0xa2, 0x0a, 0x3c, 0xa2, 0xaf, 0x99, 0x80, 0xad, 0x60, 0x8d, + 0x97, 0xf2, 0x3b, 0xdf, 0x67, 0x73, 0x2e, 0x08, 0xb3, 0x8c, 0x7d, 0x13, 0x5c, 0x94, 0xb4, 0x83, + 0x35, 0x8b, 0x68, 0x4b, 0xb3, 0x80, 0x8a, 0xae, 0x4e, 0x8c, 0xce, 0xbb, 0x93, 0xbd, 0xfc, 0xaa, + 0x49, 0x1f, 0xb1, 0xf5, 0x2e, 0xb8, 0x94, 0xe9, 0xcd, 0x3c, 0x74, 0xc0, 0xff, 0x8a, 0xbe, 0xea, + 0x52, 0x4e, 0x68, 0x22, 0x3d, 0xef, 0x66, 0x71, 0xea, 0xd3, 0x67, 0x0b, 0x4c, 0x36, 0x94, 0xff, + 0x3c, 0xf4, 0xb0, 0xa6, 0x4d, 0x2c, 0x71, 0xa0, 0xec, 0xcb, 0xa0, 0xa0, 0x98, 0xdf, 0xb7, 0x2b, + 0x8d, 0xec, 0x35, 0x50, 0x08, 0x93, 0x1b, 0x89, 0x51, 0x63, 0xd5, 0x1a, 0xfc, 0xf7, 0x7f, 0x10, + 0x9a, 0x1e, 0xa9, 0xf6, 0x14, 0xaf, 0x36, 0xd9, 0x13, 0x93, 0xb6, 0x2a, 0xcf, 0x80, 0xe9, 0x3f, + 0x58, 0xf5, 0x34, 0x55, 0x3f, 0xe4, 0xc1, 0x50, 0x43, 0xf9, 0xf6, 0x57, 0x0b, 0xcc, 0xfc, 0x7d, + 0xf8, 0x9b, 0x83, 0x70, 0x3b, 0x69, 0x2e, 0x9d, 0xb5, 0xf3, 0x46, 0xcc, 0x5e, 0xe9, 0xa3, 0x05, + 0x0a, 0xe9, 0xa0, 0x3e, 0x1c, 0xb0, 0x89, 0x29, 0x77, 0x1e, 0x9f, 0xa9, 0x3c, 0x23, 0xb4, 0x65, + 0x81, 0xf1, 0xdf, 0x26, 0x62, 0x79, 0x40, 0xdc, 0xc3, 0x20, 0xce, 0x93, 0x73, 0x00, 0xe9, 0x51, + 0x74, 0x86, 0xdf, 0x1e, 0x6c, 0x2f, 0x58, 0x4b, 0x2f, 0x77, 0xf6, 0x4a, 0xd6, 0xee, 0x5e, 0xc9, + 0xfa, 0xb1, 0x57, 0xb2, 0x3e, 0xed, 0x97, 0x72, 0xbb, 0xfb, 0xa5, 0xdc, 0xb7, 0xfd, 0x52, 0xee, + 0x45, 0xd3, 0x67, 0x7a, 0xbd, 0xdb, 0x86, 0x44, 0x04, 0x28, 0xdd, 0xb2, 0xac, 0x4d, 0x16, 0x7d, + 0x81, 0xa2, 0xfb, 0x28, 0x10, 0x5e, 0xb7, 0x43, 0x55, 0xbc, 0xbf, 0x15, 0xaa, 0xde, 0x5b, 0xec, + 0xf3, 0x58, 0x3c, 0x6e, 0x75, 0xeb, 0x37, 0x21, 0x55, 0xed, 0x42, 0xb2, 0x77, 0x6f, 0xff, 0x0a, + 0x00, 0x00, 0xff, 0xff, 0x5c, 0x9c, 0xca, 0xe1, 0xb7, 0x06, 0x00, 0x00, +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } // Reference imports to suppress errors if they are not otherwise used. @@ -401,6 +465,11 @@ func (m *MsgRegisterInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if m.Order != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Order)) + i-- + dAtA[i] = 0x20 + } if len(m.Version) > 0 { i -= len(m.Version) copy(dAtA[i:], m.Version) @@ -571,6 +640,9 @@ func (m *MsgRegisterInterchainAccount) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.Order != 0 { + n += 1 + sovTx(uint64(m.Order)) + } return n } @@ -756,6 +828,25 @@ func (m *MsgRegisterInterchainAccount) Unmarshal(dAtA []byte) error { } m.Version = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Order", wireType) + } + m.Order = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Order |= types.Order(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index c0c8c0b3561..346144ead6e 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -140,7 +140,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { expPass bool }{ { - "success", func() {}, true, + "success w/ ORDERED channel", func() {}, true, + }, + { + "success w/ UNORDERED channel", func() { + channel.Ordering = channeltypes.UNORDERED + }, true, }, { "account address generation is block dependent", func() { @@ -169,11 +174,6 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { } }, true, }, - { - "ICA callback fails - invalid channel order", func() { - channel.Ordering = channeltypes.UNORDERED - }, false, - }, } for _, tc := range testCases { diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 9f31c787ff3..8ec9bc624cf 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -26,10 +26,13 @@ func (k Keeper) OnChanOpenTry( counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { +<<<<<<< HEAD if order != channeltypes.ORDERED { return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) } +======= +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) if portID != icatypes.HostPortID { return "", sdkerrors.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, portID) } @@ -50,6 +53,7 @@ func (k Keeper) OnChanOpenTry( panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } +<<<<<<< HEAD if channel.State == channeltypes.OPEN { return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } @@ -62,6 +66,15 @@ func (k Keeper) OnChanOpenTry( if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") } +======= + if channel.State != channeltypes.CLOSED { + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s must be %s", activeChannelID, portID, channeltypes.CLOSED) + } + + // if a channel is being reopened, we allow the controller to propose new fields + // which are not exactly the same as the previous. The provided address will + // be overwritten with the correct one before the metadata is returned. +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } // On the host chain the capability may only be claimed during the OnChanOpenTry @@ -129,3 +142,74 @@ func (k Keeper) OnChanCloseConfirm( ) error { return nil } +<<<<<<< HEAD +======= + +// OnChanUpgradeTry performs the upgrade try step of the channel upgrade handshake. +// The upgrade try callback must verify the proposed changes to the order, connectionHops, and version. +// Within the version we have the tx type, encoding, interchain account address, host/controller connectionID's +// and the ICS27 protocol version. +// +// The following may be changed: +// - tx type (must be supported) +// - encoding (must be supported) +// - order +// +// The following may not be changed: +// - connectionHops (and subsequently host/controller connectionIDs) +// - interchain account address +// - ICS27 protocol version +func (k Keeper) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { + if portID != icatypes.HostPortID { + return "", errorsmod.Wrapf(porttypes.ErrInvalidPort, "expected %s, got %s", icatypes.HostPortID, portID) + } + + // verify connection hops has not changed + connectionID, err := k.getConnectionID(ctx, portID, channelID) + if err != nil { + return "", err + } + + if len(proposedConnectionHops) != 1 || proposedConnectionHops[0] != connectionID { + return "", errorsmod.Wrapf(channeltypes.ErrInvalidUpgrade, "expected connection hops %s, got %s", []string{connectionID}, proposedConnectionHops) + } + + if strings.TrimSpace(counterpartyVersion) == "" { + return "", errorsmod.Wrap(channeltypes.ErrInvalidChannelVersion, "counterparty version cannot be empty") + } + + proposedCounterpartyMetadata, err := icatypes.MetadataFromVersion(counterpartyVersion) + if err != nil { + return "", err + } + + currentMetadata, err := k.getAppMetadata(ctx, portID, channelID) + if err != nil { + return "", err + } + + // ValidateHostMetadata will ensure the ICS27 protocol version has not changed and that the + // tx type and encoding are supported. It also validates the connection params against the counterparty metadata. + if err := icatypes.ValidateHostMetadata(ctx, k.channelKeeper, proposedConnectionHops, proposedCounterpartyMetadata); err != nil { + return "", errorsmod.Wrap(err, "invalid metadata") + } + + // the interchain account address on the host chain + // must remain the same after the upgrade. + if currentMetadata.Address != proposedCounterpartyMetadata.Address { + return "", errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be changed") + } + + // these explicit checks on the controller connection identifier should be unreachable + if currentMetadata.ControllerConnectionId != proposedCounterpartyMetadata.ControllerConnectionId { + return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change") + } + + // these explicit checks on the host connection identifier should be unreachable + if currentMetadata.HostConnectionId != proposedConnectionHops[0] { + return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnectionIdentifier, "proposed connection hop must not change") + } + + return counterpartyVersion, nil +} +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 8158008c1e9..67c8e918816 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -88,6 +88,25 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.Require().False(found) }, true, }, + { + "success - previous metadata is different", + func() { + // set the active channelID in state + suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) + + // set the previous encoding to be proto3json. + // the new encoding is set to be protobuf in the test below. + metadata.Encoding = icatypes.EncodingProto3JSON + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + channel.State = channeltypes.CLOSED + channel.Version = string(versionBytes) + + path.EndpointB.SetChannel(*channel) + }, true, + }, { "reopening account fails - no existing account", func() { @@ -137,6 +156,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { false, }, { +<<<<<<< HEAD "invalid metadata - previous metadata is different", func() { // create a new channel and set it in state @@ -165,6 +185,8 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { false, }, { +======= +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) "invalid port ID", func() { path.EndpointB.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst @@ -256,7 +278,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { false, }, { - "active channel already set", + "active channel already set (OPEN state)", func() { // create a new channel and set it in state ch := channeltypes.NewChannel(channeltypes.OPEN, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, ibctesting.DefaultChannelVersion) @@ -266,6 +288,23 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false, }, + { + "channel is already active (FLUSHING state)", + func() { + suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) + + counterparty := channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + channel := channeltypes.Channel{ + State: channeltypes.FLUSHING, + Ordering: channeltypes.ORDERED, + Counterparty: counterparty, + ConnectionHops: []string{path.EndpointB.ConnectionID}, + Version: TestVersion, + } + suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel) + }, + false, + }, } for _, tc := range testCases { @@ -416,3 +455,185 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { }) } } +<<<<<<< HEAD +======= + +func (suite *KeeperTestSuite) TestOnChanUpgradeTry() { + var ( + path *ibctesting.Path + metadata icatypes.Metadata + order channeltypes.Order + counterpartyVersion string + ) + + // updateMetadata is a helper function which modifies the metadata stored in the channel version + // and marshals it into a string to pass to OnChanUpgradeTry as the counterpartyVersion string. + updateMetadata := func(modificationFn func(*icatypes.Metadata)) { + metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) + suite.Require().NoError(err) + modificationFn(&metadata) + counterpartyVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + } + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + name: "success: change order", + malleate: func() { + order = channeltypes.UNORDERED + }, + expError: nil, + }, + { + name: "failure: invalid port ID", + malleate: func() { + path.EndpointB.ChannelConfig.PortID = "invalid-port-id" + }, + expError: porttypes.ErrInvalidPort, + }, + { + name: "failure: invalid proposed connectionHops", + malleate: func() { + // connection hops is provided via endpoint connectionID + path.EndpointB.ConnectionID = differentConnectionID + }, + expError: channeltypes.ErrInvalidUpgrade, + }, + { + name: "failure: empty counterparty version", + malleate: func() { + counterpartyVersion = "" + }, + expError: channeltypes.ErrInvalidChannelVersion, + }, + { + name: "failure: cannot parse metadata from counterparty version string", + malleate: func() { + counterpartyVersion = "invalid-version" + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: cannot decode version string from channel", + malleate: func() { + channel := path.EndpointB.GetChannel() + channel.Version = "invalid-metadata-string" + path.EndpointB.SetChannel(channel) + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: metadata encoding not supported", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Encoding = "invalid-encoding-format" + }) + }, + expError: icatypes.ErrInvalidCodec, + }, + { + name: "failure: metadata tx type not supported", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.TxType = "invalid-tx-type" + }) + }, + expError: icatypes.ErrUnknownDataType, + }, + { + name: "failure: interchain account address has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.Address = TestOwnerAddress // use valid address + }) + }, + expError: icatypes.ErrInvalidAccountAddress, + }, + { + name: "failure: controller connection ID has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.ControllerConnectionId = differentConnectionID + }) + }, + expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller connection identifier are unreachable + }, + { + name: "failure: host connection ID has changed", + malleate: func() { + updateMetadata(func(metadata *icatypes.Metadata) { + metadata.HostConnectionId = differentConnectionID + }) + }, + expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host connection identifier are unreachable + }, + { + name: "failure: channel not found", + malleate: func() { + path.EndpointB.ChannelID = "invalid-channel-id" + }, + expError: channeltypes.ErrChannelNotFound, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + currentMetadata, err := suite.chainB.GetSimApp().ICAHostKeeper.GetAppMetadata(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + suite.Require().NoError(err) + + order = channeltypes.ORDERED + metadata = icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) + // use the same address as the previous metadata. + metadata.Address = currentMetadata.Address + + // this is the actual change to the version. + metadata.Encoding = icatypes.EncodingProto3JSON + + path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) + + err = path.EndpointA.ChanUpgradeInit() + suite.Require().NoError(err) + + counterpartyVersion = path.EndpointA.GetChannel().Version + + tc.malleate() // malleate mutates test data + + version, err := suite.chainB.GetSimApp().ICAHostKeeper.OnChanUpgradeTry( + suite.chainB.GetContext(), + path.EndpointB.ChannelConfig.PortID, + path.EndpointB.ChannelID, + order, + []string{path.EndpointB.ConnectionID}, + counterpartyVersion, + ) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().Equal(path.EndpointB.GetChannel().Version, version) + } else { + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/callbacks/callbacks_test.go b/modules/apps/callbacks/callbacks_test.go index 8235a3285dd..a87abac231e 100644 --- a/modules/apps/callbacks/callbacks_test.go +++ b/modules/apps/callbacks/callbacks_test.go @@ -18,12 +18,23 @@ import ( simapp "github.com/cosmos/ibc-go/modules/apps/callbacks/testing/simapp" "github.com/cosmos/ibc-go/modules/apps/callbacks/types" +<<<<<<< HEAD icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" +======= + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" + ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) const maxCallbackGas = uint64(1000000) @@ -155,7 +166,7 @@ func (s *CallbacksTestSuite) SetupICATest() string { // RegisterInterchainAccount submits a MsgRegisterInterchainAccount and updates the controller endpoint with the // channel created. func (s *CallbacksTestSuite) RegisterInterchainAccount(owner string) { - msgRegister := icacontrollertypes.NewMsgRegisterInterchainAccount(s.path.EndpointA.ConnectionID, owner, s.path.EndpointA.ChannelConfig.Version) + msgRegister := icacontrollertypes.NewMsgRegisterInterchainAccount(s.path.EndpointA.ConnectionID, owner, s.path.EndpointA.ChannelConfig.Version, channeltypes.ORDERED) res, err := s.chainA.SendMsgs(msgRegister) s.Require().NotEmpty(res) diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index 284ffe70576..a124fd02167 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -6,6 +6,12 @@ option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-acco import "gogoproto/gogo.proto"; import "ibc/applications/interchain_accounts/v1/packet.proto"; +<<<<<<< HEAD +======= +import "ibc/applications/interchain_accounts/controller/v1/controller.proto"; +import "cosmos/msg/v1/msg.proto"; +import "ibc/core/channel/v1/channel.proto"; +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) // Msg defines the 27-interchain-accounts/controller Msg service. service Msg { @@ -20,9 +26,16 @@ message MsgRegisterInterchainAccount { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; +<<<<<<< HEAD string owner = 1; string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; string version = 3; +======= + string owner = 1; + string connection_id = 2; + string version = 3; + ibc.core.channel.v1.Order order = 4; +>>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } // MsgRegisterInterchainAccountResponse defines the response for Msg/RegisterAccount From a7d082d7be046c30f0be767fd7de22a60a38d6ce Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 25 Apr 2024 22:00:06 +0200 Subject: [PATCH 2/5] fix conflicts --- .../interchain-accounts/active-channels.md | 4 - docs/apps/interchain-accounts/overview.md | 4 - e2e/tests/core/04-channel/upgrades_test.go | 328 -------- e2e/tests/interchain_accounts/base_test.go | 554 ------------- e2e/tests/interchain_accounts/gov_test.go | 122 --- e2e/tests/interchain_accounts/groups_test.go | 215 ------ .../interchain_accounts/incentivized_test.go | 383 --------- .../interchain_accounts/localhost_test.go | 477 ------------ e2e/tests/interchain_accounts/params_test.go | 152 ---- e2e/tests/upgrades/genesis_test.go | 246 ------ e2e/testsuite/testconfig.go | 725 ------------------ .../controller/client/cli/tx.go | 11 +- .../controller/ibc_middleware_test.go | 376 +-------- .../controller/keeper/handshake.go | 140 +--- .../controller/keeper/handshake_test.go | 375 +-------- .../controller/keeper/msg_server_test.go | 4 - .../controller/types/msgs.go | 26 +- .../controller/types/msgs_test.go | 22 - .../controller/types/tx.pb.go | 149 ++-- .../host/keeper/handshake.go | 94 +-- .../host/keeper/handshake_test.go | 230 ------ modules/apps/callbacks/callbacks_test.go | 13 +- modules/core/03-connection/types/version.go | 6 +- .../controller/v1/tx.proto | 13 +- 24 files changed, 78 insertions(+), 4591 deletions(-) delete mode 100644 e2e/tests/core/04-channel/upgrades_test.go delete mode 100644 e2e/tests/interchain_accounts/base_test.go delete mode 100644 e2e/tests/interchain_accounts/gov_test.go delete mode 100644 e2e/tests/interchain_accounts/groups_test.go delete mode 100644 e2e/tests/interchain_accounts/incentivized_test.go delete mode 100644 e2e/tests/interchain_accounts/localhost_test.go delete mode 100644 e2e/tests/interchain_accounts/params_test.go delete mode 100644 e2e/tests/upgrades/genesis_test.go delete mode 100644 e2e/testsuite/testconfig.go diff --git a/docs/apps/interchain-accounts/active-channels.md b/docs/apps/interchain-accounts/active-channels.md index 2d369a8dd55..45033136fdc 100644 --- a/docs/apps/interchain-accounts/active-channels.md +++ b/docs/apps/interchain-accounts/active-channels.md @@ -4,9 +4,6 @@ order: 9 # Understanding Active Channels -<<<<<<< HEAD:docs/apps/interchain-accounts/active-channels.md -The Interchain Accounts module uses [ORDERED channels](https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#ordering) to maintain the order of transactions when sending packets from a controller to a host chain. A limitation when using ORDERED channels is that when a packet times out the channel will be closed. -======= The Interchain Accounts module uses either [ORDERED or UNORDERED](https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#ordering) channels. When using `ORDERED` channels, the order of transactions when sending packets from a controller to a host chain is maintained. @@ -14,7 +11,6 @@ When using `ORDERED` channels, the order of transactions when sending packets fr When using `UNORDERED` channels, there is no guarantee that the order of transactions when sending packets from the controller to the host chain is maintained. > A limitation when using ORDERED channels is that when a packet times out the channel will be closed. ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)):docs/docs/02-apps/02-interchain-accounts/09-active-channels.md In the case of a channel closing, a controller chain needs to be able to regain access to the interchain account registered on this channel. `Active Channels` enable this functionality. diff --git a/docs/apps/interchain-accounts/overview.md b/docs/apps/interchain-accounts/overview.md index c92dc1e02bb..c33073db544 100644 --- a/docs/apps/interchain-accounts/overview.md +++ b/docs/apps/interchain-accounts/overview.md @@ -30,9 +30,6 @@ SDK modules on a chain are assumed to be trustworthy. For example, there are no The implementation of ICS-27 in ibc-go uses this assumption in its security considerations. -<<<<<<< HEAD:docs/apps/interchain-accounts/overview.md -The implementation assumes other IBC application modules will not bind to ports within the ICS-27 namespace. -======= The implementation assumes other IBC application modules will not bind to ports within the ICS-27 namespace. ## Channel Closure @@ -43,4 +40,3 @@ This means that the host and controller modules cannot close channels, but they In the event of a channel closing (due to a packet timeout in an ordered channel, for example), the interchain account associated with that channel can become accessible again if a new channel is created with a (JSON-formatted) version string that encodes the exact same `Metadata` information of the previous channel. The channel can be reopened using either [`MsgRegisterInterchainAccount`](./05-messages.md#msgregisterinterchainaccount) or `MsgChannelOpenInit`. If `MsgRegisterInterchainAccount` is used, then it is possible to leave the `version` field of the message empty, since it will be filled in by the controller submodule. If `MsgChannelOpenInit` is used, then the `version` field must be provided with the correct JSON-encoded `Metadata` string. See section [Understanding Active Channels](./09-active-channels.md#understanding-active-channels) for more information. When reopening a channel with the default controller submodule, the ordering of the channel cannot be changed. In order to change the ordering of the channel, the channel has to go through a [channel upgrade handshake](../../01-ibc/06-channel-upgrades.md) or reopen the channel with a custom controller implementation. ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)):docs/docs/02-apps/02-interchain-accounts/01-overview.md diff --git a/e2e/tests/core/04-channel/upgrades_test.go b/e2e/tests/core/04-channel/upgrades_test.go deleted file mode 100644 index b3cd671911a..00000000000 --- a/e2e/tests/core/04-channel/upgrades_test.go +++ /dev/null @@ -1,328 +0,0 @@ -//go:build !test_e2e - -package channel - -import ( - "context" - "testing" - - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - testifysuite "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" -) - -func TestChannelTestSuite(t *testing.T) { - testifysuite.Run(t, new(ChannelTestSuite)) -} - -type ChannelTestSuite struct { - testsuite.E2ETestSuite -} - -// TestChannelUpgrade_WithFeeMiddleware_Succeeds tests upgrading a transfer channel to wire up fee middleware -func (s *ChannelTestSuite) TestChannelUpgrade_WithFeeMiddleware_Succeeds() { - t := s.T() - ctx := context.TODO() - - relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions()) - channelB := channelA.Counterparty - chainA, chainB := s.GetChains() - - chainADenom := chainA.Config().Denom - chainBDenom := chainB.Config().Denom - chainAIBCToken := testsuite.GetIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID) - chainBIBCToken := testsuite.GetIBCToken(chainADenom, channelB.PortID, channelB.ChannelID) - - chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - chainAAddress := chainAWallet.FormattedAddress() - - chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - chainBAddress := chainBWallet.FormattedAddress() - - var ( - chainARelayerWallet, chainBRelayerWallet ibc.Wallet - relayerAStartingBalance int64 - testFee = testvalues.DefaultFee(chainADenom) - ) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") - - // trying to create some inflight packets, although they might get relayed before the upgrade starts - t.Run("create inflight transfer packets between chain A and chain B", func(t *testing.T) { - chainBWalletAmount := ibc.WalletAmount{ - Address: chainBWallet.FormattedAddress(), // destination address - Denom: chainADenom, - Amount: sdkmath.NewInt(testvalues.IBCTransferAmount), - } - - transferTxResp, err := chainA.SendIBCTransfer(ctx, channelA.ChannelID, chainAWallet.KeyName(), chainBWalletAmount, ibc.TransferOptions{}) - s.Require().NoError(err) - s.Require().NoError(transferTxResp.Validate(), "chain-a ibc transfer tx is invalid") - - chainAwalletAmount := ibc.WalletAmount{ - Address: chainAWallet.FormattedAddress(), // destination address - Denom: chainBDenom, - Amount: sdkmath.NewInt(testvalues.IBCTransferAmount), - } - - transferTxResp, err = chainB.SendIBCTransfer(ctx, channelB.ChannelID, chainBWallet.KeyName(), chainAwalletAmount, ibc.TransferOptions{}) - s.Require().NoError(err) - s.Require().NoError(transferTxResp.Validate(), "chain-b ibc transfer tx is invalid") - }) - - t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) { - chA, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - - s.initiateChannelUpgrade(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, s.createUpgradeFields(chA)) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") - - t.Run("packets are relayed between chain A and chain B", func(t *testing.T) { - // packet from chain A to chain B - s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) - actualBalance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom()) - s.Require().NoError(err) - expected := testvalues.IBCTransferAmount - s.Require().Equal(expected, actualBalance.Int64()) - - // packet from chain B to chain A - s.AssertPacketRelayed(ctx, chainB, channelB.PortID, channelB.ChannelID, 1) - actualBalance, err = s.QueryBalance(ctx, chainA, chainAAddress, chainAIBCToken.IBCDenom()) - s.Require().NoError(err) - expected = testvalues.IBCTransferAmount - s.Require().Equal(expected, actualBalance.Int64()) - }) - - t.Run("verify channel A upgraded and is fee enabled", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - - // check the channel version include the fee version - version, err := feetypes.MetadataFromVersion(channel.Version) - s.Require().NoError(err) - s.Require().Equal(feetypes.Version, version.FeeVersion, "the channel version did not include ics29") - - // extra check - feeEnabled, err := s.QueryFeeEnabledChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - s.Require().Equal(true, feeEnabled) - }) - - t.Run("verify channel B upgraded and is fee enabled", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainB, channelB.PortID, channelB.ChannelID) - s.Require().NoError(err) - - // check the channel version include the fee version - version, err := feetypes.MetadataFromVersion(channel.Version) - s.Require().NoError(err) - s.Require().Equal(feetypes.Version, version.FeeVersion, "the channel version did not include ics29") - - // extra check - feeEnabled, err := s.QueryFeeEnabledChannel(ctx, chainB, channelB.PortID, channelB.ChannelID) - s.Require().NoError(err) - s.Require().Equal(true, feeEnabled) - }) - - t.Run("prune packet acknowledgements", func(t *testing.T) { - // there should be one ack for the packet that we sent before the upgrade - acks, err := s.QueryPacketAcknowledgements(ctx, chainA, channelA.PortID, channelA.ChannelID, []uint64{}) - s.Require().NoError(err) - s.Require().Len(acks, 1) - s.Require().Equal(uint64(1), acks[0].Sequence) - - pruneAcksTxResponse := s.PruneAcknowledgements(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, uint64(1)) - s.AssertTxSuccess(pruneAcksTxResponse) - - // after pruning there should not be any acks - acks, err = s.QueryPacketAcknowledgements(ctx, chainA, channelA.PortID, channelA.ChannelID, []uint64{}) - s.Require().NoError(err) - s.Require().Empty(acks) - }) - - t.Run("stop relayer", func(t *testing.T) { - s.StopRelayer(ctx, relayer) - }) - - t.Run("recover relayer wallets", func(t *testing.T) { - err := s.RecoverRelayerWallets(ctx, relayer) - s.Require().NoError(err) - - chainARelayerWallet, chainBRelayerWallet, err = s.GetRelayerWallets(relayer) - s.Require().NoError(err) - - relayerAStartingBalance, err = s.GetChainANativeBalance(ctx, chainARelayerWallet) - s.Require().NoError(err) - t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") - - t.Run("register and verify counterparty payee", func(t *testing.T) { - _, chainBRelayerUser := s.GetRelayerUsers(ctx) - resp := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, chainBRelayerWallet.FormattedAddress(), chainARelayerWallet.FormattedAddress()) - s.AssertTxSuccess(resp) - - address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.FormattedAddress(), channelA.Counterparty.ChannelID) - s.Require().NoError(err) - s.Require().Equal(chainARelayerWallet.FormattedAddress(), address) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("send incentivized transfer packet", func(t *testing.T) { - // before adding fees for the packet, there should not be incentivized packets - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - s.Require().Empty(packets) - - transferAmount := testvalues.DefaultTransferAmount(chainA.Config().Denom) - - msgPayPacketFee := feetypes.NewMsgPayPacketFee(testFee, channelA.PortID, channelA.ChannelID, chainAWallet.FormattedAddress(), nil) - msgTransfer := transfertypes.NewMsgTransfer(channelA.PortID, channelA.ChannelID, transferAmount, chainAWallet.FormattedAddress(), chainBWallet.FormattedAddress(), s.GetTimeoutHeight(ctx, chainB), 0, "") - resp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgPayPacketFee, msgTransfer) - s.AssertTxSuccess(resp) - }) - - t.Run("packets are relayed", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - s.Require().Empty(packets) - }) - - t.Run("tokens are received by walletB", func(t *testing.T) { - actualBalance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom()) - s.Require().NoError(err) - - // walletB has received two IBC transfers of value testvalues.IBCTransferAmount since the start of the test. - expected := 2 * testvalues.IBCTransferAmount - s.Require().Equal(expected, actualBalance.Int64()) - }) - - t.Run("timeout fee is refunded", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) - s.Require().NoError(err) - - // once the relayer has relayed the packets, the timeout fee should be refunded. - // walletA has done two IBC transfers of value testvalues.IBCTransferAmount since the start of the test. - expected := testvalues.StartingTokenAmount - (2 * testvalues.IBCTransferAmount) - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() - s.Require().Equal(expected, actualBalance) - }) - - t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerWallet) - s.Require().NoError(err) - - expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() - s.Require().Equal(expected, actualBalance) - }) -} - -// TestChannelUpgrade_WithFeeMiddleware_FailsWithTimeoutOnAck tests upgrading a transfer channel to wire up fee middleware but fails on ACK because of timeout -func (s *ChannelTestSuite) TestChannelUpgrade_WithFeeMiddleware_FailsWithTimeoutOnAck() { - t := s.T() - ctx := context.TODO() - - relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions()) - channelB := channelA.Counterparty - chainA, chainB := s.GetChains() - - chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") - - t.Run("execute gov proposal to set upgrade timeout", func(t *testing.T) { - s.setUpgradeTimeoutParam(ctx, chainB, chainBWallet) - }) - - t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) { - chA, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - - s.initiateChannelUpgrade(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, s.createUpgradeFields(chA)) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") - - t.Run("verify channel A did not upgrade", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - - s.Require().Equal(channeltypes.OPEN, channel.State, "the channel state is not OPEN") - s.Require().Equal(transfertypes.Version, channel.Version, "the channel version is not ics20-1") - - errorReceipt, err := s.QueryUpgradeError(ctx, chainA, channelA.PortID, channelA.ChannelID) - s.Require().NoError(err) - s.Require().Equal(uint64(1), errorReceipt.Sequence) - s.Require().Contains(errorReceipt.Message, "restored channel to pre-upgrade state") - }) - - t.Run("verify channel B did not upgrade", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainB, channelB.PortID, channelB.ChannelID) - s.Require().NoError(err) - - s.Require().Equal(channeltypes.OPEN, channel.State, "the channel state is not OPEN") - s.Require().Equal(transfertypes.Version, channel.Version, "the channel version is not ics20-1") - - errorReceipt, err := s.QueryUpgradeError(ctx, chainB, channelB.PortID, channelB.ChannelID) - s.Require().NoError(err) - s.Require().Equal(uint64(1), errorReceipt.Sequence) - s.Require().Contains(errorReceipt.Message, "restored channel to pre-upgrade state") - }) -} - -// createUpgradeFields created the upgrade fields for channel -func (s *ChannelTestSuite) createUpgradeFields(channel channeltypes.Channel) channeltypes.UpgradeFields { - versionMetadata := feetypes.Metadata{ - FeeVersion: feetypes.Version, - AppVersion: transfertypes.Version, - } - versionBytes, err := feetypes.ModuleCdc.MarshalJSON(&versionMetadata) - s.Require().NoError(err) - - return channeltypes.NewUpgradeFields(channel.Ordering, channel.ConnectionHops, string(versionBytes)) -} - -// setUpgradeTimeoutParam creates and submits a governance proposal to execute the message to update 04-channel params with a timeout of 1s -func (s *ChannelTestSuite) setUpgradeTimeoutParam(ctx context.Context, chain ibc.Chain, wallet ibc.Wallet) { - const timeoutDelta = 1000000000 // use 1 second as relative timeout to force upgrade timeout on the counterparty - govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chain) - s.Require().NoError(err) - s.Require().NotNil(govModuleAddress) - - upgradeTimeout := channeltypes.NewTimeout(channeltypes.DefaultTimeout.Height, timeoutDelta) - msg := channeltypes.NewMsgUpdateChannelParams(govModuleAddress.String(), channeltypes.NewParams(upgradeTimeout)) - s.ExecuteAndPassGovV1Proposal(ctx, msg, chain, wallet) -} - -// initiateChannelUpgrade creates and submits a governance proposal to execute the message to initiate a channel upgrade -func (s *ChannelTestSuite) initiateChannelUpgrade(ctx context.Context, chain ibc.Chain, wallet ibc.Wallet, portID, channelID string, upgradeFields channeltypes.UpgradeFields) { - govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chain) - s.Require().NoError(err) - s.Require().NotNil(govModuleAddress) - - msg := channeltypes.NewMsgChannelUpgradeInit(portID, channelID, upgradeFields, govModuleAddress.String()) - s.ExecuteAndPassGovV1Proposal(ctx, msg, chain, wallet) -} diff --git a/e2e/tests/interchain_accounts/base_test.go b/e2e/tests/interchain_accounts/base_test.go deleted file mode 100644 index 1199e0f35b8..00000000000 --- a/e2e/tests/interchain_accounts/base_test.go +++ /dev/null @@ -1,554 +0,0 @@ -//go:build !test_e2e - -package interchainaccounts - -import ( - "context" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - testifysuite "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -// orderMapping is a mapping from channel ordering to the string representation of the ordering. -// the representation can be different depending on the relayer implementation. -var orderMapping = map[channeltypes.Order][]string{ - channeltypes.ORDERED: {channeltypes.ORDERED.String(), "Ordered"}, - channeltypes.UNORDERED: {channeltypes.UNORDERED.String(), "Unordered"}, -} - -func TestInterchainAccountsTestSuite(t *testing.T) { - testifysuite.Run(t, new(InterchainAccountsTestSuite)) -} - -type InterchainAccountsTestSuite struct { - testsuite.E2ETestSuite -} - -// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain. -func (s *InterchainAccountsTestSuite) RegisterInterchainAccount(ctx context.Context, chain ibc.Chain, user ibc.Wallet, msgRegisterAccount *controllertypes.MsgRegisterInterchainAccount) { - txResp := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount) - s.AssertTxSuccess(txResp) -} - -func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer() { - s.testMsgSendTxSuccessfulTransfer(channeltypes.ORDERED) -} - -func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_UnorderedChannel() { - s.testMsgSendTxSuccessfulTransfer(channeltypes.UNORDERED) -} - -func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order channeltypes.Order) { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - - // setup 2 accounts: controller account on chain A, a second chain B account. - // host account will be created when the ICA is registered - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - controllerAddress := controllerAccount.FormattedAddress() - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - var hostAccount string - - t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, order) - - txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) - s.AssertTxSuccess(txResp) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("verify interchain account", func(t *testing.T) { - var err error - hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(hostAccount)) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) - icaChannel := channels[0] - s.Require().Contains(orderMapping[order], icaChannel.Ordering) - }) - - t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) { - t.Run("fund interchain account wallet", func(t *testing.T) { - // fund the host account so it has some $$ to send - err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: hostAccount, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainB.Config().Denom, - }) - s.Require().NoError(err) - }) - - t.Run("broadcast MsgSendTx", func(t *testing.T) { - // assemble bank transfer message from host account to user account on host chain - msgSend := &banktypes.MsgSend{ - FromAddress: hostAccount, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - resp := s.BroadcastMessages( - ctx, - chainA, - controllerAccount, - msgSendTx, - ) - - s.AssertTxSuccess(resp) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) - }) - - t.Run("verify tokens transferred", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - _, err = s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) - }) -} - -func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientFunds() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - - // setup 2 accounts: controller account on chain A, a second chain B account. - // host account will be created when the ICA is registered - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - controllerAddress := controllerAccount.FormattedAddress() - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - var hostAccount string - - t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) - s.AssertTxSuccess(txResp) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("verify interchain account", func(t *testing.T) { - var err error - hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(hostAccount)) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) - }) - - t.Run("fail to execute bank transfer over ICA", func(t *testing.T) { - t.Run("verify empty host wallet", func(t *testing.T) { - hostAccountBalance, err := s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom) - - s.Require().NoError(err) - s.Require().Zero(hostAccountBalance.Int64()) - }) - - t.Run("broadcast MsgSendTx", func(t *testing.T) { - // assemble bank transfer message from host account to user account on host chain - msgSend := &banktypes.MsgSend{ - FromAddress: hostAccount, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - txResp := s.BroadcastMessages( - ctx, - chainA, - controllerAccount, - msgSendTx, - ) - - s.AssertTxSuccess(txResp) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) - }) - - t.Run("verify balance is the same", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) - }) -} - -func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReopeningICA() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - - // setup 2 accounts: controller account on chain A, a second chain B account. - // host account will be created when the ICA is registered - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - controllerAddress := controllerAccount.FormattedAddress() - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - - var ( - portID string - hostAccount string - - initialChannelID = "channel-1" - channelIDAfterReopening = "channel-2" - ) - - t.Run("register interchain account", func(t *testing.T) { - var err error - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) - s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount) - portID, err = icatypes.NewControllerPortID(controllerAddress) - s.Require().NoError(err) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("verify interchain account", func(t *testing.T) { - var err error - hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(hostAccount)) - - _, err = s.QueryChannel(ctx, chainA, portID, initialChannelID) - s.Require().NoError(err) - }) - - // stop the relayer to let the submit tx message time out - t.Run("stop relayer", func(t *testing.T) { - s.StopRelayer(ctx, relayer) - }) - - t.Run("submit tx message with bank transfer message times out", func(t *testing.T) { - t.Run("fund interchain account wallet", func(t *testing.T) { - // fund the host account account so it has some $$ to send - err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: hostAccount, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainB.Config().Denom, - }) - s.Require().NoError(err) - }) - - t.Run("broadcast MsgSendTx", func(t *testing.T) { - // assemble bank transfer message from host account to user account on host chain - msgSend := &banktypes.MsgSend{ - FromAddress: hostAccount, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(1), packetData) - - resp := s.BroadcastMessages( - ctx, - chainA, - controllerAccount, - msgSendTx, - ) - - s.AssertTxSuccess(resp) - - // this sleep is to allow the packet to timeout - time.Sleep(1 * time.Second) - }) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("verify channel is closed due to timeout on ordered channel", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainA, portID, initialChannelID) - s.Require().NoError(err) - - s.Require().Equal(channeltypes.CLOSED, channel.State, "the channel was not in an expected state") - }) - - t.Run("verify tokens not transferred", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - _, err = s.QueryBalance(ctx, chainB, hostAccount, chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) - - // re-register interchain account to reopen the channel now that it has been closed due to timeout - // on an ordered channel - t.Run("register interchain account", func(t *testing.T) { - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) - s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) - }) - - t.Run("verify new channel is now open and interchain account has been reregistered with the same portID", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainA, portID, channelIDAfterReopening) - s.Require().NoError(err) - - s.Require().Equal(channeltypes.OPEN, channel.State, "the channel was not in an expected state") - }) - - t.Run("broadcast MsgSendTx", func(t *testing.T) { - // assemble bank transfer message from host account to user account on host chain - msgSend := &banktypes.MsgSend{ - FromAddress: hostAccount, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(5*time.Minute), packetData) - - resp := s.BroadcastMessages( - ctx, - chainA, - controllerAccount, - msgSendTx, - ) - - s.AssertTxSuccess(resp) - - // time for the packet to be relayed - s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB)) - }) - - t.Run("verify tokens transferred", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) -} - -/* -TODO: uncomment when hermes works with upgrades, https://github.com/cosmos/ibc-go/issues/5644 -func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterUpgradingOrdertoUnordered() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, _ := s.GetChains() - - // setup 2 accounts: controller account on chain A, a second chain B account. - // host account will be created when the ICA is registered - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - controllerAddress := controllerAccount.FormattedAddress() - // chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - - var ( - portID string - hostAccount string - - initialChannelID = "channel-1" - ) - - t.Run("register interchain account", func(t *testing.T) { - var err error - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) - s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount) - portID, err = icatypes.NewControllerPortID(controllerAddress) - s.Require().NoError(err) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("verify interchain account", func(t *testing.T) { - var err error - hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(hostAccount)) - - _, err = s.QueryChannel(ctx, chainA, portID, initialChannelID) - s.Require().NoError(err) - }) - - // t.Run("fund interchain account wallet", func(t *testing.T) { - // // fund the host account account so it has some $$ to send - // err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - // Address: hostAccount, - // Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - // Denom: chainB.Config().Denom, - // }) - // s.Require().NoError(err) - // }) - - // t.Run("broadcast MsgSendTx", func(t *testing.T) { - // // assemble bank transfer message from host account to user account on host chain - // msgSend := &banktypes.MsgSend{ - // FromAddress: hostAccount, - // ToAddress: chainBAccount.FormattedAddress(), - // Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - // } - - // cdc := testsuite.Codec() - - // bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - // s.Require().NoError(err) - - // packetData := icatypes.InterchainAccountPacketData{ - // Type: icatypes.EXECUTE_TX, - // Data: bz, - // Memo: "e2e", - // } - - // msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(5*time.Minute), packetData) - - // resp := s.BroadcastMessages( - // ctx, - // chainA, - // controllerAccount, - // msgSendTx, - // ) - - // s.AssertTxSuccess(resp) - - // // time for the packet to be relayed - // s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB)) - // }) - - // t.Run("verify tokens transferred", func(t *testing.T) { - // balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - // s.Require().NoError(err) - - // expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - // s.Require().Equal(expected, balance.Int64()) - // }) - - channel, err := s.QueryChannel(ctx, chainA, portID, initialChannelID) - s.Require().NoError(err) - - // upgrade the channel ordering to UNORDERED - upgradeFields := channeltypes.NewUpgradeFields(channeltypes.UNORDERED, channel.ConnectionHops, channel.Version) - - t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) { - govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA) - s.Require().NoError(err) - s.Require().NotNil(govModuleAddress) - - msg := channeltypes.NewMsgChannelUpgradeInit(portID, initialChannelID, upgradeFields, govModuleAddress.String()) - s.ExecuteAndPassGovV1Proposal(ctx, msg, chainA, controllerAccount) - }) - - t.Run("verify channel A upgraded and is now unordered", func(t *testing.T) { - var channel channeltypes.Channel - waitErr := test.WaitForCondition(time.Minute*2, time.Second*5, func() (bool, error) { - channel, err = s.QueryChannel(ctx, chainA, portID, initialChannelID) - if err != nil { - return false, err - } - return channel.Ordering == channeltypes.UNORDERED, nil - }) - s.Require().NoErrorf(waitErr, "channel was not upgraded: expected %s got %s", channeltypes.UNORDERED, channel.Ordering) - }) -} -*/ diff --git a/e2e/tests/interchain_accounts/gov_test.go b/e2e/tests/interchain_accounts/gov_test.go deleted file mode 100644 index 212b5d173f4..00000000000 --- a/e2e/tests/interchain_accounts/gov_test.go +++ /dev/null @@ -1,122 +0,0 @@ -//go:build !test_e2e - -package interchainaccounts - -import ( - "context" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - testifysuite "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -func TestInterchainAccountsGovTestSuite(t *testing.T) { - testifysuite.Run(t, new(InterchainAccountsGovTestSuite)) -} - -type InterchainAccountsGovTestSuite struct { - testsuite.E2ETestSuite -} - -func (s *InterchainAccountsGovTestSuite) TestInterchainAccountsGovIntegration() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - chainBAddress := chainBAccount.FormattedAddress() - - govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA) - s.Require().NoError(err) - s.Require().NotNil(govModuleAddress) - - t.Run("execute proposal for MsgRegisterInterchainAccount", func(t *testing.T) { - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, govModuleAddress.String(), version, channeltypes.ORDERED) - s.ExecuteAndPassGovV1Proposal(ctx, msgRegisterAccount, chainA, controllerAccount) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) - - var interchainAccAddr string - t.Run("verify interchain account registration success", func(t *testing.T) { - var err error - interchainAccAddr, err = s.QueryInterchainAccount(ctx, chainA, govModuleAddress.String(), ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddr)) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) - }) - - t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) { - t.Run("fund interchain account wallet", func(t *testing.T) { - // fund the host account, so it has some $$ to send - err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: interchainAccAddr, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainB.Config().Denom, - }) - s.Require().NoError(err) - }) - - t.Run("execute proposal for MsgSendTx", func(t *testing.T) { - msgBankSend := &banktypes.MsgSend{ - FromAddress: interchainAccAddr, - ToAddress: chainBAddress, - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(govModuleAddress.String(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - s.ExecuteAndPassGovV1Proposal(ctx, msgSendTx, chainA, controllerAccount) - }) - - t.Run("verify tokens transferred", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - _, err = s.QueryBalance(ctx, chainB, interchainAccAddr, chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) - }) -} diff --git a/e2e/tests/interchain_accounts/groups_test.go b/e2e/tests/interchain_accounts/groups_test.go deleted file mode 100644 index 43faca17a3f..00000000000 --- a/e2e/tests/interchain_accounts/groups_test.go +++ /dev/null @@ -1,215 +0,0 @@ -//go:build !test_e2e - -package interchainaccounts - -import ( - "context" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - interchaintest "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - testifysuite "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - grouptypes "github.com/cosmos/cosmos-sdk/x/group" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -const ( - // DefaultGroupMemberWeight is the members voting weight. - // A group members weight is used in the sum of `YES` votes required to meet a decision policy threshold. - DefaultGroupMemberWeight = "1" - - // DefaultGroupThreshold is the minimum weighted sum of `YES` votes that must be met or - // exceeded for a proposal to succeed. - DefaultGroupThreshold = "1" - - // DefaultMetadata defines a reusable metadata string for testing purposes - DefaultMetadata = "custom metadata" - - // DefaultMinExecutionPeriod is the minimum duration after the proposal submission - // where members can start sending MsgExec. This means that the window for - // sending a MsgExec transaction is: - // `[ submission + min_execution_period ; submission + voting_period + max_execution_period]` - // where max_execution_period is a app-specific config, defined in the keeper. - // If not set, min_execution_period will default to 0. - DefaultMinExecutionPeriod = time.Duration(0) - - // DefaultVotingPeriod is the duration from submission of a proposal to the end of voting period - // Within this times votes can be submitted with MsgVote. - DefaultVotingPeriod = time.Minute - - // InitialGroupID is the first group ID generated by x/group - InitialGroupID = 1 - - // InitialProposalID is the first group proposal ID generated by x/group - InitialProposalID = 1 -) - -func TestInterchainAccountsGroupsTestSuite(t *testing.T) { - testifysuite.Run(t, new(InterchainAccountsGroupsTestSuite)) -} - -type InterchainAccountsGroupsTestSuite struct { - testsuite.E2ETestSuite -} - -func (s *InterchainAccountsGroupsTestSuite) QueryGroupPolicyAddress(ctx context.Context, chain ibc.Chain) string { - queryClient := s.GetChainGRCPClients(chain).GroupsQueryClient - res, err := queryClient.GroupPoliciesByGroup(ctx, &grouptypes.QueryGroupPoliciesByGroupRequest{ - GroupId: InitialGroupID, // always use the initial group id - }) - s.Require().NoError(err) - - return res.GroupPolicies[0].Address -} - -func (s *InterchainAccountsGroupsTestSuite) TestInterchainAccountsGroupsIntegration() { - t := s.T() - ctx := context.TODO() - - var ( - groupPolicyAddr string - interchainAccAddr string - err error - ) - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - - chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - chainAAddress := chainAWallet.FormattedAddress() - - chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - chainBAddress := chainBWallet.FormattedAddress() - - t.Run("create group with new threshold decision policy", func(t *testing.T) { - members := []grouptypes.MemberRequest{ - { - Address: chainAAddress, - Weight: DefaultGroupMemberWeight, - }, - } - - decisionPolicy := grouptypes.NewThresholdDecisionPolicy(DefaultGroupThreshold, DefaultVotingPeriod, DefaultMinExecutionPeriod) - msgCreateGroupWithPolicy, err := grouptypes.NewMsgCreateGroupWithPolicy(chainAAddress, members, DefaultMetadata, DefaultMetadata, true, decisionPolicy) - s.Require().NoError(err) - - txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgCreateGroupWithPolicy) - s.AssertTxSuccess(txResp) - }) - - t.Run("submit proposal for MsgRegisterInterchainAccount", func(t *testing.T) { - groupPolicyAddr = s.QueryGroupPolicyAddress(ctx, chainA) - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, groupPolicyAddr, icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID), channeltypes.ORDERED) - - msgSubmitProposal, err := grouptypes.NewMsgSubmitProposal(groupPolicyAddr, []string{chainAAddress}, []sdk.Msg{msgRegisterAccount}, DefaultMetadata, grouptypes.Exec_EXEC_UNSPECIFIED, "e2e groups proposal: for MsgRegisterInterchainAccount", "e2e groups proposal: for MsgRegisterInterchainAccount") - s.Require().NoError(err) - - txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgSubmitProposal) - s.AssertTxSuccess(txResp) - }) - - t.Run("vote and exec proposal", func(t *testing.T) { - msgVote := &grouptypes.MsgVote{ - ProposalId: InitialProposalID, - Voter: chainAAddress, - Option: grouptypes.VOTE_OPTION_YES, - Exec: grouptypes.Exec_EXEC_TRY, - } - - txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgVote) - s.AssertTxSuccess(txResp) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("verify interchain account registration success", func(t *testing.T) { - interchainAccAddr, err = s.QueryInterchainAccount(ctx, chainA, groupPolicyAddr, ibctesting.FirstConnectionID) - s.Require().NotEmpty(interchainAccAddr) - s.Require().NoError(err) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) // 1 transfer (created by default), 1 interchain-accounts - }) - - t.Run("fund interchain account wallet", func(t *testing.T) { - err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: interchainAccAddr, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainB.Config().Denom, - }) - s.Require().NoError(err) - }) - - t.Run("submit proposal for MsgSendTx", func(t *testing.T) { - msgBankSend := &banktypes.MsgSend{ - FromAddress: interchainAccAddr, - ToAddress: chainBAddress, - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSubmitTx := controllertypes.NewMsgSendTx(groupPolicyAddr, ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - msgSubmitProposal, err := grouptypes.NewMsgSubmitProposal(groupPolicyAddr, []string{chainAAddress}, []sdk.Msg{msgSubmitTx}, DefaultMetadata, grouptypes.Exec_EXEC_UNSPECIFIED, "e2e groups proposal: for MsgRegisterInterchainAccount", "e2e groups proposal: for MsgRegisterInterchainAccount") - s.Require().NoError(err) - - txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgSubmitProposal) - s.AssertTxSuccess(txResp) - }) - - t.Run("vote and exec proposal", func(t *testing.T) { - msgVote := &grouptypes.MsgVote{ - ProposalId: InitialProposalID + 1, - Voter: chainAAddress, - Option: grouptypes.VOTE_OPTION_YES, - Exec: grouptypes.Exec_EXEC_TRY, - } - - txResp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgVote) - s.AssertTxSuccess(txResp) - }) - - t.Run("verify tokens transferred", func(t *testing.T) { - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") - balance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainB.Config().Denom) - - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - - balance, err = s.QueryBalance(ctx, chainB, interchainAccAddr, chainB.Config().Denom) - s.Require().NoError(err) - - expected = testvalues.StartingTokenAmount - testvalues.IBCTransferAmount - s.Require().Equal(expected, balance.Int64()) - }) -} diff --git a/e2e/tests/interchain_accounts/incentivized_test.go b/e2e/tests/interchain_accounts/incentivized_test.go deleted file mode 100644 index 309a8e92b8f..00000000000 --- a/e2e/tests/interchain_accounts/incentivized_test.go +++ /dev/null @@ -1,383 +0,0 @@ -//go:build !test_e2e - -package interchainaccounts - -import ( - "context" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - interchaintest "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - testifysuite "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -func TestIncentivizedInterchainAccountsTestSuite(t *testing.T) { - testifysuite.Run(t, new(IncentivizedInterchainAccountsTestSuite)) -} - -type IncentivizedInterchainAccountsTestSuite struct { - InterchainAccountsTestSuite -} - -func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_SuccessfulBankSend_Incentivized() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - - var ( - chainADenom = chainA.Config().Denom - interchainAcc = "" - testFee = testvalues.DefaultFee(chainADenom) - ) - - t.Run("relayer wallets recovered", func(t *testing.T) { - err := s.RecoverRelayerWallets(ctx, relayer) - s.Require().NoError(err) - }) - - chainARelayerWallet, chainBRelayerWallet, err := s.GetRelayerWallets(relayer) - t.Run("relayer wallets fetched", func(t *testing.T) { - s.Require().NoError(err) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") - - chainARelayerUser, chainBRelayerUser := s.GetRelayerUsers(ctx) - relayerAStartingBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) - s.Require().NoError(err) - t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) - - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - - t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - version := "" // allow version to be specified by the controller chain since both chains should support incentivized channels - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) - s.AssertTxSuccess(txResp) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - var channelOutput ibc.ChannelOutput - t.Run("verify interchain account", func(t *testing.T) { - var err error - interchainAcc, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAcc)) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) - - // interchain accounts channel at index: 0 - channelOutput = channels[0] - - s.Require().NoError(test.WaitForBlocks(ctx, 2, chainA, chainB)) - }) - - t.Run("execute interchain account bank send through controller", func(t *testing.T) { - t.Run("fund interchain account wallet on host chainB", func(t *testing.T) { - // fund the interchain account so it has some $$ to send - err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: interchainAcc, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainB.Config().Denom, - }) - s.Require().NoError(err) - }) - - t.Run("register counterparty payee", func(t *testing.T) { - resp := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelOutput.Counterparty.PortID, channelOutput.Counterparty.ChannelID, chainBRelayerWallet.FormattedAddress(), chainARelayerWallet.FormattedAddress()) - s.AssertTxSuccess(resp) - }) - - t.Run("verify counterparty payee", func(t *testing.T) { - address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.FormattedAddress(), channelOutput.Counterparty.ChannelID) - s.Require().NoError(err) - s.Require().Equal(chainARelayerWallet.FormattedAddress(), address) - }) - - t.Run("no incentivized packets", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) - s.Require().NoError(err) - s.Require().Empty(packets) - }) - - t.Run("stop relayer", func(t *testing.T) { - s.StopRelayer(ctx, relayer) - }) - - t.Run("broadcast incentivized MsgSendTx", func(t *testing.T) { - msgPayPacketFee := &feetypes.MsgPayPacketFee{ - Fee: testvalues.DefaultFee(chainADenom), - SourcePortId: channelOutput.PortID, - SourceChannelId: channelOutput.ChannelID, - Signer: controllerAccount.FormattedAddress(), - } - - msgSend := &banktypes.MsgSend{ - FromAddress: interchainAcc, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - resp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgPayPacketFee, msgSendTx) - s.AssertTxSuccess(resp) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB)) - }) - - t.Run("there should be incentivized packets", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) - s.Require().NoError(err) - s.Require().Len(packets, 1) - actualFee := packets[0].PacketFees[0].Fee - - s.Require().True(actualFee.RecvFee.Equal(testFee.RecvFee)) - s.Require().True(actualFee.AckFee.Equal(testFee.AckFee)) - s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee)) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("packets are relayed", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) - s.Require().NoError(err) - s.Require().Empty(packets) - }) - - t.Run("verify interchain account sent tokens", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - _, err = s.QueryBalance(ctx, chainB, interchainAcc, chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) - - t.Run("timeout fee is refunded", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, controllerAccount) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() - s.Require().Equal(expected, actualBalance) - }) - - t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) - s.Require().NoError(err) - - expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() - s.Require().Equal(expected, actualBalance) - }) - }) -} - -func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_FailedBankSend_Incentivized() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, chainB := s.GetChains() - - var ( - chainADenom = chainA.Config().Denom - interchainAcc = "" - testFee = testvalues.DefaultFee(chainADenom) - ) - - t.Run("relayer wallets recovered", func(t *testing.T) { - err := s.RecoverRelayerWallets(ctx, relayer) - s.Require().NoError(err) - }) - - chainARelayerWallet, chainBRelayerWallet, err := s.GetRelayerWallets(relayer) - t.Run("relayer wallets fetched", func(t *testing.T) { - s.Require().NoError(err) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") - - chainARelayerUser, chainBRelayerUser := s.GetRelayerUsers(ctx) - relayerAStartingBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) - s.Require().NoError(err) - t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) - - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - - t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - version := "" // allow version to be specified by the controller chain since both chains should support incentivized channels - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) - s.AssertTxSuccess(txResp) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - var channelOutput ibc.ChannelOutput - t.Run("verify interchain account", func(t *testing.T) { - var err error - interchainAcc, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAcc)) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) - - // interchain accounts channel at index: 0 - channelOutput = channels[0] - - s.Require().NoError(test.WaitForBlocks(ctx, 2, chainA, chainB)) - }) - - t.Run("execute interchain account bank send through controller", func(t *testing.T) { - t.Run("register counterparty payee", func(t *testing.T) { - resp := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelOutput.Counterparty.PortID, channelOutput.Counterparty.ChannelID, chainBRelayerWallet.FormattedAddress(), chainARelayerWallet.FormattedAddress()) - s.AssertTxSuccess(resp) - }) - - t.Run("verify counterparty payee", func(t *testing.T) { - address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.FormattedAddress(), channelOutput.Counterparty.ChannelID) - s.Require().NoError(err) - s.Require().Equal(chainARelayerWallet.FormattedAddress(), address) - }) - - t.Run("no incentivized packets", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) - s.Require().NoError(err) - s.Require().Empty(packets) - }) - - t.Run("stop relayer", func(t *testing.T) { - err := relayer.StopRelayer(ctx, s.GetRelayerExecReporter()) - s.Require().NoError(err) - }) - - t.Run("broadcast incentivized MsgSendTx", func(t *testing.T) { - msgPayPacketFee := &feetypes.MsgPayPacketFee{ - Fee: testvalues.DefaultFee(chainADenom), - SourcePortId: channelOutput.PortID, - SourceChannelId: channelOutput.ChannelID, - Signer: controllerAccount.FormattedAddress(), - } - - msgSend := &banktypes.MsgSend{ - FromAddress: interchainAcc, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - resp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgPayPacketFee, msgSendTx) - s.AssertTxSuccess(resp) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB)) - }) - - t.Run("there should be incentivized packets", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) - s.Require().NoError(err) - s.Require().Len(packets, 1) - actualFee := packets[0].PacketFees[0].Fee - - s.Require().True(actualFee.RecvFee.Equal(testFee.RecvFee)) - s.Require().True(actualFee.AckFee.Equal(testFee.AckFee)) - s.Require().True(actualFee.TimeoutFee.Equal(testFee.TimeoutFee)) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("packets are relayed", func(t *testing.T) { - packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) - s.Require().NoError(err) - s.Require().Empty(packets) - }) - - t.Run("verify interchain account did not send tokens", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - _, err = s.QueryBalance(ctx, chainB, interchainAcc, chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64(), "tokens should not have been sent as interchain account was not funded") - }) - - t.Run("timeout fee is refunded", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, controllerAccount) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() - s.Require().Equal(expected, actualBalance) - }) - - t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) - s.Require().NoError(err) - - expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() - s.Require().Equal(expected, actualBalance) - }) - }) -} diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go deleted file mode 100644 index d486041de2e..00000000000 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ /dev/null @@ -1,477 +0,0 @@ -//go:build !test_e2e - -package interchainaccounts - -import ( - "context" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - testifysuite "github.com/stretchr/testify/suite" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - "github.com/cosmos/ibc-go/v8/modules/core/exported" - localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -func TestInterchainAccountsLocalhostTestSuite(t *testing.T) { - testifysuite.Run(t, new(LocalhostInterchainAccountsTestSuite)) -} - -type LocalhostInterchainAccountsTestSuite struct { - testsuite.E2ETestSuite -} - -func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { - t := s.T() - ctx := context.TODO() - - _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, _ := s.GetChains() - - chainADenom := chainA.Config().Denom - - rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - - var ( - msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse - msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse - ack []byte - packet channeltypes.Packet - ) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") - - version := icatypes.NewDefaultMetadataString(exported.LocalhostConnectionID, exported.LocalhostConnectionID) - controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) - s.Require().NoError(err) - - t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) - s.AssertTxSuccess(txResp) - - s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) - }) - - t.Run("channel open try localhost", func(t *testing.T) { - msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( - icatypes.HostPortID, icatypes.Version, - channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, - controllerPortID, msgChanOpenInitRes.ChannelId, - version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) - s.AssertTxSuccess(txResp) - - s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) - }) - - t.Run("channel open ack localhost", func(t *testing.T) { - msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( - controllerPortID, msgChanOpenInitRes.ChannelId, - msgChanOpenTryRes.ChannelId, msgChanOpenTryRes.Version, - localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) - s.AssertTxSuccess(txResp) - }) - - t.Run("channel open confirm localhost", func(t *testing.T) { - msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( - icatypes.HostPortID, msgChanOpenTryRes.ChannelId, - localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) - s.AssertTxSuccess(txResp) - }) - - t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { - channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) - s.Require().NoError(err) - s.Require().NotNil(channelEndA) - - channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) - s.Require().NoError(err) - s.Require().NotNil(channelEndB) - - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) - }) - - t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddress)) - - walletAmount := ibc.WalletAmount{ - Address: interchainAccAddress, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainADenom, - } - - s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) - }) - - t.Run("send packet localhost interchain accounts", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddress)) - - msgSend := &banktypes.MsgSend{ - FromAddress: interchainAccAddress, - ToAddress: userBWallet.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) - s.AssertTxSuccess(txResp) - - packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) - s.Require().NoError(err) - s.Require().NotNil(packet) - }) - - t.Run("recv packet localhost interchain accounts", func(t *testing.T) { - msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) - s.AssertTxSuccess(txResp) - - ack, err = ibctesting.ParseAckFromEvents(txResp.Events) - s.Require().NoError(err) - s.Require().NotNil(ack) - }) - - t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { - msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) - s.AssertTxSuccess(txResp) - }) - - t.Run("verify tokens transferred", func(t *testing.T) { - balance, err := s.QueryBalance(ctx, chainA, userBWallet.FormattedAddress(), chainADenom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) -} - -func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChannel_Localhost() { - t := s.T() - ctx := context.TODO() - - // relayer and channel output is discarded, only a single chain is required - _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, _ := s.GetChains() - - chainADenom := chainA.Config().Denom - - rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - - var ( - msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse - msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse - ack []byte - packet channeltypes.Packet - ) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") - - version := icatypes.NewDefaultMetadataString(exported.LocalhostConnectionID, exported.LocalhostConnectionID) - controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) - s.Require().NoError(err) - - t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) - s.AssertTxSuccess(txResp) - - s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) - }) - - t.Run("channel open try localhost", func(t *testing.T) { - msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( - icatypes.HostPortID, icatypes.Version, - channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, - controllerPortID, msgChanOpenInitRes.ChannelId, - version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) - s.AssertTxSuccess(txResp) - - s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) - }) - - t.Run("channel open ack localhost", func(t *testing.T) { - msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( - controllerPortID, msgChanOpenInitRes.ChannelId, - msgChanOpenTryRes.ChannelId, msgChanOpenTryRes.Version, - localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) - s.AssertTxSuccess(txResp) - }) - - t.Run("channel open confirm localhost", func(t *testing.T) { - msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( - icatypes.HostPortID, msgChanOpenTryRes.ChannelId, - localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) - s.AssertTxSuccess(txResp) - }) - - t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { - channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) - s.Require().NoError(err) - s.Require().NotNil(channelEndA) - - channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) - s.Require().NoError(err) - s.Require().NotNil(channelEndB) - - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) - }) - - t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddress)) - - walletAmount := ibc.WalletAmount{ - Address: interchainAccAddress, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainADenom, - } - - s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) - }) - - t.Run("send localhost interchain accounts packet with timeout", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddress)) - - msgSend := &banktypes.MsgSend{ - FromAddress: interchainAccAddress, - ToAddress: userBWallet.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(1), packetData) - - txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) - s.AssertTxSuccess(txResp) - - packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) - s.Require().NoError(err) - s.Require().NotNil(packet) - }) - - t.Run("timeout localhost interchain accounts packet", func(t *testing.T) { - msgTimeout := channeltypes.NewMsgTimeout(packet, 1, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgTimeout) - s.AssertTxSuccess(txResp) - }) - - t.Run("close interchain accounts host channel end", func(t *testing.T) { - // Pass in zero for counterpartyUpgradeSequence given that channel has not undergone any upgrades. - msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), 0) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgCloseConfirm) - s.AssertTxSuccess(txResp) - }) - - t.Run("verify localhost interchain accounts channel is closed", func(t *testing.T) { - channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) - s.Require().NoError(err) - - s.Require().Equal(channeltypes.CLOSED, channelEndA.State, "the channel was not in an expected state") - - channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) - s.Require().NoError(err) - - s.Require().Equal(channeltypes.CLOSED, channelEndB.State, "the channel was not in an expected state") - }) - - t.Run("channel open init localhost: create new channel for existing account", func(t *testing.T) { - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(exported.LocalhostConnectionID, userAWallet.FormattedAddress(), version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) - s.AssertTxSuccess(txResp) - - // note: response values are updated here in msgChanOpenInitRes - s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) - }) - - t.Run("channel open try localhost", func(t *testing.T) { - msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( - icatypes.HostPortID, icatypes.Version, - channeltypes.ORDERED, []string{exported.LocalhostConnectionID}, - controllerPortID, msgChanOpenInitRes.ChannelId, - version, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) - s.AssertTxSuccess(txResp) - - // note: response values are updated here in msgChanOpenTryRes - s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) - }) - - t.Run("channel open ack localhost", func(t *testing.T) { - msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( - controllerPortID, msgChanOpenInitRes.ChannelId, - msgChanOpenTryRes.ChannelId, msgChanOpenTryRes.Version, - localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) - s.AssertTxSuccess(txResp) - }) - - t.Run("channel open confirm localhost", func(t *testing.T) { - msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( - icatypes.HostPortID, msgChanOpenTryRes.ChannelId, - localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) - s.AssertTxSuccess(txResp) - }) - - t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { - channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId) - s.Require().NoError(err) - s.Require().NotNil(channelEndA) - - channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.ChannelId) - s.Require().NoError(err) - s.Require().NotNil(channelEndB) - - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) - }) - - t.Run("verify interchain account and existing balance", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddress)) - - balance, err := s.QueryBalance(ctx, chainA, interchainAccAddress, chainADenom) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) - - t.Run("send packet localhost interchain accounts", func(t *testing.T) { - interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), exported.LocalhostConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(interchainAccAddress)) - - msgSend := &banktypes.MsgSend{ - FromAddress: interchainAccAddress, - ToAddress: userBWallet.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), exported.LocalhostConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - txResp := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) - s.AssertTxSuccess(txResp) - - packet, err = ibctesting.ParsePacketFromEvents(txResp.Events) - s.Require().NoError(err) - s.Require().NotNil(packet) - }) - - t.Run("recv packet localhost interchain accounts", func(t *testing.T) { - msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) - s.AssertTxSuccess(txResp) - - ack, err = ibctesting.ParseAckFromEvents(txResp.Events) - s.Require().NoError(err) - s.Require().NotNil(ack) - }) - - t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { - msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) - - txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) - s.AssertTxSuccess(txResp) - }) - - t.Run("verify tokens transferred", func(t *testing.T) { - s.AssertPacketRelayed(ctx, chainA, controllerPortID, msgChanOpenInitRes.ChannelId, 1) - - balance, err := s.QueryBalance(ctx, chainA, userBWallet.FormattedAddress(), chainADenom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) -} diff --git a/e2e/tests/interchain_accounts/params_test.go b/e2e/tests/interchain_accounts/params_test.go deleted file mode 100644 index 4cdc64fa371..00000000000 --- a/e2e/tests/interchain_accounts/params_test.go +++ /dev/null @@ -1,152 +0,0 @@ -//go:build !test_e2e - -package interchainaccounts - -import ( - "context" - "testing" - - "github.com/strangelove-ventures/interchaintest/v8/ibc" - testifysuite "github.com/stretchr/testify/suite" - - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - hosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -func TestInterchainAccountsParamsTestSuite(t *testing.T) { - testifysuite.Run(t, new(InterchainAccountsParamsTestSuite)) -} - -type InterchainAccountsParamsTestSuite struct { - testsuite.E2ETestSuite -} - -// QueryControllerParams queries the params for the controller -func (s *InterchainAccountsParamsTestSuite) QueryControllerParams(ctx context.Context, chain ibc.Chain) controllertypes.Params { - queryClient := s.GetChainGRCPClients(chain).ICAControllerQueryClient - res, err := queryClient.Params(ctx, &controllertypes.QueryParamsRequest{}) - s.Require().NoError(err) - - return *res.Params -} - -// QueryHostParams queries the host chain for the params -func (s *InterchainAccountsParamsTestSuite) QueryHostParams(ctx context.Context, chain ibc.Chain) hosttypes.Params { - queryClient := s.GetChainGRCPClients(chain).ICAHostQueryClient - res, err := queryClient.Params(ctx, &hosttypes.QueryParamsRequest{}) - s.Require().NoError(err) - - return *res.Params -} - -// TestControllerEnabledParam tests that changing the ControllerEnabled param works as expected -func (s *InterchainAccountsParamsTestSuite) TestControllerEnabledParam() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) - chainA, _ := s.GetChains() - chainAVersion := chainA.Config().Images[0].Version - - // setup controller account on chainA - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - controllerAddress := controllerAccount.FormattedAddress() - - t.Run("ensure the controller is enabled", func(t *testing.T) { - params := s.QueryControllerParams(ctx, chainA) - s.Require().True(params.ControllerEnabled) - }) - - t.Run("disable the controller", func(t *testing.T) { - if testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion) { - authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA) - s.Require().NoError(err) - s.Require().NotNil(authority) - - msg := controllertypes.MsgUpdateParams{ - Signer: authority.String(), - Params: controllertypes.NewParams(false), - } - s.ExecuteAndPassGovV1Proposal(ctx, &msg, chainA, controllerAccount) - } else { - changes := []paramsproposaltypes.ParamChange{ - paramsproposaltypes.NewParamChange(controllertypes.StoreKey, string(controllertypes.KeyControllerEnabled), "false"), - } - - proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes) - s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainA, controllerAccount, proposal) - } - }) - - t.Run("ensure controller is disabled", func(t *testing.T) { - params := s.QueryControllerParams(ctx, chainA) - s.Require().False(params.ControllerEnabled) - }) - - t.Run("ensure that broadcasting a MsgRegisterInterchainAccount fails", func(t *testing.T) { - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) - s.AssertTxFailure(txResp, controllertypes.ErrControllerSubModuleDisabled) - }) -} - -func (s *InterchainAccountsParamsTestSuite) TestHostEnabledParam() { - t := s.T() - ctx := context.TODO() - - // setup relayers and connection-0 between two chains - // channel-0 is a transfer channel but it will not be used in this test case - _, _ = s.SetupChainsRelayerAndChannel(ctx, nil) - _, chainB := s.GetChains() - chainBVersion := chainB.Config().Images[0].Version - - // setup 2 accounts: controller account on chain A, a second chain B account. - // host account will be created when the ICA is registered - chainBUser := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - - // Assert that default value for enabled is true. - t.Run("ensure the host is enabled", func(t *testing.T) { - params := s.QueryHostParams(ctx, chainB) - s.Require().True(params.HostEnabled) - s.Require().Equal([]string{hosttypes.AllowAllHostMsgs}, params.AllowMessages) - }) - - t.Run("disable the host", func(t *testing.T) { - if testvalues.SelfParamsFeatureReleases.IsSupported(chainBVersion) { - authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainB) - s.Require().NoError(err) - s.Require().NotNil(authority) - - msg := hosttypes.MsgUpdateParams{ - Signer: authority.String(), - Params: hosttypes.NewParams(false, []string{hosttypes.AllowAllHostMsgs}), - } - s.ExecuteAndPassGovV1Proposal(ctx, &msg, chainB, chainBUser) - } else { - changes := []paramsproposaltypes.ParamChange{ - paramsproposaltypes.NewParamChange(hosttypes.StoreKey, string(hosttypes.KeyHostEnabled), "false"), - } - - proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes) - s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainB, chainBUser, proposal) - } - }) - - t.Run("ensure the host is disabled", func(t *testing.T) { - params := s.QueryHostParams(ctx, chainB) - s.Require().False(params.HostEnabled) - }) -} diff --git a/e2e/tests/upgrades/genesis_test.go b/e2e/tests/upgrades/genesis_test.go deleted file mode 100644 index 4b387bb128b..00000000000 --- a/e2e/tests/upgrades/genesis_test.go +++ /dev/null @@ -1,246 +0,0 @@ -//go:build !test_e2e - -package upgrades - -import ( - "context" - "testing" - "time" - - "github.com/cosmos/gogoproto/proto" - "github.com/strangelove-ventures/interchaintest/v8" - cosmos "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - test "github.com/strangelove-ventures/interchaintest/v8/testutil" - "github.com/stretchr/testify/suite" - "go.uber.org/zap" - - sdkmath "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - "github.com/cosmos/ibc-go/e2e/testsuite" - "github.com/cosmos/ibc-go/e2e/testvalues" - controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" -) - -func TestGenesisTestSuite(t *testing.T) { - suite.Run(t, new(GenesisTestSuite)) -} - -type GenesisTestSuite struct { - testsuite.E2ETestSuite -} - -func (s *GenesisTestSuite) TestIBCGenesis() { - t := s.T() - - configFileOverrides := make(map[string]any) - appTomlOverrides := make(test.Toml) - - appTomlOverrides["halt-height"] = haltHeight - configFileOverrides["config/app.toml"] = appTomlOverrides - chainOpts := func(options *testsuite.ChainOptions) { - options.ChainASpec.ConfigFileOverrides = configFileOverrides - } - - // create chains with specified chain configuration options - chainA, chainB := s.GetChains(chainOpts) - - ctx := context.Background() - relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, nil) - var ( - chainADenom = chainA.Config().Denom - chainBIBCToken = testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID) // IBC token sent to chainB - - ) - - chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - chainAAddress := chainAWallet.FormattedAddress() - - chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - chainBAddress := chainBWallet.FormattedAddress() - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") - - t.Run("ics20: native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) { - transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "") - s.AssertTxSuccess(transferTxResp) - }) - - t.Run("ics20: tokens are escrowed", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount - s.Require().Equal(expected, actualBalance) - }) - - // setup 2 accounts: controller account on chain A, a second chain B account. - // host account will be created when the ICA is registered - controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - controllerAddress := controllerAccount.FormattedAddress() - chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) - var hostAccount string - - t.Run("ics27: broadcast MsgRegisterInterchainAccount", func(t *testing.T) { - // explicitly set the version string because we don't want to use incentivized channels. - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) - msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED) - - txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) - s.AssertTxSuccess(txResp) - }) - - t.Run("start relayer", func(t *testing.T) { - s.StartRelayer(relayer) - }) - - t.Run("ics20: packets are relayed", func(t *testing.T) { - s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) - - actualBalance, err := s.QueryBalance(ctx, chainB, chainBAddress, chainBIBCToken.IBCDenom()) - - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount - s.Require().Equal(expected, actualBalance.Int64()) - }) - - t.Run("ics27: verify interchain account", func(t *testing.T) { - var err error - hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) - s.Require().NoError(err) - s.Require().NotZero(len(hostAccount)) - - channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) - s.Require().NoError(err) - s.Require().Equal(len(channels), 2) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks") - - t.Run("Halt chain and export genesis", func(t *testing.T) { - s.HaltChainAndExportGenesis(ctx, chainA.(*cosmos.CosmosChain), relayer, int64(haltHeight)) - }) - - t.Run("ics20: native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) { - transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "") - s.AssertTxSuccess(transferTxResp) - }) - - t.Run("ics20: tokens are escrowed", func(t *testing.T) { - actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) - s.Require().NoError(err) - - expected := testvalues.StartingTokenAmount - 2*testvalues.IBCTransferAmount - s.Require().Equal(expected, actualBalance) - }) - - t.Run("ics27: interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) { - t.Run("fund interchain account wallet", func(t *testing.T) { - // fund the host account so it has some $$ to send - err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: hostAccount, - Amount: sdkmath.NewInt(testvalues.StartingTokenAmount), - Denom: chainB.Config().Denom, - }) - s.Require().NoError(err) - }) - - t.Run("broadcast MsgSendTx", func(t *testing.T) { - // assemble bank transfer message from host account to user account on host chain - msgSend := &banktypes.MsgSend{ - FromAddress: hostAccount, - ToAddress: chainBAccount.FormattedAddress(), - Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), - } - - cdc := testsuite.Codec() - bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf) - s.Require().NoError(err) - - packetData := icatypes.InterchainAccountPacketData{ - Type: icatypes.EXECUTE_TX, - Data: bz, - Memo: "e2e", - } - - msgSendTx := controllertypes.NewMsgSendTx(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) - - resp := s.BroadcastMessages( - ctx, - chainA, - controllerAccount, - msgSendTx, - ) - - s.AssertTxSuccess(resp) - - s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) - }) - }) - - s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") -} - -func (s *GenesisTestSuite) HaltChainAndExportGenesis(ctx context.Context, chain *cosmos.CosmosChain, relayer ibc.Relayer, haltHeight int64) { - timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Minute*2) - defer timeoutCtxCancel() - - err := test.WaitForBlocks(timeoutCtx, int(haltHeight), chain) - s.Require().Error(err, "chain did not halt at halt height") - - err = chain.StopAllNodes(ctx) - s.Require().NoError(err, "error stopping node(s)") - - state, err := chain.ExportState(ctx, haltHeight) - s.Require().NoError(err) - - appTomlOverrides := make(test.Toml) - - appTomlOverrides["halt-height"] = 0 - - for _, node := range chain.Nodes() { - err := node.OverwriteGenesisFile(ctx, []byte(state)) - s.Require().NoError(err) - } - - for _, node := range chain.Nodes() { - err := test.ModifyTomlConfigFile( - ctx, - zap.NewExample(), - node.DockerClient, - node.TestName, - node.VolumeName, - "config/app.toml", - appTomlOverrides, - ) - s.Require().NoError(err) - - _, _, err = node.ExecBin(ctx, "comet", "unsafe-reset-all") - s.Require().NoError(err) - } - - err = chain.StartAllNodes(ctx) - s.Require().NoError(err) - - // we are reinitializing the clients because we need to update the hostGRPCAddress after - // the upgrade and subsequent restarting of nodes - s.InitGRPCClients(chain) - - timeoutCtx, timeoutCtxCancel = context.WithTimeout(ctx, time.Minute*2) - defer timeoutCtxCancel() - - err = test.WaitForBlocks(timeoutCtx, int(blocksAfterUpgrade), chain) - s.Require().NoError(err, "chain did not produce blocks after halt") - - height, err := chain.Height(ctx) - s.Require().NoError(err, "error fetching height after halt") - - s.Require().Greater(int64(height), haltHeight, "height did not increment after halt") -} diff --git a/e2e/testsuite/testconfig.go b/e2e/testsuite/testconfig.go deleted file mode 100644 index ea759ba1322..00000000000 --- a/e2e/testsuite/testconfig.go +++ /dev/null @@ -1,725 +0,0 @@ -package testsuite - -import ( - "bytes" - "encoding/json" - "fmt" - "os" - "path" - "strings" - "time" - - "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - interchaintestutil "github.com/strangelove-ventures/interchaintest/v8/testutil" - "gopkg.in/yaml.v2" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - cmtjson "github.com/cometbft/cometbft/libs/json" - - "github.com/cosmos/ibc-go/e2e/relayer" - "github.com/cosmos/ibc-go/e2e/semverutil" - "github.com/cosmos/ibc-go/e2e/testvalues" - wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" - ibctypes "github.com/cosmos/ibc-go/v8/modules/core/types" -) - -const ( - // ChainImageEnv specifies the image that the chains will use. If left unspecified, it will - // default to being determined based on the specified binary. E.g. ghcr.io/cosmos/ibc-go-simd - ChainImageEnv = "CHAIN_IMAGE" - // ChainATagEnv specifies the tag that Chain A will use. - ChainATagEnv = "CHAIN_A_TAG" - // ChainBTagEnv specifies the tag that Chain B will use. If unspecified - // the value will default to the same value as Chain A. - ChainBTagEnv = "CHAIN_B_TAG" - // RelayerIDEnv specifies the ID of the relayer to use. - RelayerIDEnv = "RELAYER_ID" - // ChainBinaryEnv binary is the binary that will be used for both chains. - ChainBinaryEnv = "CHAIN_BINARY" - // ChainUpgradeTagEnv specifies the upgrade version tag - ChainUpgradeTagEnv = "CHAIN_UPGRADE_TAG" - // ChainUpgradePlanEnv specifies the upgrade plan name - ChainUpgradePlanEnv = "CHAIN_UPGRADE_PLAN" - // E2EConfigFilePathEnv allows you to specify a custom path for the config file to be used. - E2EConfigFilePathEnv = "E2E_CONFIG_PATH" - - // defaultBinary is the default binary that will be used by the chains. - defaultBinary = "simd" - // defaultRlyTag is the tag that will be used if no relayer tag is specified. - // all images are here https://github.com/cosmos/relayer/pkgs/container/relayer/versions - defaultRlyTag = "latest" - - // TODO: https://github.com/cosmos/ibc-go/issues/4965 - defaultHyperspaceTag = "20231122v39" - // defaultHermesTag is the tag that will be used if no relayer tag is specified for hermes. - defaultHermesTag = "luca_joss-channel-upgrade-authority" - // defaultChainTag is the tag that will be used for the chains if none is specified. - defaultChainTag = "main" - // defaultConfigFileName is the default filename for the config file that can be used to configure - // e2e tests. See sample.config.yaml as an example for what this should look like. - defaultConfigFileName = ".ibc-go-e2e-config.yaml" -) - -func getChainImage(binary string) string { - if binary == "" { - binary = defaultBinary - } - return fmt.Sprintf("ghcr.io/cosmos/ibc-go-%s", binary) -} - -// TestConfig holds configuration used throughout the different e2e tests. -type TestConfig struct { - // ChainConfigs holds configuration values related to the chains used in the tests. - ChainConfigs []ChainConfig `yaml:"chains"` - // RelayerConfig holds all known relayer configurations that can be used in the tests. - RelayerConfigs []relayer.Config `yaml:"relayers"` - // ActiveRelayer specifies the relayer that will be used. It must match the ID of one of the entries in RelayerConfigs. - ActiveRelayer string `yaml:"activeRelayer"` - // UpgradeConfig holds values used only for the upgrade tests. - UpgradeConfig UpgradeConfig `yaml:"upgrade"` - // CometBFTConfig holds values for configuring CometBFT. - CometBFTConfig CometBFTConfig `yaml:"cometbft"` - // DebugConfig holds configuration for miscellaneous options. - DebugConfig DebugConfig `yaml:"debug"` -} - -// Validate validates the test configuration is valid for use within the tests. -// this should be called before using the configuration. -func (tc TestConfig) Validate() error { - if err := tc.validateChains(); err != nil { - return fmt.Errorf("invalid chain configuration: %w", err) - } - - if err := tc.validateRelayers(); err != nil { - return fmt.Errorf("invalid relayer configuration: %w", err) - } - return nil -} - -// validateChains validates the chain configurations. -func (tc TestConfig) validateChains() error { - for _, cfg := range tc.ChainConfigs { - if cfg.Binary == "" { - return fmt.Errorf("chain config missing binary: %+v", cfg) - } - if cfg.Image == "" { - return fmt.Errorf("chain config missing image: %+v", cfg) - } - if cfg.Tag == "" { - return fmt.Errorf("chain config missing tag: %+v", cfg) - } - - // TODO: validate chainID in https://github.com/cosmos/ibc-go/issues/4697 - // these are not passed in the CI at the moment. Defaults are used. - if !IsCI() { - if cfg.ChainID == "" { - return fmt.Errorf("chain config missing chainID: %+v", cfg) - } - } - - // TODO: validate number of nodes in https://github.com/cosmos/ibc-go/issues/4697 - // these are not passed in the CI at the moment. - if !IsCI() { - if cfg.NumValidators == 0 && cfg.NumFullNodes == 0 { - return fmt.Errorf("chain config missing number of validators or full nodes: %+v", cfg) - } - } - } - return nil -} - -// validateRelayers validates relayer configuration. -func (tc TestConfig) validateRelayers() error { - if len(tc.RelayerConfigs) < 1 { - return fmt.Errorf("no relayer configurations specified") - } - - for _, r := range tc.RelayerConfigs { - if r.ID == "" { - return fmt.Errorf("relayer config missing ID: %+v", r) - } - if r.Image == "" { - return fmt.Errorf("relayer config missing image: %+v", r) - } - if r.Tag == "" { - return fmt.Errorf("relayer config missing tag: %+v", r) - } - } - - if tc.GetActiveRelayerConfig() == nil { - return fmt.Errorf("active relayer %s not found in relayer configs: %+v", tc.ActiveRelayer, tc.RelayerConfigs) - } - - return nil -} - -// GetActiveRelayerConfig returns the currently specified relayer config. -func (tc TestConfig) GetActiveRelayerConfig() *relayer.Config { - for _, r := range tc.RelayerConfigs { - if r.ID == tc.ActiveRelayer { - return &r - } - } - return nil -} - -// GetChainNumValidators returns the number of validators for the specific chain index. -// default 1 -func (tc TestConfig) GetChainNumValidators(idx int) int { - if tc.ChainConfigs[idx].NumValidators > 0 { - return tc.ChainConfigs[idx].NumValidators - } - return 1 -} - -// GetChainNumFullNodes returns the number of full nodes for the specific chain index. -// default 0 -func (tc TestConfig) GetChainNumFullNodes(idx int) int { - if tc.ChainConfigs[idx].NumFullNodes > 0 { - return tc.ChainConfigs[idx].NumFullNodes - } - return 0 -} - -// GetChainAID returns the chain-id for chain A. -func (tc TestConfig) GetChainAID() string { - if tc.ChainConfigs[0].ChainID != "" { - return tc.ChainConfigs[0].ChainID - } - return "chainA-1" -} - -// GetChainBID returns the chain-id for chain B. -func (tc TestConfig) GetChainBID() string { - if tc.ChainConfigs[1].ChainID != "" { - return tc.ChainConfigs[1].ChainID - } - return "chainB-1" -} - -// UpgradeConfig holds values relevant to upgrade tests. -type UpgradeConfig struct { - PlanName string `yaml:"planName"` - Tag string `yaml:"tag"` -} - -// ChainConfig holds information about an individual chain used in the tests. -type ChainConfig struct { - ChainID string `yaml:"chainId"` - Image string `yaml:"image"` - Tag string `yaml:"tag"` - Binary string `yaml:"binary"` - NumValidators int `yaml:"numValidators"` - NumFullNodes int `yaml:"numFullNodes"` -} - -type CometBFTConfig struct { - LogLevel string `yaml:"logLevel"` -} - -type DebugConfig struct { - // DumpLogs forces the logs to be collected before removing test containers. - DumpLogs bool `yaml:"dumpLogs"` -} - -// LoadConfig attempts to load a atest configuration from the default file path. -// if any environment variables are specified, they will take precedence over the individual configuration -// options. -func LoadConfig() TestConfig { - tc := getConfig() - if err := tc.Validate(); err != nil { - panic(err) - } - return tc -} - -// getConfig returns the TestConfig with any environment variable overrides. -func getConfig() TestConfig { - fileTc, foundFile := fromFile() - if !foundFile { - return fromEnv() - } - - return applyEnvironmentVariableOverrides(fileTc) -} - -// fromFile returns a TestConfig from a json file and a boolean indicating if the file was found. -func fromFile() (TestConfig, bool) { - var tc TestConfig - bz, err := os.ReadFile(getConfigFilePath()) - if err != nil { - return TestConfig{}, false - } - - if err := yaml.Unmarshal(bz, &tc); err != nil { - panic(err) - } - - return tc, true -} - -// applyEnvironmentVariableOverrides applies all environment variable changes to the config -// loaded from a file. -func applyEnvironmentVariableOverrides(fromFile TestConfig) TestConfig { - envTc := fromEnv() - - if os.Getenv(ChainATagEnv) != "" { - fromFile.ChainConfigs[0].Tag = envTc.ChainConfigs[0].Tag - } - - if os.Getenv(ChainBTagEnv) != "" { - fromFile.ChainConfigs[1].Tag = envTc.ChainConfigs[1].Tag - } - - if os.Getenv(ChainBinaryEnv) != "" { - for i := range fromFile.ChainConfigs { - fromFile.ChainConfigs[i].Binary = envTc.ChainConfigs[i].Binary - } - } - - if os.Getenv(ChainImageEnv) != "" { - for i := range fromFile.ChainConfigs { - fromFile.ChainConfigs[i].Image = envTc.ChainConfigs[i].Image - } - } - - if os.Getenv(RelayerIDEnv) != "" { - fromFile.ActiveRelayer = envTc.ActiveRelayer - } - - if os.Getenv(ChainUpgradePlanEnv) != "" { - fromFile.UpgradeConfig.PlanName = envTc.UpgradeConfig.PlanName - } - - if os.Getenv(ChainUpgradeTagEnv) != "" { - fromFile.UpgradeConfig.Tag = envTc.UpgradeConfig.Tag - } - - return fromFile -} - -// fromEnv returns a TestConfig constructed from environment variables. -func fromEnv() TestConfig { - return TestConfig{ - ChainConfigs: getChainConfigsFromEnv(), - UpgradeConfig: getUpgradePlanConfigFromEnv(), - ActiveRelayer: os.Getenv(RelayerIDEnv), - - // TODO: we can remove this, and specify these values in a config file for the CI - // in https://github.com/cosmos/ibc-go/issues/4697 - RelayerConfigs: []relayer.Config{ - getDefaultRlyRelayerConfig(), - getDefaultHermesRelayerConfig(), - getDefaultHyperspaceRelayerConfig(), - }, - CometBFTConfig: CometBFTConfig{LogLevel: "info"}, - } -} - -// getChainConfigsFromEnv returns the chain configs from environment variables. -func getChainConfigsFromEnv() []ChainConfig { - chainBinary, ok := os.LookupEnv(ChainBinaryEnv) - if !ok { - chainBinary = defaultBinary - } - - chainATag, ok := os.LookupEnv(ChainATagEnv) - if !ok { - chainATag = defaultChainTag - } - - chainBTag, ok := os.LookupEnv(ChainBTagEnv) - if !ok { - chainBTag = chainATag - } - - chainAImage := getChainImage(chainBinary) - specifiedChainImage, ok := os.LookupEnv(ChainImageEnv) - if ok { - chainAImage = specifiedChainImage - } - - numValidators := 4 - numFullNodes := 1 - - chainBImage := chainAImage - return []ChainConfig{ - { - Image: chainAImage, - Tag: chainATag, - Binary: chainBinary, - NumValidators: numValidators, - NumFullNodes: numFullNodes, - }, - { - Image: chainBImage, - Tag: chainBTag, - Binary: chainBinary, - NumValidators: numValidators, - NumFullNodes: numFullNodes, - }, - } -} - -// getConfigFilePath returns the absolute path where the e2e config file should be. -func getConfigFilePath() string { - if absoluteConfigPath := os.Getenv(E2EConfigFilePathEnv); absoluteConfigPath != "" { - return absoluteConfigPath - } - - homeDir, err := os.UserHomeDir() - if err != nil { - panic(err) - } - return path.Join(homeDir, defaultConfigFileName) -} - -// TODO: remove in https://github.com/cosmos/ibc-go/issues/4697 -// getDefaultHermesRelayerConfig returns the default config for the hermes relayer. -func getDefaultHermesRelayerConfig() relayer.Config { - return relayer.Config{ - Tag: defaultHermesTag, - ID: relayer.Hermes, - Image: relayer.HermesRelayerRepository, - } -} - -// TODO: remove in https://github.com/cosmos/ibc-go/issues/4697 -// getDefaultRlyRelayerConfig returns the default config for the golang relayer. -func getDefaultRlyRelayerConfig() relayer.Config { - return relayer.Config{ - Tag: defaultRlyTag, - ID: relayer.Rly, - Image: relayer.RlyRelayerRepository, - } -} - -// TODO: remove in https://github.com/cosmos/ibc-go/issues/4697 -// getDefaultHyperspaceRelayerConfig returns the default config for the hyperspace relayer. -func getDefaultHyperspaceRelayerConfig() relayer.Config { - return relayer.Config{ - Tag: defaultHyperspaceTag, - ID: relayer.Hyperspace, - Image: relayer.HyperspaceRelayerRepository, - } -} - -// getUpgradePlanConfigFromEnv returns the upgrade config from environment variables. -func getUpgradePlanConfigFromEnv() UpgradeConfig { - upgradeTag, ok := os.LookupEnv(ChainUpgradeTagEnv) - if !ok { - upgradeTag = "" - } - - upgradePlan, ok := os.LookupEnv(ChainUpgradePlanEnv) - if !ok { - upgradePlan = "" - } - return UpgradeConfig{ - PlanName: upgradePlan, - Tag: upgradeTag, - } -} - -func GetChainATag() string { - return LoadConfig().ChainConfigs[0].Tag -} - -func GetChainBTag() string { - if chainBTag := LoadConfig().ChainConfigs[1].Tag; chainBTag != "" { - return chainBTag - } - return GetChainATag() -} - -// IsCI returns true if the tests are running in CI, false is returned -// if the tests are running locally. -// Note: github actions passes a CI env value of true by default to all runners. -func IsCI() bool { - return strings.ToLower(os.Getenv("CI")) == "true" -} - -// IsFork returns true if the tests are running in fork mode, false is returned otherwise. -func IsFork() bool { - return strings.ToLower(os.Getenv("FORK")) == "true" -} - -// ChainOptions stores chain configurations for the chains that will be -// created for the tests. They can be modified by passing ChainOptionConfiguration -// to E2ETestSuite.GetChains. -type ChainOptions struct { - ChainASpec *interchaintest.ChainSpec - ChainBSpec *interchaintest.ChainSpec - SkipPathCreation bool -} - -// ChainOptionConfiguration enables arbitrary configuration of ChainOptions. -type ChainOptionConfiguration func(options *ChainOptions) - -// DefaultChainOptions returns the default configuration for the chains. -// These options can be configured by passing configuration functions to E2ETestSuite.GetChains. -func DefaultChainOptions() ChainOptions { - tc := LoadConfig() - - chainACfg := newDefaultSimappConfig(tc.ChainConfigs[0], "simapp-a", tc.GetChainAID(), "atoma", tc.CometBFTConfig) - chainBCfg := newDefaultSimappConfig(tc.ChainConfigs[1], "simapp-b", tc.GetChainBID(), "atomb", tc.CometBFTConfig) - - chainAVal, chainAFn := getValidatorsAndFullNodes(0) - chainBVal, chainBFn := getValidatorsAndFullNodes(1) - - return ChainOptions{ - ChainASpec: &interchaintest.ChainSpec{ - ChainConfig: chainACfg, - NumFullNodes: &chainAFn, - NumValidators: &chainAVal, - }, - ChainBSpec: &interchaintest.ChainSpec{ - ChainConfig: chainBCfg, - NumFullNodes: &chainBFn, - NumValidators: &chainBVal, - }, - } -} - -// newDefaultSimappConfig creates an ibc configuration for simd. -func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string, cometCfg CometBFTConfig) ibc.ChainConfig { - configFileOverrides := make(map[string]any) - tmTomlOverrides := make(interchaintestutil.Toml) - - tmTomlOverrides["log_level"] = cometCfg.LogLevel // change to debug in ~/.ibc-go-e2e-config.json to increase cometbft logging. - configFileOverrides["config/config.toml"] = tmTomlOverrides - - return ibc.ChainConfig{ - Type: "cosmos", - Name: name, - ChainID: chainID, - Images: []ibc.DockerImage{ - { - Repository: cc.Image, - Version: cc.Tag, - UidGid: "1000:1000", - }, - }, - Bin: cc.Binary, - Bech32Prefix: "cosmos", - CoinType: fmt.Sprint(sdk.GetConfig().GetCoinType()), - Denom: denom, - EncodingConfig: SDKEncodingConfig(), - GasPrices: fmt.Sprintf("0.00%s", denom), - GasAdjustment: 1.3, - TrustingPeriod: "508h", - NoHostMount: false, - ModifyGenesis: getGenesisModificationFunction(cc), - ConfigFileOverrides: configFileOverrides, - } -} - -// getGenesisModificationFunction returns a genesis modification function that handles the GenesisState type -// correctly depending on if the govv1beta1 gov module is used or if govv1 is being used. -func getGenesisModificationFunction(cc ChainConfig) func(ibc.ChainConfig, []byte) ([]byte, error) { - binary := cc.Binary - version := cc.Tag - - simdSupportsGovV1Genesis := binary == defaultBinary && testvalues.GovGenesisFeatureReleases.IsSupported(version) - - if simdSupportsGovV1Genesis { - return defaultGovv1ModifyGenesis(version) - } - - return defaultGovv1Beta1ModifyGenesis(version) -} - -// defaultGovv1ModifyGenesis will only modify governance params to ensure the voting period and minimum deposit -// are functional for e2e testing purposes. -func defaultGovv1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([]byte, error) { - stdlibJSONMarshalling := semverutil.FeatureReleases{MajorVersion: "v8"} - return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { - appGenesis, err := genutiltypes.AppGenesisFromReader(bytes.NewReader(genbz)) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err) - } - - var appState genutiltypes.AppMap - if err := json.Unmarshal(appGenesis.AppState, &appState); err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis bytes into app state: %w", err) - } - - govGenBz, err := modifyGovV1AppState(chainConfig, appState[govtypes.ModuleName]) - if err != nil { - return nil, err - } - appState[govtypes.ModuleName] = govGenBz - - if !testvalues.AllowAllClientsWildcardFeatureReleases.IsSupported(version) { - ibcGenBz, err := modifyClientGenesisAppState(appState[ibcexported.ModuleName]) - if err != nil { - return nil, err - } - appState[ibcexported.ModuleName] = ibcGenBz - } - - appGenesis.AppState, err = json.Marshal(appState) - if err != nil { - return nil, err - } - - // in older version < v8, tmjson marshal must be used. - // regular json marshalling must be used for v8 and above as the - // sdk is de-coupled from comet. - marshalIndentFn := cmtjson.MarshalIndent - if stdlibJSONMarshalling.IsSupported(version) { - marshalIndentFn = json.MarshalIndent - } - - bz, err := marshalIndentFn(appGenesis, "", " ") - if err != nil { - return nil, err - } - - return bz, nil - } -} - -// defaultGovv1Beta1ModifyGenesis will only modify governance params to ensure the voting period and minimum deposit -// // are functional for e2e testing purposes. -func defaultGovv1Beta1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([]byte, error) { - const appStateKey = "app_state" - return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { - genesisDocMap := map[string]interface{}{} - err := json.Unmarshal(genbz, &genesisDocMap) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err) - } - - appStateMap, ok := genesisDocMap[appStateKey].(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("failed to extract to app_state") - } - - govModuleBytes, err := json.Marshal(appStateMap[govtypes.ModuleName]) - if err != nil { - return nil, fmt.Errorf("failed to extract gov genesis bytes: %s", err) - } - - govModuleGenesisBytes, err := modifyGovv1Beta1AppState(chainConfig, govModuleBytes) - if err != nil { - return nil, err - } - - govModuleGenesisMap := map[string]interface{}{} - err = json.Unmarshal(govModuleGenesisBytes, &govModuleGenesisMap) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal gov genesis bytes into map: %w", err) - } - - if !testvalues.AllowAllClientsWildcardFeatureReleases.IsSupported(version) { - ibcModuleBytes, err := json.Marshal(appStateMap[ibcexported.ModuleName]) - if err != nil { - return nil, fmt.Errorf("failed to extract ibc genesis bytes: %s", err) - } - - ibcGenesisBytes, err := modifyClientGenesisAppState(ibcModuleBytes) - if err != nil { - return nil, err - } - - ibcModuleGenesisMap := map[string]interface{}{} - err = json.Unmarshal(ibcGenesisBytes, &ibcModuleGenesisMap) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal gov genesis bytes into map: %w", err) - } - } - - appStateMap[govtypes.ModuleName] = govModuleGenesisMap - genesisDocMap[appStateKey] = appStateMap - - finalGenesisDocBytes, err := json.MarshalIndent(genesisDocMap, "", " ") - if err != nil { - return nil, err - } - - return finalGenesisDocBytes, nil - } -} - -// modifyGovV1AppState takes the existing gov app state and marshals it to a govv1 GenesisState. -func modifyGovV1AppState(chainConfig ibc.ChainConfig, govAppState []byte) ([]byte, error) { - cfg := testutil.MakeTestEncodingConfig() - - cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) - govv1.RegisterInterfaces(cfg.InterfaceRegistry) - - govGenesisState := &govv1.GenesisState{} - - if err := cdc.UnmarshalJSON(govAppState, govGenesisState); err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis bytes into gov genesis state: %w", err) - } - - if govGenesisState.Params == nil { - govGenesisState.Params = &govv1.Params{} - } - - govGenesisState.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(chainConfig.Denom, govv1beta1.DefaultMinDepositTokens)) - maxDep := time.Second * 10 - govGenesisState.Params.MaxDepositPeriod = &maxDep - vp := testvalues.VotingPeriod - govGenesisState.Params.VotingPeriod = &vp - - govGenBz := MustProtoMarshalJSON(govGenesisState) - - return govGenBz, nil -} - -// modifyGovv1Beta1AppState takes the existing gov app state and marshals it to a govv1beta1 GenesisState. -func modifyGovv1Beta1AppState(chainConfig ibc.ChainConfig, govAppState []byte) ([]byte, error) { - cfg := testutil.MakeTestEncodingConfig() - - cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) - govv1beta1.RegisterInterfaces(cfg.InterfaceRegistry) - - govGenesisState := &govv1beta1.GenesisState{} - if err := cdc.UnmarshalJSON(govAppState, govGenesisState); err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis bytes into govv1beta1 genesis state: %w", err) - } - - govGenesisState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(chainConfig.Denom, govv1beta1.DefaultMinDepositTokens)) - govGenesisState.VotingParams.VotingPeriod = testvalues.VotingPeriod - - govGenBz, err := cdc.MarshalJSON(govGenesisState) - if err != nil { - return nil, fmt.Errorf("failed to marshal gov genesis state: %w", err) - } - - return govGenBz, nil -} - -// modifyClientGenesisAppState takes the existing ibc app state and marshals it to an ibc GenesisState. -func modifyClientGenesisAppState(ibcAppState []byte) ([]byte, error) { - cfg := testutil.MakeTestEncodingConfig() - - cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) - clienttypes.RegisterInterfaces(cfg.InterfaceRegistry) - - ibcGenesisState := &ibctypes.GenesisState{} - if err := cdc.UnmarshalJSON(ibcAppState, ibcGenesisState); err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis bytes into client genesis state: %w", err) - } - - ibcGenesisState.ClientGenesis.Params.AllowedClients = append(ibcGenesisState.ClientGenesis.Params.AllowedClients, wasmtypes.Wasm) - ibcGenBz, err := cdc.MarshalJSON(ibcGenesisState) - if err != nil { - return nil, fmt.Errorf("failed to marshal gov genesis state: %w", err) - } - - return ibcGenBz, nil -} diff --git a/modules/apps/27-interchain-accounts/controller/client/cli/tx.go b/modules/apps/27-interchain-accounts/controller/client/cli/tx.go index 95a1fd42988..7ca3d5cd3ff 100644 --- a/modules/apps/27-interchain-accounts/controller/client/cli/tx.go +++ b/modules/apps/27-interchain-accounts/controller/client/cli/tx.go @@ -11,15 +11,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/cobra" -<<<<<<< HEAD "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" -======= - "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) const ( @@ -59,7 +54,7 @@ the associated capability.`), return err } - msg := types.NewMsgRegisterInterchainAccount(connectionID, owner, version, order) + msg := types.NewMsgRegisterInterchainAccountWithOrdering(connectionID, owner, version, order) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go index d4d24a54b02..9eea42e851e 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -754,376 +754,6 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { } } -<<<<<<< HEAD -======= -func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() { - var ( - path *ibctesting.Path - isNilApp bool - version string - channelOrder channeltypes.Order - ) - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success w/ ORDERED channel", func() {}, nil, - }, - { - "success w/ UNORDERED channel", func() { - channelOrder = channeltypes.UNORDERED - }, nil, - }, - { - "success: nil underlying app", - func() { - isNilApp = true - }, - nil, - }, - { - "controller submodule disabled", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false)) - }, types.ErrControllerSubModuleDisabled, - }, - { - "ICA OnChanUpgradeInit fails - invalid version", func() { - version = invalidVersion - }, icatypes.ErrUnknownDataType, - }, - { - "ICA auth module callback fails", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { - return "", ibcmock.MockApplicationCallbackError - } - }, ibcmock.MockApplicationCallbackError, - }, - { - "middleware disabled", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { - return "", ibcmock.MockApplicationCallbackError - } - }, nil, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - isNilApp = false - - path = NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress) - suite.Require().NoError(err) - - metadata := icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) - version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - - tc.malleate() // malleate mutates test data - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - cbs, ok := app.(porttypes.UpgradableModule) - suite.Require().True(ok) - - if isNilApp { - cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) - } - - channelOrder = channeltypes.ORDERED - - version, err = cbs.OnChanUpgradeInit( - suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, - path.EndpointA.ChannelID, - channelOrder, - []string{path.EndpointA.ConnectionID}, - version, - ) - - if tc.expError == nil { - suite.Require().NoError(err) - } else { - suite.Require().ErrorIs(err, tc.expError) - suite.Require().Empty(version) - } - }) - } -} - -// OnChanUpgradeTry callback returns error on controller chains -func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeTry() { - suite.SetupTest() // reset - path := NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - // call application callback directly - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - cbs, ok := app.(porttypes.UpgradableModule) - suite.Require().True(ok) - - version, err := cbs.OnChanUpgradeTry( - suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, - path.EndpointA.ChannelConfig.Order, []string{path.EndpointA.ConnectionID}, path.EndpointB.ChannelConfig.Version, - ) - suite.Require().Error(err) - suite.Require().ErrorIs(err, icatypes.ErrInvalidChannelFlow) - suite.Require().Equal("", version) -} - -func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() { - var ( - path *ibctesting.Path - isNilApp bool - counterpartyVersion string - ) - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", func() {}, nil, - }, - { - "success: nil underlying app", - func() { - isNilApp = true - }, - nil, - }, - { - "controller submodule disabled", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false)) - }, types.ErrControllerSubModuleDisabled, - }, - { - "ICA OnChanUpgradeAck fails - invalid version", func() { - counterpartyVersion = invalidVersion - }, icatypes.ErrUnknownDataType, - }, - { - "ICA auth module callback fails", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { - return ibcmock.MockApplicationCallbackError - } - }, ibcmock.MockApplicationCallbackError, - }, - { - "middleware disabled", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { - return ibcmock.MockApplicationCallbackError - } - }, nil, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - isNilApp = false - - path = NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - counterpartyVersion = path.EndpointB.GetChannel().Version - - tc.malleate() // malleate mutates test data - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - cbs, ok := app.(porttypes.UpgradableModule) - suite.Require().True(ok) - - if isNilApp { - cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) - } - - err = cbs.OnChanUpgradeAck( - suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, - path.EndpointA.ChannelID, - counterpartyVersion, - ) - - if tc.expError == nil { - suite.Require().NoError(err) - } else { - suite.Require().ErrorIs(err, tc.expError) - } - }) - } -} - -func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeOpen() { - var ( - path *ibctesting.Path - isNilApp bool - counterpartyVersion string - channelOrder channeltypes.Order - ) - - testCases := []struct { - name string - malleate func() - }{ - { - "success w/ ORDERED channel", func() {}, - }, - { - "success w/ UNORDERED channel", func() { - channelOrder = channeltypes.UNORDERED - }, - }, - { - "success: nil app", - func() { - isNilApp = true - }, - }, - { - "middleware disabled", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { - return ibcmock.MockApplicationCallbackError - } - }, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - isNilApp = false - - path = NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - counterpartyVersion = path.EndpointB.GetChannel().Version - - tc.malleate() // malleate mutates test data - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - cbs, ok := app.(porttypes.UpgradableModule) - suite.Require().True(ok) - - if isNilApp { - cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) - } - - channelOrder = channeltypes.ORDERED - - cbs.OnChanUpgradeOpen( - suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, - path.EndpointA.ChannelID, - channelOrder, - []string{path.EndpointA.ConnectionID}, - counterpartyVersion, - ) - }) - } -} - -func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeRestore() { - var ( - path *ibctesting.Path - isNilApp bool - ) - - testCases := []struct { - name string - malleate func() - }{ - { - "success", func() {}, - }, - { - "success: nil app", - func() { - isNilApp = true - }, - }, - { - "middleware disabled", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { - return ibcmock.MockApplicationCallbackError - } - }, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - isNilApp = false - - path = NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - tc.malleate() // malleate mutates test data - - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) - suite.Require().True(ok) - cbs, ok := app.(porttypes.UpgradableModule) - suite.Require().True(ok) - - if isNilApp { - cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper) - } - - cbs.OnChanUpgradeRestore(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }) - } -} - ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() { var ( pathAToB *ibctesting.Path @@ -1220,7 +850,7 @@ func (suite *InterchainAccountsTestSuite) TestInFlightHandshakeRespectsGoAPICall // attempt to start a second handshake via the controller msg server msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion, channeltypes.ORDERED) + msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion) res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount) suite.Require().Error(err) @@ -1233,7 +863,7 @@ func (suite *InterchainAccountsTestSuite) TestInFlightHandshakeRespectsMsgServer // initiate a channel handshake such that channel.State == INIT msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion, channeltypes.ORDERED) + msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), TestVersion) res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount) suite.Require().NotNil(res) @@ -1266,7 +896,7 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer( // route a new MsgRegisterInterchainAccount in order to reopen the msgServer := controllerkeeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) - msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), path.EndpointA.ChannelConfig.Version, channeltypes.ORDERED) + msgRegisterInterchainAccount := types.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, suite.chainA.SenderAccount.GetAddress().String(), path.EndpointA.ChannelConfig.Version) res, err := msgServer.RegisterInterchainAccount(suite.chainA.GetContext(), msgRegisterInterchainAccount) suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 4d6c625762a..fa0da1166d2 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -28,13 +28,6 @@ func (k Keeper) OnChanOpenInit( counterparty channeltypes.Counterparty, version string, ) (string, error) { -<<<<<<< HEAD - if order != channeltypes.ORDERED { - return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) - } - -======= ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) if !strings.HasPrefix(portID, icatypes.ControllerPortPrefix) { return "", sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) } @@ -68,17 +61,12 @@ func (k Keeper) OnChanOpenInit( panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } -<<<<<<< HEAD - if channel.State == channeltypes.OPEN { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) -======= if channel.State != channeltypes.CLOSED { - return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s must be %s", activeChannelID, portID, channeltypes.CLOSED) + return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s must be %s", activeChannelID, portID, channeltypes.CLOSED) } if channel.Ordering != order { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "order cannot change when reopening a channel expected %s, got %s", channel.Ordering, order) ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) + return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "order cannot change when reopening a channel expected %s, got %s", channel.Ordering, order) } appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) @@ -146,127 +134,3 @@ func (k Keeper) OnChanCloseConfirm( ) error { return nil } -<<<<<<< HEAD -======= - -// OnChanUpgradeInit performs the upgrade init step of the channel upgrade handshake. -// The upgrade init callback must verify the proposed changes to the order, connectionHops, and version. -// Within the version we have the tx type, encoding, interchain account address, host/controller connectionID's -// and the ICS27 protocol version. -// -// The following may be changed: -// - tx type (must be supported) -// - encoding (must be supported) -// - order -// -// The following may not be changed: -// - connectionHops (and subsequently host/controller connectionIDs) -// - interchain account address -// - ICS27 protocol version -func (k Keeper) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedversion string) (string, error) { - // verify connection hops has not changed - connectionID, err := k.GetConnectionID(ctx, portID, channelID) - if err != nil { - return "", err - } - - if len(proposedConnectionHops) != 1 || proposedConnectionHops[0] != connectionID { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidUpgrade, "expected connection hops %s, got %s", []string{connectionID}, proposedConnectionHops) - } - - // verify proposed version only modifies tx type or encoding - if strings.TrimSpace(proposedversion) == "" { - return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "version cannot be empty") - } - - proposedMetadata, err := icatypes.MetadataFromVersion(proposedversion) - if err != nil { - return "", err - } - - currentMetadata, err := k.getAppMetadata(ctx, portID, channelID) - if err != nil { - return "", err - } - - // ValidateControllerMetadata will ensure the ICS27 protocol version has not changed and that the - // tx type and encoding are supported - if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, proposedConnectionHops, proposedMetadata); err != nil { - return "", errorsmod.Wrap(err, "invalid upgrade metadata") - } - - // the interchain account address on the host chain - // must remain the same after the upgrade. - if currentMetadata.Address != proposedMetadata.Address { - return "", errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be changed") - } - - if currentMetadata.ControllerConnectionId != proposedMetadata.ControllerConnectionId { - return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change") - } - - if currentMetadata.HostConnectionId != proposedMetadata.HostConnectionId { - return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed host connection ID must not change") - } - - return proposedversion, nil -} - -// OnChanUpgradeAck implements the ack setup of the channel upgrade handshake. -// The upgrade ack callback must verify the proposed changes to the channel version. -// Within the channel version we have the tx type, encoding, interchain account address, host/controller connectionID's -// and the ICS27 protocol version. -// -// The following may be changed: -// - tx type (must be supported) -// - encoding (must be supported) -// -// The following may not be changed: -// - controller connectionID -// - host connectionID -// - interchain account address -// - ICS27 protocol version -func (k Keeper) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { - if strings.TrimSpace(counterpartyVersion) == "" { - return errorsmod.Wrap(channeltypes.ErrInvalidChannelVersion, "counterparty version cannot be empty") - } - - proposedMetadata, err := icatypes.MetadataFromVersion(counterpartyVersion) - if err != nil { - return err - } - - currentMetadata, err := k.getAppMetadata(ctx, portID, channelID) - if err != nil { - return err - } - - channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) - if !found { - return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) - } - - // ValidateControllerMetadata will ensure the ICS27 protocol version has not changed and that the - // tx type and encoding are supported. Note, we pass in the current channel connection hops. The upgrade init - // step will verify that the proposed connection hops will not change. - if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, channel.ConnectionHops, proposedMetadata); err != nil { - return errorsmod.Wrap(err, "invalid upgrade metadata") - } - - // the interchain account address on the host chain - // must remain the same after the upgrade. - if currentMetadata.Address != proposedMetadata.Address { - return errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "address cannot be changed") - } - - if currentMetadata.ControllerConnectionId != proposedMetadata.ControllerConnectionId { - return errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change") - } - - if currentMetadata.HostConnectionId != proposedMetadata.HostConnectionId { - return errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed host connection ID must not change") - } - - return nil -} ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index 347a7642b32..75add555418 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -4,6 +4,7 @@ import ( capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v7/testing" @@ -232,23 +233,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { }, icatypes.ErrActiveChannelAlreadySet, }, - { - "channel is already active (FLUSHING state)", - func() { - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - - counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - channel := channeltypes.Channel{ - State: channeltypes.FLUSHING, - Ordering: channeltypes.ORDERED, - Counterparty: counterparty, - ConnectionHops: []string{path.EndpointA.ConnectionID}, - Version: TestVersion, - } - suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) - }, - icatypes.ErrActiveChannelAlreadySet, - }, } for _, tc := range testCases { @@ -500,360 +484,3 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { }) } } -<<<<<<< HEAD -======= - -func (suite *KeeperTestSuite) TestOnChanUpgradeInit() { - const ( - invalidVersion = "invalid-version" - ) - - var ( - path *ibctesting.Path - metadata icatypes.Metadata - version string - order channeltypes.Order - ) - - // updateMetadata is a helper function which modifies the metadata stored in the channel version - // and marshals it into a string to pass to OnChanUpgradeInit as the version string. - updateMetadata := func(modificationFn func(*icatypes.Metadata)) { - metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) - suite.Require().NoError(err) - modificationFn(&metadata) - version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - } - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() {}, - nil, - }, - { - name: "success: change order", - malleate: func() { - order = channeltypes.UNORDERED - }, - expError: nil, - }, - { - name: "failure: connectionID not found", - malleate: func() { - // channelID is provided via the endpoint channelID - path.EndpointA.ChannelID = "invalid channel" - }, - expError: channeltypes.ErrChannelNotFound, - }, - { - name: "failure: invalid proposed connectionHops", - malleate: func() { - // connection hops is provided via endpoint connectionID - path.EndpointA.ConnectionID = differentConnectionID - }, - expError: channeltypes.ErrInvalidUpgrade, - }, - { - name: "failure: empty version", - malleate: func() { - version = "" - }, - expError: icatypes.ErrInvalidVersion, - }, - { - name: "failure: cannot decode version string", - malleate: func() { - version = invalidVersion - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: cannot decode self version string", - malleate: func() { - ch := path.EndpointA.GetChannel() - ch.Version = invalidVersion - path.EndpointA.SetChannel(ch) - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: failed controller metadata validation, invalid encoding", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Encoding = "invalid-encoding" - }) - }, - expError: icatypes.ErrInvalidCodec, - }, - { - name: "failure: failed controller metadata validation, invalid tx type", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.TxType = "invalid-tx-type" - }) - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: failed controller metadata validation, invalid interchain account version", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Version = "invalid-interchain-account-version" - }) - }, - expError: icatypes.ErrInvalidVersion, - }, - { - name: "failure: interchain account address changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Address = TestOwnerAddress // use valid address - }) - }, - expError: icatypes.ErrInvalidAccountAddress, - }, - { - name: "failure: controller connection ID has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.ControllerConnectionId = differentConnectionID - }) - }, - expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller connection identifier are unreachable - }, - { - name: "failure: host connection ID has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.HostConnectionId = differentConnectionID - }) - }, - expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host connection identifier are unreachable - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - - path = NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - currentMetadata, err := suite.chainA.GetSimApp().ICAControllerKeeper.GetAppMetadata(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - suite.Require().NoError(err) - - order = channeltypes.ORDERED - metadata = icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) - // use the same address as the previous metadata. - metadata.Address = currentMetadata.Address - - // this is the actual change to the version. - metadata.Encoding = icatypes.EncodingProto3JSON - - path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - - version = path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version - - tc.malleate() // malleate mutates test data - - upgradeVersion, err := path.EndpointA.Chain.GetSimApp().ICAControllerKeeper.OnChanUpgradeInit( - path.EndpointA.Chain.GetContext(), - path.EndpointA.ChannelConfig.PortID, - path.EndpointA.ChannelID, - order, - []string{path.EndpointA.ConnectionID}, - version, - ) - - expPass := tc.expError == nil - - if expPass { - suite.Require().NoError(err) - suite.Require().Equal(upgradeVersion, version) - } else { - suite.Require().ErrorIs(err, tc.expError) - } - }) - } -} - -func (suite *KeeperTestSuite) TestOnChanUpgradeAck() { - const ( - invalidVersion = "invalid-version" - ) - - var ( - path *ibctesting.Path - metadata icatypes.Metadata - counterpartyVersion string - ) - - // updateMetadata is a helper function which modifies the metadata stored in the channel version - // and marshals it into a string to pass to OnChanUpgradeAck as the counterpartyVersion string. - updateMetadata := func(modificationFn func(*icatypes.Metadata)) { - metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) - suite.Require().NoError(err) - modificationFn(&metadata) - counterpartyVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - } - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() {}, - nil, - }, - { - name: "failure: empty counterparty version", - malleate: func() { - counterpartyVersion = "" - }, - expError: channeltypes.ErrInvalidChannelVersion, - }, - { - name: "failure: invalid counterparty version", - malleate: func() { - counterpartyVersion = invalidVersion - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: cannot decode self version string", - malleate: func() { - channel := path.EndpointA.GetChannel() - channel.Version = invalidVersion - path.EndpointA.SetChannel(channel) - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: channel not found", - malleate: func() { - // channelID is provided via the endpoint channelID - path.EndpointA.ChannelID = "invalid channel" - }, - expError: ibcerrors.ErrNotFound, // GetChannel error is unreachable - }, - { - name: "failure: failed controller metadata validation, invalid encoding", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Encoding = "invalid-encoding" - }) - }, - expError: icatypes.ErrInvalidCodec, - }, - { - name: "failure: failed controller metadata validation, invalid tx type", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.TxType = "invalid-tx-type" - }) - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: failed controller metadata validation, invalid interchain account version", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Version = "invalid-interchain-account-version" - }) - }, - expError: icatypes.ErrInvalidVersion, - }, - { - name: "failure: interchain account address changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Address = TestOwnerAddress // use valid address - }) - }, - expError: icatypes.ErrInvalidAccountAddress, - }, - { - name: "failure: controller connection ID has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.ControllerConnectionId = differentConnectionID - }) - }, - expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller identifier are unreachable - }, - { - name: "failure: host connection ID has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.HostConnectionId = differentConnectionID - }) - }, - expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host identifier are unreachable - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - - path = NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - currentMetadata, err := suite.chainA.GetSimApp().ICAControllerKeeper.GetAppMetadata(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - suite.Require().NoError(err) - - metadata = icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) - // use the same address as the previous metadata. - metadata.Address = currentMetadata.Address - - // this is the actual change to the version. - metadata.Encoding = icatypes.EncodingProto3JSON - - path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - - err = path.EndpointA.ChanUpgradeInit() - suite.Require().NoError(err) - - err = path.EndpointB.ChanUpgradeTry() - suite.Require().NoError(err) - - counterpartyVersion = path.EndpointB.GetChannel().Version - - tc.malleate() // malleate mutates test data - - err = suite.chainA.GetSimApp().ICAControllerKeeper.OnChanUpgradeAck( - suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, - path.EndpointA.ChannelID, - counterpartyVersion, - ) - - expPass := tc.expError == nil - if expPass { - suite.Require().NoError(err) - suite.Require().Equal(path.EndpointA.GetChannel().Version, counterpartyVersion) - } else { - suite.Require().ErrorIs(err, tc.expError) - } - }) - } -} ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go index 43f7b476a45..44585b2eea4 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server_test.go @@ -71,11 +71,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount_MsgServer() { msg = types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") -<<<<<<< HEAD tc.malleate() -======= - msg = types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "", channeltypes.ORDERED) ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ctx := suite.chainA.GetContext() msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAControllerKeeper) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index 13fe111822f..0e417c8fac0 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -6,26 +6,32 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -<<<<<<< HEAD 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" -======= - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v8/modules/core/24-host" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) var _ sdk.Msg = &MsgRegisterInterchainAccount{} -// NewMsgRegisterInterchainAccount creates a new instance of MsgRegisterInterchainAccount -func NewMsgRegisterInterchainAccount(connectionID, owner, version string, order channeltypes.Order) *MsgRegisterInterchainAccount { +// NewMsgRegisterInterchainAccountWithOrdering creates a new instance of MsgRegisterInterchainAccount. +func NewMsgRegisterInterchainAccountWithOrdering(connectionID, owner, version string, ordering channeltypes.Order) *MsgRegisterInterchainAccount { return &MsgRegisterInterchainAccount{ ConnectionId: connectionID, Owner: owner, Version: version, - Order: order, + Order: ordering, + } +} + +// NewMsgRegisterInterchainAccount creates a new instance of MsgRegisterInterchainAccount. +// It uses channeltypes.ORDERED as the default ordering. Breakage in v9.0.0 will allow the ordering to be provided +// directly. Use NewMsgRegisterInterchainAccountWithOrder to provide the ordering in previous versions. +func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRegisterInterchainAccount { + return &MsgRegisterInterchainAccount{ + ConnectionId: connectionID, + Owner: owner, + Version: version, + Order: channeltypes.ORDERED, } } diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index a6462ae1a7a..e5afa00c93e 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -8,24 +8,11 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" -<<<<<<< HEAD "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/cosmos/ibc-go/v7/testing/simapp" -======= - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" - "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { @@ -83,7 +70,6 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { ibctesting.FirstConnectionID, ibctesting.TestAccAddress, icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID), - channeltypes.ORDERED, ) tc.malleate() @@ -101,16 +87,8 @@ func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) require.NoError(t, err) -<<<<<<< HEAD msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners()) -======= - msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "", channeltypes.ORDERED) - encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) - signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) - require.NoError(t, err) - require.Equal(t, expSigner.Bytes(), signers[0]) ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } func TestMsgSendTxValidateBasic(t *testing.T) { diff --git a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go index 6d091375dc7..e1c2e69ed6d 100644 --- a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go +++ b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go @@ -9,12 +9,8 @@ import ( _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" -<<<<<<< HEAD - types "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" -======= - types1 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - types "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) + types1 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + types "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -36,16 +32,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgRegisterInterchainAccount defines the payload for Msg/RegisterAccount type MsgRegisterInterchainAccount struct { -<<<<<<< HEAD - Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` - ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` - Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` -======= Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` - ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` Order types.Order `protobuf:"varint,4,opt,name=order,proto3,enum=ibc.core.channel.v1.Order" json:"order,omitempty"` ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } func (m *MsgRegisterInterchainAccount) Reset() { *m = MsgRegisterInterchainAccount{} } @@ -136,15 +126,9 @@ func (m *MsgRegisterInterchainAccountResponse) GetPortId() string { // MsgSendTx defines the payload for Msg/SendTx type MsgSendTx struct { -<<<<<<< HEAD - Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` - ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` - PacketData types.InterchainAccountPacketData `protobuf:"bytes,3,opt,name=packet_data,json=packetData,proto3" json:"packet_data" yaml:"packet_data"` -======= Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` - ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` - PacketData types1.InterchainAccountPacketData `protobuf:"bytes,3,opt,name=packet_data,json=packetData,proto3" json:"packet_data"` ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + PacketData types1.InterchainAccountPacketData `protobuf:"bytes,3,opt,name=packet_data,json=packetData,proto3" json:"packet_data" yaml:"packet_data"` // Relative timeout timestamp provided will be added to the current block time during transaction execution. // The timeout timestamp must be non-zero. RelativeTimeout uint64 `protobuf:"varint,4,opt,name=relative_timeout,json=relativeTimeout,proto3" json:"relative_timeout,omitempty" yaml:"relative_timeout"` @@ -240,89 +224,46 @@ func init() { } var fileDescriptor_7def041328c84a30 = []byte{ -<<<<<<< HEAD - // 570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xed, 0x34, 0xa4, 0xcd, 0x95, 0x5f, 0xb5, 0x82, 0x30, 0x06, 0xd9, 0x95, 0xc5, 0x50, - 0x09, 0xc5, 0xa7, 0x84, 0x4a, 0x95, 0x8a, 0x3a, 0x10, 0x15, 0xa4, 0x0c, 0x91, 0x22, 0xd3, 0x01, - 0xb1, 0x44, 0x97, 0xf3, 0xc9, 0x39, 0x70, 0xee, 0x8c, 0xef, 0x62, 0xda, 0x91, 0x0d, 0x16, 0xc4, - 0xc6, 0xda, 0xbf, 0x82, 0x7f, 0x81, 0x8e, 0x1d, 0x99, 0xac, 0x2a, 0x59, 0x98, 0xf3, 0x17, 0x20, - 0xdb, 0x89, 0x53, 0xa0, 0x54, 0xe5, 0x47, 0x37, 0xbf, 0x7b, 0xf7, 0x79, 0xef, 0x7b, 0xef, 0x3d, - 0x3f, 0xf0, 0x88, 0xf6, 0x31, 0x44, 0x61, 0x18, 0x50, 0x8c, 0x24, 0xe5, 0x4c, 0x40, 0xca, 0x24, - 0x89, 0xf0, 0x00, 0x51, 0xd6, 0x43, 0x18, 0xf3, 0x11, 0x93, 0x02, 0x62, 0xce, 0x64, 0xc4, 0x83, - 0x80, 0x44, 0x30, 0x6e, 0x40, 0xb9, 0xef, 0x84, 0x11, 0x97, 0x5c, 0x6b, 0xd2, 0x3e, 0x76, 0x4e, - 0xc3, 0xce, 0x19, 0xb0, 0xb3, 0x80, 0x9d, 0xb8, 0x61, 0xd4, 0x7c, 0xee, 0xf3, 0x0c, 0x87, 0xe9, - 0x57, 0x1e, 0xc9, 0xd8, 0xbc, 0x90, 0x8c, 0xb8, 0x01, 0x43, 0x84, 0x5f, 0x11, 0x99, 0x53, 0xf6, - 0x27, 0x15, 0xdc, 0xeb, 0x08, 0xdf, 0x25, 0x3e, 0x15, 0x92, 0x44, 0xed, 0x02, 0x79, 0x9c, 0x13, - 0x5a, 0x0d, 0x5c, 0xe1, 0x6f, 0x18, 0x89, 0x74, 0x75, 0x5d, 0xdd, 0xa8, 0xba, 0xb9, 0xa1, 0xed, - 0x80, 0x6b, 0x98, 0x33, 0x46, 0x70, 0x9a, 0xa9, 0x47, 0x3d, 0xbd, 0x94, 0x7a, 0x5b, 0xfa, 0x34, - 0xb1, 0x6a, 0x07, 0x68, 0x18, 0x6c, 0xdb, 0x3f, 0xb8, 0x6d, 0xf7, 0xea, 0xc2, 0x6e, 0x7b, 0x9a, - 0x0e, 0x96, 0x63, 0x12, 0x09, 0xca, 0x99, 0xbe, 0x94, 0x85, 0x9d, 0x9b, 0xdb, 0x2b, 0xef, 0x0e, - 0x2d, 0xe5, 0xdb, 0xa1, 0xa5, 0xd8, 0xef, 0x55, 0x70, 0xff, 0x3c, 0x65, 0x2e, 0x11, 0x21, 0x67, - 0x82, 0x68, 0x9b, 0x00, 0xe0, 0x01, 0x62, 0x8c, 0x04, 0xa9, 0x90, 0x4c, 0x66, 0xeb, 0xd6, 0x34, - 0xb1, 0xd6, 0x66, 0x42, 0x0a, 0x9f, 0xed, 0x56, 0x67, 0x46, 0xdb, 0xd3, 0x1e, 0x80, 0xe5, 0x90, - 0x47, 0x72, 0xa1, 0x5d, 0x9b, 0x26, 0xd6, 0xf5, 0x1c, 0x99, 0x39, 0x6c, 0xb7, 0x92, 0x7e, 0xb5, - 0x3d, 0xfb, 0x73, 0x09, 0x54, 0x3b, 0xc2, 0x7f, 0x46, 0x98, 0xb7, 0xb7, 0x7f, 0x39, 0x25, 0x79, - 0xab, 0x82, 0xd5, 0xbc, 0x33, 0x3d, 0x0f, 0x49, 0x94, 0xd5, 0x65, 0xb5, 0xb9, 0xeb, 0x5c, 0x68, - 0x3e, 0xe2, 0x86, 0xf3, 0x4b, 0x7d, 0xba, 0x59, 0xb0, 0x5d, 0x24, 0x51, 0xcb, 0x38, 0x4a, 0x2c, - 0x65, 0x9a, 0x58, 0xda, 0xec, 0x79, 0x8b, 0x34, 0xb6, 0x0b, 0xc2, 0xe2, 0x9e, 0xf6, 0x14, 0xdc, - 0x8c, 0x48, 0x80, 0x24, 0x8d, 0x49, 0x4f, 0xd2, 0x21, 0xe1, 0x23, 0xa9, 0x97, 0xd7, 0xd5, 0x8d, - 0x72, 0xeb, 0xee, 0x34, 0xb1, 0x6e, 0xe7, 0xf4, 0xcf, 0x37, 0x6c, 0xf7, 0xc6, 0xfc, 0x68, 0x2f, - 0x3f, 0x39, 0xd5, 0x44, 0x08, 0xd6, 0x8a, 0xba, 0x15, 0x0d, 0x33, 0xc0, 0x8a, 0x20, 0xaf, 0x47, - 0x84, 0x61, 0x92, 0x95, 0xb0, 0xec, 0x16, 0x76, 0xf3, 0xa4, 0x04, 0x96, 0x3a, 0xc2, 0xd7, 0xbe, - 0xa8, 0xe0, 0xce, 0xef, 0x87, 0xb2, 0xeb, 0xfc, 0xf9, 0x6f, 0xe3, 0x9c, 0x37, 0x4c, 0xc6, 0xf3, - 0xff, 0x1d, 0xb1, 0x78, 0xed, 0x07, 0x15, 0x54, 0x66, 0x83, 0xb3, 0xf3, 0x97, 0x49, 0x72, 0xdc, - 0x78, 0xf2, 0x4f, 0xf8, 0x5c, 0x50, 0xeb, 0xe5, 0xd1, 0xd8, 0x54, 0x8f, 0xc7, 0xa6, 0x7a, 0x32, - 0x36, 0xd5, 0x8f, 0x13, 0x53, 0x39, 0x9e, 0x98, 0xca, 0xd7, 0x89, 0xa9, 0xbc, 0xe8, 0xfa, 0x54, - 0x0e, 0x46, 0x7d, 0x07, 0xf3, 0x21, 0xc4, 0x5c, 0x0c, 0xb9, 0x80, 0xb4, 0x8f, 0xeb, 0x3e, 0x87, - 0xf1, 0x16, 0x1c, 0x72, 0x6f, 0x14, 0x10, 0x91, 0xae, 0x18, 0x01, 0x9b, 0x5b, 0xf5, 0x45, 0xea, - 0xfa, 0x59, 0x4b, 0x4e, 0x1e, 0x84, 0x44, 0xf4, 0x2b, 0xd9, 0x96, 0x79, 0xf8, 0x3d, 0x00, 0x00, - 0xff, 0xff, 0xf0, 0x81, 0x7c, 0xb2, 0x24, 0x05, 0x00, 0x00, -======= - // 668 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x4f, 0x13, 0x4f, - 0x14, 0xef, 0xfe, 0x29, 0xe5, 0xcf, 0x80, 0xa0, 0x1b, 0x22, 0x65, 0xa3, 0x05, 0xab, 0x07, 0x24, - 0x61, 0xc6, 0x56, 0x8d, 0xa6, 0xc6, 0x83, 0x80, 0x87, 0xc6, 0x34, 0x36, 0x2b, 0x26, 0xc4, 0x4b, - 0x33, 0x9d, 0x9d, 0x2c, 0x23, 0xdd, 0x99, 0x75, 0x66, 0xba, 0xe2, 0xcd, 0x78, 0x32, 0x1e, 0x8c, - 0x07, 0x3f, 0x00, 0x1f, 0x81, 0x8b, 0x9f, 0x41, 0x8e, 0x1c, 0x3d, 0x19, 0x03, 0x07, 0x6e, 0x7e, - 0x06, 0xb3, 0x3b, 0xdb, 0x2d, 0x0a, 0x12, 0x2c, 0xdc, 0xf6, 0xbd, 0x99, 0xf7, 0x7b, 0xbf, 0xdf, - 0x6f, 0xde, 0x3e, 0xf0, 0x80, 0xb5, 0x09, 0xc2, 0x61, 0xd8, 0x61, 0x04, 0x6b, 0x26, 0xb8, 0x42, - 0x8c, 0x6b, 0x2a, 0xc9, 0x3a, 0x66, 0xbc, 0x85, 0x09, 0x11, 0x5d, 0xae, 0x15, 0x22, 0x82, 0x6b, - 0x29, 0x3a, 0x1d, 0x2a, 0x51, 0x54, 0x41, 0x7a, 0x13, 0x86, 0x52, 0x68, 0x61, 0x57, 0x59, 0x9b, - 0xc0, 0xc3, 0xc5, 0xf0, 0x98, 0x62, 0xd8, 0x2f, 0x86, 0x51, 0xc5, 0x99, 0xf2, 0x85, 0x2f, 0x92, - 0x72, 0x14, 0x7f, 0x19, 0x24, 0xe7, 0xce, 0xa9, 0x68, 0x44, 0x15, 0x14, 0x62, 0xb2, 0x41, 0x75, - 0x5a, 0xb5, 0x3c, 0x00, 0xf9, 0x43, 0x6c, 0x0c, 0xc8, 0x34, 0x11, 0x2a, 0x10, 0x0a, 0x05, 0xca, - 0x8f, 0xcf, 0x03, 0xe5, 0xa7, 0x07, 0xd7, 0x62, 0x74, 0x22, 0x24, 0x45, 0x64, 0x1d, 0x73, 0x4e, - 0x3b, 0x49, 0xb9, 0xf9, 0x34, 0x57, 0xca, 0x5f, 0x2c, 0x70, 0xa5, 0xa1, 0x7c, 0x97, 0xfa, 0x4c, - 0x69, 0x2a, 0xeb, 0x59, 0xf7, 0x47, 0xa6, 0xb9, 0x3d, 0x05, 0x86, 0xc5, 0x6b, 0x4e, 0x65, 0xd1, - 0x9a, 0xb3, 0xe6, 0x47, 0x5d, 0x13, 0xd8, 0xd7, 0xc1, 0x05, 0x22, 0x38, 0xa7, 0x24, 0x26, 0xdd, - 0x62, 0x5e, 0xf1, 0xbf, 0xe4, 0x74, 0xbc, 0x9f, 0xac, 0x7b, 0x76, 0x11, 0x8c, 0x44, 0x54, 0x2a, - 0x26, 0x78, 0x71, 0x28, 0x39, 0xee, 0x85, 0xf6, 0x2d, 0x30, 0x2c, 0xa4, 0x47, 0x65, 0x31, 0x3f, - 0x67, 0xcd, 0x4f, 0x54, 0x1d, 0x18, 0x3f, 0x43, 0x4c, 0x14, 0xf6, 0xd8, 0x45, 0x15, 0xf8, 0x34, - 0xbe, 0xe1, 0x9a, 0x8b, 0xb5, 0x89, 0xf7, 0x5b, 0xb3, 0xb9, 0x77, 0x07, 0xdb, 0x0b, 0x86, 0x40, - 0xd9, 0x03, 0x37, 0x4e, 0xa2, 0xed, 0x52, 0x15, 0x0a, 0xae, 0xa8, 0x7d, 0x15, 0x80, 0x14, 0x32, - 0x66, 0x69, 0x34, 0x8c, 0xa6, 0x99, 0xba, 0x67, 0x4f, 0x83, 0x91, 0x50, 0x48, 0xdd, 0x57, 0x50, - 0x88, 0xc3, 0xba, 0x57, 0xcb, 0xc7, 0xfd, 0xca, 0x3f, 0x2d, 0x30, 0xda, 0x50, 0xfe, 0x33, 0xca, - 0xbd, 0xd5, 0xcd, 0xb3, 0x58, 0xb1, 0x01, 0xc6, 0xcc, 0xbb, 0xb7, 0x3c, 0xac, 0x71, 0x62, 0xc7, - 0x58, 0x75, 0x05, 0x9e, 0x6a, 0xfa, 0xa2, 0x0a, 0x3c, 0xa2, 0xaf, 0x99, 0x80, 0xad, 0x60, 0x8d, - 0x97, 0xf2, 0x3b, 0xdf, 0x67, 0x73, 0x2e, 0x08, 0xb3, 0x8c, 0x7d, 0x13, 0x5c, 0x94, 0xb4, 0x83, - 0x35, 0x8b, 0x68, 0x4b, 0xb3, 0x80, 0x8a, 0xae, 0x4e, 0x8c, 0xce, 0xbb, 0x93, 0xbd, 0xfc, 0xaa, - 0x49, 0x1f, 0xb1, 0xf5, 0x2e, 0xb8, 0x94, 0xe9, 0xcd, 0x3c, 0x74, 0xc0, 0xff, 0x8a, 0xbe, 0xea, - 0x52, 0x4e, 0x68, 0x22, 0x3d, 0xef, 0x66, 0x71, 0xea, 0xd3, 0x67, 0x0b, 0x4c, 0x36, 0x94, 0xff, - 0x3c, 0xf4, 0xb0, 0xa6, 0x4d, 0x2c, 0x71, 0xa0, 0xec, 0xcb, 0xa0, 0xa0, 0x98, 0xdf, 0xb7, 0x2b, - 0x8d, 0xec, 0x35, 0x50, 0x08, 0x93, 0x1b, 0x89, 0x51, 0x63, 0xd5, 0x1a, 0xfc, 0xf7, 0x7f, 0x10, - 0x9a, 0x1e, 0xa9, 0xf6, 0x14, 0xaf, 0x36, 0xd9, 0x13, 0x93, 0xb6, 0x2a, 0xcf, 0x80, 0xe9, 0x3f, - 0x58, 0xf5, 0x34, 0x55, 0x3f, 0xe4, 0xc1, 0x50, 0x43, 0xf9, 0xf6, 0x57, 0x0b, 0xcc, 0xfc, 0x7d, - 0xf8, 0x9b, 0x83, 0x70, 0x3b, 0x69, 0x2e, 0x9d, 0xb5, 0xf3, 0x46, 0xcc, 0x5e, 0xe9, 0xa3, 0x05, - 0x0a, 0xe9, 0xa0, 0x3e, 0x1c, 0xb0, 0x89, 0x29, 0x77, 0x1e, 0x9f, 0xa9, 0x3c, 0x23, 0xb4, 0x65, - 0x81, 0xf1, 0xdf, 0x26, 0x62, 0x79, 0x40, 0xdc, 0xc3, 0x20, 0xce, 0x93, 0x73, 0x00, 0xe9, 0x51, - 0x74, 0x86, 0xdf, 0x1e, 0x6c, 0x2f, 0x58, 0x4b, 0x2f, 0x77, 0xf6, 0x4a, 0xd6, 0xee, 0x5e, 0xc9, - 0xfa, 0xb1, 0x57, 0xb2, 0x3e, 0xed, 0x97, 0x72, 0xbb, 0xfb, 0xa5, 0xdc, 0xb7, 0xfd, 0x52, 0xee, - 0x45, 0xd3, 0x67, 0x7a, 0xbd, 0xdb, 0x86, 0x44, 0x04, 0x28, 0xdd, 0xb2, 0xac, 0x4d, 0x16, 0x7d, - 0x81, 0xa2, 0xfb, 0x28, 0x10, 0x5e, 0xb7, 0x43, 0x55, 0xbc, 0xbf, 0x15, 0xaa, 0xde, 0x5b, 0xec, - 0xf3, 0x58, 0x3c, 0x6e, 0x75, 0xeb, 0x37, 0x21, 0x55, 0xed, 0x42, 0xb2, 0x77, 0x6f, 0xff, 0x0a, - 0x00, 0x00, 0xff, 0xff, 0x5c, 0x9c, 0xca, 0xe1, 0xb7, 0x06, 0x00, 0x00, ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) + // 609 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcb, 0x6e, 0xd4, 0x30, + 0x14, 0x9d, 0xf4, 0x5d, 0x17, 0x0a, 0x8d, 0x8a, 0x08, 0x01, 0x25, 0x25, 0x62, 0x51, 0x09, 0xd5, + 0x66, 0x86, 0x4a, 0x95, 0x8a, 0xba, 0x60, 0x54, 0x90, 0x66, 0x51, 0x51, 0x85, 0x2e, 0x10, 0x9b, + 0x91, 0xc7, 0xb1, 0x52, 0x43, 0xc6, 0x0e, 0xb6, 0x27, 0xb4, 0x4b, 0x76, 0xb0, 0x41, 0x7c, 0x42, + 0xbf, 0x82, 0x5f, 0xa0, 0xec, 0xba, 0x64, 0x15, 0x55, 0x9d, 0x0d, 0xeb, 0xf9, 0x02, 0x94, 0xc7, + 0x64, 0x0a, 0x94, 0xaa, 0xbc, 0x76, 0xbe, 0xb9, 0xf7, 0x1c, 0xdf, 0x73, 0xee, 0x8d, 0xc1, 0x03, + 0xd6, 0x21, 0x08, 0xc7, 0x71, 0xc4, 0x08, 0xd6, 0x4c, 0x70, 0x85, 0x18, 0xd7, 0x54, 0x92, 0x5d, + 0xcc, 0x78, 0x1b, 0x13, 0x22, 0x7a, 0x5c, 0x2b, 0x44, 0x04, 0xd7, 0x52, 0x44, 0x11, 0x95, 0x28, + 0xa9, 0x23, 0xbd, 0x07, 0x63, 0x29, 0xb4, 0x30, 0x1b, 0xac, 0x43, 0xe0, 0x69, 0x30, 0x3c, 0x03, + 0x0c, 0x47, 0x60, 0x98, 0xd4, 0xed, 0xc5, 0x50, 0x84, 0x22, 0x87, 0xa3, 0xec, 0x54, 0x30, 0xd9, + 0xab, 0x17, 0x6a, 0x23, 0xa9, 0xa3, 0x18, 0x93, 0x97, 0x54, 0x97, 0xa8, 0xdb, 0x19, 0x8a, 0x08, + 0x49, 0x11, 0xd9, 0xc5, 0x9c, 0xd3, 0x28, 0xab, 0x28, 0x8f, 0x45, 0x89, 0xf7, 0xd9, 0x00, 0xb7, + 0xb6, 0x54, 0xe8, 0xd3, 0x90, 0x29, 0x4d, 0x65, 0xab, 0x62, 0x7d, 0x58, 0x90, 0x9a, 0x8b, 0x60, + 0x52, 0xbc, 0xe6, 0x54, 0x5a, 0xc6, 0x92, 0xb1, 0x3c, 0xeb, 0x17, 0x81, 0xb9, 0x01, 0x2e, 0x13, + 0xc1, 0x39, 0x25, 0x59, 0x33, 0x6d, 0x16, 0x58, 0x63, 0x59, 0xb6, 0x69, 0x0d, 0x52, 0x77, 0x71, + 0x1f, 0x77, 0xa3, 0x75, 0xef, 0xbb, 0xb4, 0xe7, 0x5f, 0x1a, 0xc5, 0xad, 0xc0, 0xb4, 0xc0, 0x74, + 0x42, 0xa5, 0x62, 0x82, 0x5b, 0xe3, 0x39, 0xed, 0x30, 0x34, 0xef, 0x81, 0x49, 0x21, 0x03, 0x2a, + 0xad, 0x89, 0x25, 0x63, 0x79, 0xbe, 0x61, 0xc3, 0xcc, 0xc2, 0x4c, 0x02, 0x1c, 0xf6, 0x9d, 0xd4, + 0xe1, 0x93, 0xac, 0xc2, 0x2f, 0x0a, 0xd7, 0x67, 0xde, 0x1e, 0xb8, 0xb5, 0xaf, 0x07, 0x6e, 0xcd, + 0x7b, 0x67, 0x80, 0x3b, 0xe7, 0x69, 0xf1, 0xa9, 0x8a, 0x05, 0x57, 0xd4, 0x5c, 0x05, 0xa0, 0x64, + 0xcb, 0x5a, 0xcf, 0x85, 0x35, 0xaf, 0x0d, 0x52, 0x77, 0xa1, 0x6c, 0xbd, 0xca, 0x79, 0xfe, 0x6c, + 0x19, 0xb4, 0x02, 0xf3, 0x2e, 0x98, 0x8e, 0x85, 0xd4, 0x23, 0xb5, 0xe6, 0x20, 0x75, 0xe7, 0x0b, + 0x48, 0x99, 0xf0, 0xfc, 0xa9, 0xec, 0xd4, 0x0a, 0xbc, 0x8f, 0x63, 0x60, 0x76, 0x4b, 0x85, 0x4f, + 0x29, 0x0f, 0x76, 0xf6, 0xfe, 0x8f, 0x89, 0x6f, 0x0c, 0x30, 0x57, 0x8c, 0xbb, 0x1d, 0x60, 0x8d, + 0x73, 0x27, 0xe7, 0x1a, 0x9b, 0xf0, 0x42, 0x4b, 0x97, 0xd4, 0xe1, 0x4f, 0xfe, 0x6c, 0xe7, 0x64, + 0x9b, 0x58, 0xe3, 0xa6, 0x7d, 0x98, 0xba, 0xb5, 0x41, 0xea, 0x9a, 0xa5, 0xbc, 0xd1, 0x35, 0x9e, + 0x0f, 0xe2, 0xaa, 0xce, 0x7c, 0x0c, 0xae, 0x4a, 0x1a, 0x61, 0xcd, 0x12, 0xda, 0xd6, 0xac, 0x4b, + 0x45, 0x4f, 0xe7, 0x93, 0x9b, 0x68, 0xde, 0x1c, 0xa4, 0xee, 0xf5, 0x02, 0xfd, 0x63, 0x85, 0xe7, + 0x5f, 0x19, 0x7e, 0xda, 0x29, 0xbe, 0x9c, 0x1a, 0x22, 0x02, 0x0b, 0x95, 0x6f, 0xd5, 0xc0, 0x6c, + 0x30, 0xa3, 0xe8, 0xab, 0x1e, 0xe5, 0x84, 0xe6, 0x16, 0x4e, 0xf8, 0x55, 0xdc, 0x38, 0x1e, 0x03, + 0xe3, 0x5b, 0x2a, 0x34, 0x3f, 0x19, 0xe0, 0xc6, 0xaf, 0xd7, 0x78, 0x1b, 0xfe, 0xfe, 0xbf, 0x08, + 0xcf, 0x5b, 0x26, 0xfb, 0xd9, 0xbf, 0x66, 0xac, 0xd4, 0xbe, 0x37, 0xc0, 0x54, 0xb9, 0x38, 0x1b, + 0x7f, 0x78, 0x49, 0x01, 0xb7, 0x1f, 0xfd, 0x15, 0x7c, 0xd8, 0x50, 0xf3, 0xc5, 0xe1, 0x89, 0x63, + 0x1c, 0x9d, 0x38, 0xc6, 0xf1, 0x89, 0x63, 0x7c, 0xe8, 0x3b, 0xb5, 0xa3, 0xbe, 0x53, 0xfb, 0xd2, + 0x77, 0x6a, 0xcf, 0xb7, 0x43, 0xa6, 0x77, 0x7b, 0x1d, 0x48, 0x44, 0x17, 0x11, 0xa1, 0xba, 0x42, + 0x21, 0xd6, 0x21, 0x2b, 0xa1, 0x40, 0xc9, 0x1a, 0xea, 0x8a, 0xa0, 0x17, 0x51, 0x95, 0xbd, 0x5b, + 0x0a, 0x35, 0xd6, 0x56, 0x46, 0x57, 0xaf, 0x9c, 0xf5, 0x72, 0xea, 0xfd, 0x98, 0xaa, 0xce, 0x54, + 0xfe, 0x2e, 0xdd, 0xff, 0x16, 0x00, 0x00, 0xff, 0xff, 0xa9, 0xf2, 0xe4, 0x17, 0x79, 0x05, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 8ec9bc624cf..7e567ce449e 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" @@ -26,13 +27,6 @@ func (k Keeper) OnChanOpenTry( counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { -<<<<<<< HEAD - if order != channeltypes.ORDERED { - return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) - } - -======= ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) if portID != icatypes.HostPortID { return "", sdkerrors.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, portID) } @@ -53,20 +47,6 @@ func (k Keeper) OnChanOpenTry( panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } -<<<<<<< HEAD - if channel.State == channeltypes.OPEN { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) - } - - appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) - if !found { - panic(fmt.Sprintf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID)) - } - - if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") - } -======= if channel.State != channeltypes.CLOSED { return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s must be %s", activeChannelID, portID, channeltypes.CLOSED) } @@ -74,7 +54,6 @@ func (k Keeper) OnChanOpenTry( // if a channel is being reopened, we allow the controller to propose new fields // which are not exactly the same as the previous. The provided address will // be overwritten with the correct one before the metadata is returned. ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } // On the host chain the capability may only be claimed during the OnChanOpenTry @@ -142,74 +121,3 @@ func (k Keeper) OnChanCloseConfirm( ) error { return nil } -<<<<<<< HEAD -======= - -// OnChanUpgradeTry performs the upgrade try step of the channel upgrade handshake. -// The upgrade try callback must verify the proposed changes to the order, connectionHops, and version. -// Within the version we have the tx type, encoding, interchain account address, host/controller connectionID's -// and the ICS27 protocol version. -// -// The following may be changed: -// - tx type (must be supported) -// - encoding (must be supported) -// - order -// -// The following may not be changed: -// - connectionHops (and subsequently host/controller connectionIDs) -// - interchain account address -// - ICS27 protocol version -func (k Keeper) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { - if portID != icatypes.HostPortID { - return "", errorsmod.Wrapf(porttypes.ErrInvalidPort, "expected %s, got %s", icatypes.HostPortID, portID) - } - - // verify connection hops has not changed - connectionID, err := k.getConnectionID(ctx, portID, channelID) - if err != nil { - return "", err - } - - if len(proposedConnectionHops) != 1 || proposedConnectionHops[0] != connectionID { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidUpgrade, "expected connection hops %s, got %s", []string{connectionID}, proposedConnectionHops) - } - - if strings.TrimSpace(counterpartyVersion) == "" { - return "", errorsmod.Wrap(channeltypes.ErrInvalidChannelVersion, "counterparty version cannot be empty") - } - - proposedCounterpartyMetadata, err := icatypes.MetadataFromVersion(counterpartyVersion) - if err != nil { - return "", err - } - - currentMetadata, err := k.getAppMetadata(ctx, portID, channelID) - if err != nil { - return "", err - } - - // ValidateHostMetadata will ensure the ICS27 protocol version has not changed and that the - // tx type and encoding are supported. It also validates the connection params against the counterparty metadata. - if err := icatypes.ValidateHostMetadata(ctx, k.channelKeeper, proposedConnectionHops, proposedCounterpartyMetadata); err != nil { - return "", errorsmod.Wrap(err, "invalid metadata") - } - - // the interchain account address on the host chain - // must remain the same after the upgrade. - if currentMetadata.Address != proposedCounterpartyMetadata.Address { - return "", errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be changed") - } - - // these explicit checks on the controller connection identifier should be unreachable - if currentMetadata.ControllerConnectionId != proposedCounterpartyMetadata.ControllerConnectionId { - return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change") - } - - // these explicit checks on the host connection identifier should be unreachable - if currentMetadata.HostConnectionId != proposedConnectionHops[0] { - return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnectionIdentifier, "proposed connection hop must not change") - } - - return counterpartyVersion, nil -} ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 67c8e918816..e26e9530092 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -156,37 +156,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { false, }, { -<<<<<<< HEAD - "invalid metadata - previous metadata is different", - func() { - // create a new channel and set it in state - ch := channeltypes.NewChannel(channeltypes.CLOSED, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointA.ConnectionID}, TestVersion) - suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, ch) - - // set the active channelID in state - suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) - - // attempt to downgrade version by reinitializing channel with version 1, but setting channel to version 2 - metadata.Version = "ics27-2" - - versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) - suite.Require().NoError(err) - - channel.Version = string(versionBytes) - - path.EndpointB.SetChannel(*channel) - }, false, - }, - { - "invalid order - UNORDERED", - func() { - channel.Ordering = channeltypes.UNORDERED - }, - false, - }, - { -======= ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) "invalid port ID", func() { path.EndpointB.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst @@ -288,23 +257,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false, }, - { - "channel is already active (FLUSHING state)", - func() { - suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) - - counterparty := channeltypes.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channel := channeltypes.Channel{ - State: channeltypes.FLUSHING, - Ordering: channeltypes.ORDERED, - Counterparty: counterparty, - ConnectionHops: []string{path.EndpointB.ConnectionID}, - Version: TestVersion, - } - suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel) - }, - false, - }, } for _, tc := range testCases { @@ -455,185 +407,3 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { }) } } -<<<<<<< HEAD -======= - -func (suite *KeeperTestSuite) TestOnChanUpgradeTry() { - var ( - path *ibctesting.Path - metadata icatypes.Metadata - order channeltypes.Order - counterpartyVersion string - ) - - // updateMetadata is a helper function which modifies the metadata stored in the channel version - // and marshals it into a string to pass to OnChanUpgradeTry as the counterpartyVersion string. - updateMetadata := func(modificationFn func(*icatypes.Metadata)) { - metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) - suite.Require().NoError(err) - modificationFn(&metadata) - counterpartyVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - } - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() {}, - nil, - }, - { - name: "success: change order", - malleate: func() { - order = channeltypes.UNORDERED - }, - expError: nil, - }, - { - name: "failure: invalid port ID", - malleate: func() { - path.EndpointB.ChannelConfig.PortID = "invalid-port-id" - }, - expError: porttypes.ErrInvalidPort, - }, - { - name: "failure: invalid proposed connectionHops", - malleate: func() { - // connection hops is provided via endpoint connectionID - path.EndpointB.ConnectionID = differentConnectionID - }, - expError: channeltypes.ErrInvalidUpgrade, - }, - { - name: "failure: empty counterparty version", - malleate: func() { - counterpartyVersion = "" - }, - expError: channeltypes.ErrInvalidChannelVersion, - }, - { - name: "failure: cannot parse metadata from counterparty version string", - malleate: func() { - counterpartyVersion = "invalid-version" - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: cannot decode version string from channel", - malleate: func() { - channel := path.EndpointB.GetChannel() - channel.Version = "invalid-metadata-string" - path.EndpointB.SetChannel(channel) - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: metadata encoding not supported", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Encoding = "invalid-encoding-format" - }) - }, - expError: icatypes.ErrInvalidCodec, - }, - { - name: "failure: metadata tx type not supported", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.TxType = "invalid-tx-type" - }) - }, - expError: icatypes.ErrUnknownDataType, - }, - { - name: "failure: interchain account address has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.Address = TestOwnerAddress // use valid address - }) - }, - expError: icatypes.ErrInvalidAccountAddress, - }, - { - name: "failure: controller connection ID has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.ControllerConnectionId = differentConnectionID - }) - }, - expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller connection identifier are unreachable - }, - { - name: "failure: host connection ID has changed", - malleate: func() { - updateMetadata(func(metadata *icatypes.Metadata) { - metadata.HostConnectionId = differentConnectionID - }) - }, - expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host connection identifier are unreachable - }, - { - name: "failure: channel not found", - malleate: func() { - path.EndpointB.ChannelID = "invalid-channel-id" - }, - expError: channeltypes.ErrChannelNotFound, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - - path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - currentMetadata, err := suite.chainB.GetSimApp().ICAHostKeeper.GetAppMetadata(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - suite.Require().NoError(err) - - order = channeltypes.ORDERED - metadata = icatypes.NewDefaultMetadata(path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) - // use the same address as the previous metadata. - metadata.Address = currentMetadata.Address - - // this is the actual change to the version. - metadata.Encoding = icatypes.EncodingProto3JSON - - path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) - - err = path.EndpointA.ChanUpgradeInit() - suite.Require().NoError(err) - - counterpartyVersion = path.EndpointA.GetChannel().Version - - tc.malleate() // malleate mutates test data - - version, err := suite.chainB.GetSimApp().ICAHostKeeper.OnChanUpgradeTry( - suite.chainB.GetContext(), - path.EndpointB.ChannelConfig.PortID, - path.EndpointB.ChannelID, - order, - []string{path.EndpointB.ConnectionID}, - counterpartyVersion, - ) - - expPass := tc.expError == nil - if expPass { - suite.Require().NoError(err) - suite.Require().Equal(path.EndpointB.GetChannel().Version, version) - } else { - suite.Require().ErrorIs(err, tc.expError) - } - }) - } -} ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) diff --git a/modules/apps/callbacks/callbacks_test.go b/modules/apps/callbacks/callbacks_test.go index a87abac231e..8235a3285dd 100644 --- a/modules/apps/callbacks/callbacks_test.go +++ b/modules/apps/callbacks/callbacks_test.go @@ -18,23 +18,12 @@ import ( simapp "github.com/cosmos/ibc-go/modules/apps/callbacks/testing/simapp" "github.com/cosmos/ibc-go/modules/apps/callbacks/types" -<<<<<<< HEAD icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" -======= - icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" - ibctesting "github.com/cosmos/ibc-go/v8/testing" - ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) ) const maxCallbackGas = uint64(1000000) @@ -166,7 +155,7 @@ func (s *CallbacksTestSuite) SetupICATest() string { // RegisterInterchainAccount submits a MsgRegisterInterchainAccount and updates the controller endpoint with the // channel created. func (s *CallbacksTestSuite) RegisterInterchainAccount(owner string) { - msgRegister := icacontrollertypes.NewMsgRegisterInterchainAccount(s.path.EndpointA.ConnectionID, owner, s.path.EndpointA.ChannelConfig.Version, channeltypes.ORDERED) + msgRegister := icacontrollertypes.NewMsgRegisterInterchainAccount(s.path.EndpointA.ConnectionID, owner, s.path.EndpointA.ChannelConfig.Version) res, err := s.chainA.SendMsgs(msgRegister) s.Require().NotEmpty(res) diff --git a/modules/core/03-connection/types/version.go b/modules/core/03-connection/types/version.go index a9a9f3df699..827ced76ba9 100644 --- a/modules/core/03-connection/types/version.go +++ b/modules/core/03-connection/types/version.go @@ -13,11 +13,15 @@ var ( // in connection version negotiation. The current version supports only // ORDERED and UNORDERED channels and requires at least one channel type // to be agreed upon. - DefaultIBCVersion = NewVersion(DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED", "ORDER_UNORDERED"}) + DefaultIBCVersion = NewVersion(DefaultIBCVersionIdentifier, SupportedOrderings) // DefaultIBCVersionIdentifier is the IBC v1.0.0 protocol version identifier DefaultIBCVersionIdentifier = "1" + // SupportedOrderings is the list of orderings supported by IBC. The current + // version supports only ORDERED and UNORDERED channels. + SupportedOrderings = []string{"ORDER_ORDERED", "ORDER_UNORDERED"} + // AllowNilFeatureSet is a helper map to indicate if a specified version // identifier is allowed to have a nil feature set. Any versions supported, // but not included in the map default to not supporting nil feature sets. diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index a124fd02167..79ec288c023 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -6,12 +6,7 @@ option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-acco import "gogoproto/gogo.proto"; import "ibc/applications/interchain_accounts/v1/packet.proto"; -<<<<<<< HEAD -======= -import "ibc/applications/interchain_accounts/controller/v1/controller.proto"; -import "cosmos/msg/v1/msg.proto"; import "ibc/core/channel/v1/channel.proto"; ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) // Msg defines the 27-interchain-accounts/controller Msg service. service Msg { @@ -26,16 +21,10 @@ message MsgRegisterInterchainAccount { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; -<<<<<<< HEAD - string owner = 1; - string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string version = 3; -======= string owner = 1; - string connection_id = 2; + string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; string version = 3; ibc.core.channel.v1.Order order = 4; ->>>>>>> 61748221 (feat(ica): allow unordered ica channels (#5633)) } // MsgRegisterInterchainAccountResponse defines the response for Msg/RegisterAccount From f395900e52406072eec8fbc93e645479b06e78cb Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 26 Apr 2024 09:14:32 +0200 Subject: [PATCH 3/5] rename order to ordering (backport #5674) --- .../controller/client/cli/tx.go | 8 +- .../controller/keeper/account.go | 4 +- .../controller/keeper/msg_server.go | 2 +- .../controller/types/msgs.go | 4 +- .../controller/types/tx.pb.go | 96 +++++++++---------- .../controller/v1/tx.proto | 2 +- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/client/cli/tx.go b/modules/apps/27-interchain-accounts/controller/client/cli/tx.go index 7ca3d5cd3ff..eb0af19693b 100644 --- a/modules/apps/27-interchain-accounts/controller/client/cli/tx.go +++ b/modules/apps/27-interchain-accounts/controller/client/cli/tx.go @@ -49,12 +49,12 @@ the associated capability.`), return err } - order, err := parseOrder(cmd) + ordering, err := parseOrdering(cmd) if err != nil { return err } - msg := types.NewMsgRegisterInterchainAccountWithOrdering(connectionID, owner, version, order) + msg := types.NewMsgRegisterInterchainAccountWithOrdering(connectionID, owner, version, ordering) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, @@ -118,8 +118,8 @@ appropriate relative timeoutTimestamp must be provided with flag {relative-packe return cmd } -// parseOrder gets the channel ordering from the flags. -func parseOrder(cmd *cobra.Command) (channeltypes.Order, error) { +// parseOrdering gets the channel ordering from the flags. +func parseOrdering(cmd *cobra.Command) (channeltypes.Order, error) { orderString, err := cmd.Flags().GetString(flagOrdering) if err != nil { return channeltypes.NONE, err diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 1c31f349525..2abe1505527 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -49,7 +49,7 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, // registerInterchainAccount registers an interchain account, returning the channel id of the MsgChannelOpenInitResponse // and an error if one occurred. -func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, version string, order channeltypes.Order) (string, error) { +func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, version string, ordering channeltypes.Order) (string, error) { // if there is an active channel for this portID / connectionID return an error activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if found { @@ -66,7 +66,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, } } - msg := channeltypes.NewMsgChannelOpenInit(portID, version, order, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) + msg := channeltypes.NewMsgChannelOpenInit(portID, version, ordering, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) handler := k.msgRouter.Handler(msg) res, err := handler(ctx, msg) if err != nil { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go index 43cc5d427dc..f118fbd75a3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -37,7 +37,7 @@ func (s msgServer) RegisterInterchainAccount(goCtx context.Context, msg *types.M s.SetMiddlewareDisabled(ctx, portID, msg.ConnectionId) - channelID, err := s.registerInterchainAccount(ctx, msg.ConnectionId, portID, msg.Version, msg.Order) + channelID, err := s.registerInterchainAccount(ctx, msg.ConnectionId, portID, msg.Version, msg.Ordering) if err != nil { s.Logger(ctx).Error("error registering interchain account", "error", err.Error()) return nil, err diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index 0e417c8fac0..400e48bf5d0 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -19,7 +19,7 @@ func NewMsgRegisterInterchainAccountWithOrdering(connectionID, owner, version st ConnectionId: connectionID, Owner: owner, Version: version, - Order: ordering, + Ordering: ordering, } } @@ -31,7 +31,7 @@ func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRe ConnectionId: connectionID, Owner: owner, Version: version, - Order: channeltypes.ORDERED, + Ordering: channeltypes.ORDERED, } } diff --git a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go index e1c2e69ed6d..d800fcd0616 100644 --- a/modules/apps/27-interchain-accounts/controller/types/tx.pb.go +++ b/modules/apps/27-interchain-accounts/controller/types/tx.pb.go @@ -35,7 +35,7 @@ type MsgRegisterInterchainAccount struct { Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` - Order types.Order `protobuf:"varint,4,opt,name=order,proto3,enum=ibc.core.channel.v1.Order" json:"order,omitempty"` + Ordering types.Order `protobuf:"varint,4,opt,name=ordering,proto3,enum=ibc.core.channel.v1.Order" json:"ordering,omitempty"` } func (m *MsgRegisterInterchainAccount) Reset() { *m = MsgRegisterInterchainAccount{} } @@ -224,46 +224,46 @@ func init() { } var fileDescriptor_7def041328c84a30 = []byte{ - // 609 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcb, 0x6e, 0xd4, 0x30, - 0x14, 0x9d, 0xf4, 0x5d, 0x17, 0x0a, 0x8d, 0x8a, 0x08, 0x01, 0x25, 0x25, 0x62, 0x51, 0x09, 0xd5, - 0x66, 0x86, 0x4a, 0x95, 0x8a, 0xba, 0x60, 0x54, 0x90, 0x66, 0x51, 0x51, 0x85, 0x2e, 0x10, 0x9b, - 0x91, 0xc7, 0xb1, 0x52, 0x43, 0xc6, 0x0e, 0xb6, 0x27, 0xb4, 0x4b, 0x76, 0xb0, 0x41, 0x7c, 0x42, - 0xbf, 0x82, 0x5f, 0xa0, 0xec, 0xba, 0x64, 0x15, 0x55, 0x9d, 0x0d, 0xeb, 0xf9, 0x02, 0x94, 0xc7, - 0x64, 0x0a, 0x94, 0xaa, 0xbc, 0x76, 0xbe, 0xb9, 0xf7, 0x1c, 0xdf, 0x73, 0xee, 0x8d, 0xc1, 0x03, - 0xd6, 0x21, 0x08, 0xc7, 0x71, 0xc4, 0x08, 0xd6, 0x4c, 0x70, 0x85, 0x18, 0xd7, 0x54, 0x92, 0x5d, - 0xcc, 0x78, 0x1b, 0x13, 0x22, 0x7a, 0x5c, 0x2b, 0x44, 0x04, 0xd7, 0x52, 0x44, 0x11, 0x95, 0x28, - 0xa9, 0x23, 0xbd, 0x07, 0x63, 0x29, 0xb4, 0x30, 0x1b, 0xac, 0x43, 0xe0, 0x69, 0x30, 0x3c, 0x03, - 0x0c, 0x47, 0x60, 0x98, 0xd4, 0xed, 0xc5, 0x50, 0x84, 0x22, 0x87, 0xa3, 0xec, 0x54, 0x30, 0xd9, - 0xab, 0x17, 0x6a, 0x23, 0xa9, 0xa3, 0x18, 0x93, 0x97, 0x54, 0x97, 0xa8, 0xdb, 0x19, 0x8a, 0x08, - 0x49, 0x11, 0xd9, 0xc5, 0x9c, 0xd3, 0x28, 0xab, 0x28, 0x8f, 0x45, 0x89, 0xf7, 0xd9, 0x00, 0xb7, - 0xb6, 0x54, 0xe8, 0xd3, 0x90, 0x29, 0x4d, 0x65, 0xab, 0x62, 0x7d, 0x58, 0x90, 0x9a, 0x8b, 0x60, - 0x52, 0xbc, 0xe6, 0x54, 0x5a, 0xc6, 0x92, 0xb1, 0x3c, 0xeb, 0x17, 0x81, 0xb9, 0x01, 0x2e, 0x13, - 0xc1, 0x39, 0x25, 0x59, 0x33, 0x6d, 0x16, 0x58, 0x63, 0x59, 0xb6, 0x69, 0x0d, 0x52, 0x77, 0x71, - 0x1f, 0x77, 0xa3, 0x75, 0xef, 0xbb, 0xb4, 0xe7, 0x5f, 0x1a, 0xc5, 0xad, 0xc0, 0xb4, 0xc0, 0x74, - 0x42, 0xa5, 0x62, 0x82, 0x5b, 0xe3, 0x39, 0xed, 0x30, 0x34, 0xef, 0x81, 0x49, 0x21, 0x03, 0x2a, - 0xad, 0x89, 0x25, 0x63, 0x79, 0xbe, 0x61, 0xc3, 0xcc, 0xc2, 0x4c, 0x02, 0x1c, 0xf6, 0x9d, 0xd4, - 0xe1, 0x93, 0xac, 0xc2, 0x2f, 0x0a, 0xd7, 0x67, 0xde, 0x1e, 0xb8, 0xb5, 0xaf, 0x07, 0x6e, 0xcd, - 0x7b, 0x67, 0x80, 0x3b, 0xe7, 0x69, 0xf1, 0xa9, 0x8a, 0x05, 0x57, 0xd4, 0x5c, 0x05, 0xa0, 0x64, - 0xcb, 0x5a, 0xcf, 0x85, 0x35, 0xaf, 0x0d, 0x52, 0x77, 0xa1, 0x6c, 0xbd, 0xca, 0x79, 0xfe, 0x6c, - 0x19, 0xb4, 0x02, 0xf3, 0x2e, 0x98, 0x8e, 0x85, 0xd4, 0x23, 0xb5, 0xe6, 0x20, 0x75, 0xe7, 0x0b, - 0x48, 0x99, 0xf0, 0xfc, 0xa9, 0xec, 0xd4, 0x0a, 0xbc, 0x8f, 0x63, 0x60, 0x76, 0x4b, 0x85, 0x4f, - 0x29, 0x0f, 0x76, 0xf6, 0xfe, 0x8f, 0x89, 0x6f, 0x0c, 0x30, 0x57, 0x8c, 0xbb, 0x1d, 0x60, 0x8d, - 0x73, 0x27, 0xe7, 0x1a, 0x9b, 0xf0, 0x42, 0x4b, 0x97, 0xd4, 0xe1, 0x4f, 0xfe, 0x6c, 0xe7, 0x64, - 0x9b, 0x58, 0xe3, 0xa6, 0x7d, 0x98, 0xba, 0xb5, 0x41, 0xea, 0x9a, 0xa5, 0xbc, 0xd1, 0x35, 0x9e, - 0x0f, 0xe2, 0xaa, 0xce, 0x7c, 0x0c, 0xae, 0x4a, 0x1a, 0x61, 0xcd, 0x12, 0xda, 0xd6, 0xac, 0x4b, - 0x45, 0x4f, 0xe7, 0x93, 0x9b, 0x68, 0xde, 0x1c, 0xa4, 0xee, 0xf5, 0x02, 0xfd, 0x63, 0x85, 0xe7, - 0x5f, 0x19, 0x7e, 0xda, 0x29, 0xbe, 0x9c, 0x1a, 0x22, 0x02, 0x0b, 0x95, 0x6f, 0xd5, 0xc0, 0x6c, - 0x30, 0xa3, 0xe8, 0xab, 0x1e, 0xe5, 0x84, 0xe6, 0x16, 0x4e, 0xf8, 0x55, 0xdc, 0x38, 0x1e, 0x03, - 0xe3, 0x5b, 0x2a, 0x34, 0x3f, 0x19, 0xe0, 0xc6, 0xaf, 0xd7, 0x78, 0x1b, 0xfe, 0xfe, 0xbf, 0x08, - 0xcf, 0x5b, 0x26, 0xfb, 0xd9, 0xbf, 0x66, 0xac, 0xd4, 0xbe, 0x37, 0xc0, 0x54, 0xb9, 0x38, 0x1b, - 0x7f, 0x78, 0x49, 0x01, 0xb7, 0x1f, 0xfd, 0x15, 0x7c, 0xd8, 0x50, 0xf3, 0xc5, 0xe1, 0x89, 0x63, - 0x1c, 0x9d, 0x38, 0xc6, 0xf1, 0x89, 0x63, 0x7c, 0xe8, 0x3b, 0xb5, 0xa3, 0xbe, 0x53, 0xfb, 0xd2, - 0x77, 0x6a, 0xcf, 0xb7, 0x43, 0xa6, 0x77, 0x7b, 0x1d, 0x48, 0x44, 0x17, 0x11, 0xa1, 0xba, 0x42, - 0x21, 0xd6, 0x21, 0x2b, 0xa1, 0x40, 0xc9, 0x1a, 0xea, 0x8a, 0xa0, 0x17, 0x51, 0x95, 0xbd, 0x5b, - 0x0a, 0x35, 0xd6, 0x56, 0x46, 0x57, 0xaf, 0x9c, 0xf5, 0x72, 0xea, 0xfd, 0x98, 0xaa, 0xce, 0x54, - 0xfe, 0x2e, 0xdd, 0xff, 0x16, 0x00, 0x00, 0xff, 0xff, 0xa9, 0xf2, 0xe4, 0x17, 0x79, 0x05, 0x00, - 0x00, + // 613 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcd, 0x6e, 0xd4, 0x3c, + 0x14, 0x4d, 0xda, 0x7e, 0xfd, 0x71, 0x3f, 0x0a, 0x8d, 0x8a, 0x08, 0x01, 0x25, 0x25, 0x62, 0x51, + 0x09, 0xd5, 0xd6, 0x0c, 0x15, 0x95, 0x8a, 0xba, 0x60, 0x54, 0x90, 0x66, 0x51, 0x51, 0x85, 0x2e, + 0x10, 0x9b, 0x91, 0xc7, 0xb1, 0x52, 0x43, 0xc6, 0x0e, 0xb6, 0x27, 0xb4, 0x4b, 0x76, 0xb0, 0x41, + 0x3c, 0x42, 0x9f, 0x82, 0x57, 0xa0, 0x3b, 0xba, 0x64, 0x15, 0x55, 0xed, 0x86, 0xf5, 0x3c, 0x01, + 0xca, 0xcf, 0x64, 0x0a, 0x94, 0xaa, 0xfc, 0xed, 0x7c, 0x73, 0xef, 0x39, 0xbe, 0xe7, 0xdc, 0x1b, + 0x83, 0xfb, 0xac, 0x4b, 0x10, 0x4e, 0x92, 0x98, 0x11, 0xac, 0x99, 0xe0, 0x0a, 0x31, 0xae, 0xa9, + 0x24, 0x3b, 0x98, 0xf1, 0x0e, 0x26, 0x44, 0xf4, 0xb9, 0x56, 0x88, 0x08, 0xae, 0xa5, 0x88, 0x63, + 0x2a, 0x51, 0xda, 0x40, 0x7a, 0x17, 0x26, 0x52, 0x68, 0x61, 0x35, 0x59, 0x97, 0xc0, 0xd3, 0x60, + 0x78, 0x06, 0x18, 0x8e, 0xc0, 0x30, 0x6d, 0x38, 0x0b, 0x91, 0x88, 0x44, 0x01, 0x47, 0xf9, 0xa9, + 0x64, 0x72, 0x56, 0x2e, 0xd4, 0x46, 0xda, 0x40, 0x09, 0x26, 0x2f, 0xa8, 0xae, 0x50, 0xb7, 0x72, + 0x14, 0x11, 0x92, 0x22, 0xb2, 0x83, 0x39, 0xa7, 0x71, 0x5e, 0x51, 0x1d, 0xcb, 0x12, 0xff, 0x93, + 0x09, 0x6e, 0x6e, 0xaa, 0x28, 0xa0, 0x11, 0x53, 0x9a, 0xca, 0x76, 0xcd, 0xfa, 0xa0, 0x24, 0xb5, + 0x16, 0xc0, 0x7f, 0xe2, 0x15, 0xa7, 0xd2, 0x36, 0x17, 0xcd, 0xa5, 0x99, 0xa0, 0x0c, 0xac, 0x75, + 0x70, 0x89, 0x08, 0xce, 0x29, 0xc9, 0x9b, 0xe9, 0xb0, 0xd0, 0x1e, 0xcb, 0xb3, 0x2d, 0x7b, 0x90, + 0x79, 0x0b, 0x7b, 0xb8, 0x17, 0xaf, 0xf9, 0xdf, 0xa4, 0xfd, 0xe0, 0xff, 0x51, 0xdc, 0x0e, 0x2d, + 0x1b, 0x4c, 0xa5, 0x54, 0x2a, 0x26, 0xb8, 0x3d, 0x5e, 0xd0, 0x0e, 0x43, 0xeb, 0x1e, 0x98, 0x16, + 0x32, 0xa4, 0x92, 0xf1, 0xc8, 0x9e, 0x58, 0x34, 0x97, 0xe6, 0x9a, 0x0e, 0xcc, 0x5d, 0xcc, 0x55, + 0xc0, 0x61, 0xeb, 0x69, 0x03, 0x3e, 0xce, 0x8b, 0x82, 0xba, 0x76, 0x6d, 0xfa, 0xcd, 0xbe, 0x67, + 0x7c, 0xd9, 0xf7, 0x0c, 0xff, 0xad, 0x09, 0x6e, 0x9f, 0xa7, 0x28, 0xa0, 0x2a, 0x11, 0x5c, 0x51, + 0x6b, 0x05, 0x80, 0x8a, 0x30, 0x17, 0x50, 0xc8, 0x6b, 0x5d, 0x1d, 0x64, 0xde, 0x7c, 0x25, 0xa0, + 0xce, 0xf9, 0xc1, 0x4c, 0x15, 0xb4, 0x43, 0xeb, 0x0e, 0x98, 0x4a, 0x84, 0xd4, 0x23, 0xcd, 0xd6, + 0x20, 0xf3, 0xe6, 0x4a, 0x48, 0x95, 0xf0, 0x83, 0xc9, 0xfc, 0xd4, 0x0e, 0xfd, 0x0f, 0x63, 0x60, + 0x66, 0x53, 0x45, 0x4f, 0x28, 0x0f, 0xb7, 0x77, 0xff, 0x8d, 0x95, 0xaf, 0x4d, 0x30, 0x5b, 0x0e, + 0xbd, 0x13, 0x62, 0x8d, 0x0b, 0x3f, 0x67, 0x9b, 0x1b, 0xf0, 0x42, 0xab, 0x97, 0x36, 0xe0, 0x0f, + 0xfe, 0x6c, 0x15, 0x64, 0x1b, 0x58, 0xe3, 0x96, 0x73, 0x90, 0x79, 0xc6, 0x20, 0xf3, 0xac, 0x4a, + 0xde, 0xe8, 0x1a, 0x3f, 0x00, 0x49, 0x5d, 0x67, 0x3d, 0x02, 0x57, 0x24, 0x8d, 0xb1, 0x66, 0x29, + 0xed, 0x68, 0xd6, 0xa3, 0xa2, 0xaf, 0x8b, 0xe1, 0x4d, 0xb4, 0x6e, 0x0c, 0x32, 0xef, 0x5a, 0x89, + 0xfe, 0xbe, 0xc2, 0x0f, 0x2e, 0x0f, 0x3f, 0x6d, 0x97, 0x5f, 0x4e, 0x0d, 0x11, 0x81, 0xf9, 0xda, + 0xb7, 0x7a, 0x60, 0x0e, 0x98, 0x56, 0xf4, 0x65, 0x9f, 0x72, 0x42, 0x0b, 0x0b, 0x27, 0x82, 0x3a, + 0x6e, 0x1e, 0x8d, 0x81, 0xf1, 0x4d, 0x15, 0x59, 0x1f, 0x4d, 0x70, 0xfd, 0xe7, 0xcb, 0xbc, 0x05, + 0x7f, 0xfd, 0x8f, 0x84, 0xe7, 0x2d, 0x93, 0xf3, 0xf4, 0x6f, 0x33, 0xd6, 0x6a, 0xdf, 0x99, 0x60, + 0xb2, 0x5a, 0x9c, 0xf5, 0xdf, 0xbc, 0xa4, 0x84, 0x3b, 0x0f, 0xff, 0x08, 0x3e, 0x6c, 0xa8, 0xf5, + 0xfc, 0xe0, 0xd8, 0x35, 0x0f, 0x8f, 0x5d, 0xf3, 0xe8, 0xd8, 0x35, 0xdf, 0x9f, 0xb8, 0xc6, 0xe1, + 0x89, 0x6b, 0x7c, 0x3e, 0x71, 0x8d, 0x67, 0x5b, 0x11, 0xd3, 0x3b, 0xfd, 0x2e, 0x24, 0xa2, 0x87, + 0x88, 0x50, 0x3d, 0xa1, 0x10, 0xeb, 0x92, 0xe5, 0x48, 0xa0, 0x74, 0x15, 0xf5, 0x44, 0xd8, 0x8f, + 0xa9, 0xca, 0x5f, 0x2f, 0x85, 0x9a, 0xab, 0xcb, 0xa3, 0xab, 0x97, 0xcf, 0x7a, 0x3f, 0xf5, 0x5e, + 0x42, 0x55, 0x77, 0xb2, 0x78, 0x9d, 0xee, 0x7e, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xcb, 0x86, 0xb9, + 0xeb, 0x7f, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -406,8 +406,8 @@ func (m *MsgRegisterInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l - if m.Order != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Order)) + if m.Ordering != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Ordering)) i-- dAtA[i] = 0x20 } @@ -581,8 +581,8 @@ func (m *MsgRegisterInterchainAccount) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.Order != 0 { - n += 1 + sovTx(uint64(m.Order)) + if m.Ordering != 0 { + n += 1 + sovTx(uint64(m.Ordering)) } return n } @@ -771,9 +771,9 @@ func (m *MsgRegisterInterchainAccount) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Order", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Ordering", wireType) } - m.Order = 0 + m.Ordering = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -783,7 +783,7 @@ func (m *MsgRegisterInterchainAccount) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Order |= types.Order(b&0x7F) << shift + m.Ordering |= types.Order(b&0x7F) << shift if b < 0x80 { break } diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index 79ec288c023..874ab457b65 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -24,7 +24,7 @@ message MsgRegisterInterchainAccount { string owner = 1; string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; string version = 3; - ibc.core.channel.v1.Order order = 4; + ibc.core.channel.v1.Order ordering = 4; } // MsgRegisterInterchainAccountResponse defines the response for Msg/RegisterAccount From 5094af4693de9469f7857a5612f0ade57f5ac8a6 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 26 Apr 2024 09:30:33 +0200 Subject: [PATCH 4/5] add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a87dbc934..df41c312f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (apps/27-interchain-accounts) [\#5633](https://github.com/cosmos/ibc-go/pull/5633) Allow new ICA channels to use unordered ordering. + ### Bug Fixes ## [v7.4.0](https://github.com/cosmos/ibc-go/releases/tag/v7.4.0) - 2024-04-05 From fe5e588a1765e3fcc6ac8dc12a088aaa2e20d87d Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 30 Apr 2024 10:01:41 +0200 Subject: [PATCH 5/5] Update messages.md --- docs/apps/interchain-accounts/messages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/apps/interchain-accounts/messages.md b/docs/apps/interchain-accounts/messages.md index c13a7a26930..f1f735de2e2 100644 --- a/docs/apps/interchain-accounts/messages.md +++ b/docs/apps/interchain-accounts/messages.md @@ -13,7 +13,7 @@ type MsgRegisterInterchainAccount struct { Owner string ConnectionID string Version string - Order channeltypes.Order + Ordering channeltypes.Order } ```