From 62b0fb34d58dc9918388b9d078816d49eb7b23b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:15:34 +0200 Subject: [PATCH 1/5] refactor: always set ics27 ports regardless of whether the capability exists Add e2e to test integration points. Refactor persisted port state to be separate from port binding/creation --- e2e/tests/upgrades/genesis_test.go | 102 +++++++++++++++++- .../controller/keeper/account.go | 3 +- .../controller/keeper/genesis.go | 9 +- .../controller/keeper/keeper.go | 6 +- .../host/keeper/genesis.go | 8 +- .../host/keeper/keeper.go | 6 +- modules/apps/27-interchain-accounts/module.go | 14 +-- 7 files changed, 125 insertions(+), 23 deletions(-) diff --git a/e2e/tests/upgrades/genesis_test.go b/e2e/tests/upgrades/genesis_test.go index 7f1e4d457d3..ae998a2b3cb 100644 --- a/e2e/tests/upgrades/genesis_test.go +++ b/e2e/tests/upgrades/genesis_test.go @@ -6,14 +6,24 @@ import ( "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" + ibctesting "github.com/cosmos/ibc-go/v8/testing" ) func TestGenesisTestSuite(t *testing.T) { @@ -55,12 +65,12 @@ func (s *GenesisTestSuite) TestIBCGenesis() { s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") - t.Run("native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) { + 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("tokens are escrowed", func(t *testing.T) { + t.Run("ics20: tokens are escrowed", func(t *testing.T) { actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) s.Require().NoError(err) @@ -68,11 +78,27 @@ func (s *GenesisTestSuite) TestIBCGenesis() { 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) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + t.Run("start relayer", func(t *testing.T) { s.StartRelayer(relayer) }) - t.Run("packets are relayed", func(t *testing.T) { + t.Run("ics20: packets are relayed", func(t *testing.T) { s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) actualBalance, err := chainB.GetBalance(ctx, chainBAddress, chainBIBCToken.IBCDenom()) @@ -82,18 +108,29 @@ func (s *GenesisTestSuite) TestIBCGenesis() { 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, relayer, int64(haltHeight)) }) - t.Run("native IBC token transfer from chainA to chainB, sender is source of tokens", func(t *testing.T) { + 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("tokens are escrowed", func(t *testing.T) { + t.Run("ics20: tokens are escrowed", func(t *testing.T) { actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) s.Require().NoError(err) @@ -101,6 +138,61 @@ func (s *GenesisTestSuite) TestIBCGenesis() { 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)) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom) + s.Require().NoError(err) + + _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance.Int64()) + }) + }) + s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index ae52a975e58..bd0b04513c4 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -62,7 +62,8 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, case k.portKeeper.IsBound(ctx, portID) && !k.hasCapability(ctx, portID): return "", errorsmod.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) case !k.portKeeper.IsBound(ctx, portID): - capability := k.BindPort(ctx, portID) + k.setPort(ctx, portID) + capability := k.portKeeper.BindPort(ctx, portID) if err := k.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil { return "", errorsmod.Wrapf(err, "unable to bind to newly generated portID: %s", portID) } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index f41155e8ca6..9404e43bf7e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -12,8 +12,15 @@ import ( // InitGenesis initializes the interchain accounts controller application state from a provided genesis state func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) { for _, portID := range state.Ports { + keeper.setPort(ctx, portID) + + // generate port capability if it does not already exist if !keeper.hasCapability(ctx, portID) { - capability := keeper.BindPort(ctx, portID) + // use the port keeper to generate a new capability + capability := keeper.portKeeper.BindPort(ctx, portID) + + // use the controller scoped keeper to claim the port capability + if err := keeper.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 88d93cf6af7..3dd1d3342a6 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -102,12 +102,10 @@ func (k Keeper) GetAllPorts(ctx sdk.Context) []string { return ports } -// BindPort stores the provided portID and binds to it, returning the associated capability -func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { +// setPort sets the provided portID in state +func (k Keeper) setPort(ctx sdk.Context, portID string) { store := ctx.KVStore(k.storeKey) store.Set(icatypes.KeyPort(portID), []byte{0x01}) - - return k.portKeeper.BindPort(ctx, portID) } // hasCapability checks if the interchain account controller module owns the port capability for the desired port diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 86e3f3c3c01..28d58c3f766 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -12,8 +12,14 @@ import ( // InitGenesis initializes the interchain accounts host application state from a provided genesis state func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisState) { + keeper.setPort(ctx, state.Port) + + // generate port capability if it does not already exist if !keeper.hasCapability(ctx, state.Port) { - capability := keeper.BindPort(ctx, state.Port) + // use the port keeper to generate a new capability + capability := keeper.portKeeper.BindPort(ctx, state.Port) + + // use the host scoped keeper to claim the port capability if err := keeper.ClaimCapability(ctx, capability, host.PortPath(state.Port)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index d2361fc577f..c9e442854e6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -85,12 +85,10 @@ func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName)) } -// BindPort stores the provided portID and binds to it, returning the associated capability -func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { +// setPort sets the provided portID in state. +func (k Keeper) setPort(ctx sdk.Context, portID string) { store := ctx.KVStore(k.storeKey) store.Set(icatypes.KeyPort(portID), []byte{0x01}) - - return k.portKeeper.BindPort(ctx, portID) } // hasCapability checks if the interchain account host module owns the port capability for the desired port diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 5d02007f402..4a2996bbb93 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -29,7 +29,6 @@ import ( "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/simulation" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" - ibchost "github.com/cosmos/ibc-go/v8/modules/core/24-host" ) var ( @@ -123,19 +122,20 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee // called once and as an alternative to InitGenesis. func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes.Params, hostParams hosttypes.Params) { if am.controllerKeeper != nil { - am.controllerKeeper.SetParams(ctx, controllerParams) + controllerkeeper.InitGenesis(ctx, *am.controllerKeeper, genesistypes.ControllerGenesisState{ + Params: controllerParams, + }) } if am.hostKeeper != nil { if err := hostParams.Validate(); err != nil { panic(fmt.Sprintf("could not set ica host params at initialization: %v", err)) } - am.hostKeeper.SetParams(ctx, hostParams) - capability := am.hostKeeper.BindPort(ctx, types.HostPortID) - if err := am.hostKeeper.ClaimCapability(ctx, capability, ibchost.PortPath(types.HostPortID)); err != nil { - panic(fmt.Sprintf("could not claim port capability: %v", err)) - } + hostkeeper.InitGenesis(ctx, *am.hostKeeper, genesistypes.HostGenesisState{ + Params: hostParams, + Port: types.HostPortID, + }) } } From 69cb39f80ea9776f76b4acdab57928aa35df50d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:28:48 +0200 Subject: [PATCH 2/5] test: add tests for host genesis logic --- .../host/keeper/genesis_test.go | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 3ef7d2b9402..3af1f494f28 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -4,14 +4,30 @@ import ( genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" + icahosttypes "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" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v8/testing" ) func (suite *KeeperTestSuite) TestInitGenesis() { - suite.SetupTest() - interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) + testCases := []struct { + name string + malleate func() + }{ + { + "sucess", func() {}, + }, + { + "success: capabilities already initialized", + func() { + capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) + err := suite.chainA.GetSimApp().ICAHostKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID)) + suite.Require().NoError(err) + }, + }, + } genesisState := genesistypes.HostGenesisState{ ActiveChannels: []genesistypes.ActiveChannel{ @@ -31,19 +47,36 @@ func (suite *KeeperTestSuite) TestInitGenesis() { Port: icatypes.HostPortID, } - keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + tc.malleate() + + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) - channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) - suite.Require().True(found) - suite.Require().Equal(ibctesting.FirstChannelID, channelID) + channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(ibctesting.FirstChannelID, channelID) - accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) - suite.Require().True(found) - suite.Require().Equal(interchainAccAddr.String(), accountAdrr) + accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(interchainAccAddr.String(), accountAdrr) - expParams := genesisState.GetParams() - params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) + expParams := genesisState.GetParams() + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)) + suite.Require().True(store.Has(icatypes.KeyPort(icatypes.HostPortID))) + + capability, found := suite.chainA.GetSimApp().ScopedICAHostKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(icatypes.HostPortID)) + suite.Require().True(found) + suite.Require().NotNil(capability) + }) + } } func (suite *KeeperTestSuite) TestGenesisParams() { From dbf18a7c2bad2ea69c019d3bdf0140cbf64590d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:48:29 +0200 Subject: [PATCH 3/5] test: add controller genesis test and fixup host test --- .../controller/keeper/genesis.go | 1 - .../controller/keeper/genesis_test.go | 70 ++++++++++++++----- .../host/keeper/genesis_test.go | 57 ++++----------- 3 files changed, 69 insertions(+), 59 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index 9404e43bf7e..10655ff3367 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -20,7 +20,6 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGe capability := keeper.portKeeper.BindPort(ctx, portID) // use the controller scoped keeper to claim the port capability - if err := keeper.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go index c6670745765..24154bde1bc 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go @@ -3,13 +3,32 @@ package keeper_test import ( "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v8/testing" ) func (suite *KeeperTestSuite) TestInitGenesis() { - suite.SetupTest() + ports := []string{"port1", "port2", "port3"} + + testCases := []struct { + name string + malleate func() + }{ + { + "sucess", func() {}, + }, + { + "success: capabilities already initialized for first port", + func() { + capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), ports[0]) + err := suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(ports[0])) + suite.Require().NoError(err) + }, + }, + } interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) genesisState := genesistypes.ControllerGenesisState{ @@ -34,28 +53,47 @@ func (suite *KeeperTestSuite) TestInitGenesis() { AccountAddress: interchainAccAddr.String(), }, }, - Ports: []string{TestPortID}, + Ports: ports, } + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() - keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper, genesisState) + tc.malleate() - channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) - suite.Require().True(found) - suite.Require().Equal(ibctesting.FirstChannelID, channelID) + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper, genesisState) - isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled(suite.chainA.GetContext(), TestPortID, ibctesting.FirstConnectionID) - suite.Require().True(isMiddlewareEnabled) + channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(ibctesting.FirstChannelID, channelID) - isMiddlewareDisabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareDisabled(suite.chainA.GetContext(), "test-port-1", "connection-1") - suite.Require().True(isMiddlewareDisabled) + isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled(suite.chainA.GetContext(), TestPortID, ibctesting.FirstConnectionID) + suite.Require().True(isMiddlewareEnabled) - accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) - suite.Require().True(found) - suite.Require().Equal(interchainAccAddr.String(), accountAdrr) + isMiddlewareDisabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareDisabled(suite.chainA.GetContext(), "test-port-1", "connection-1") + suite.Require().True(isMiddlewareDisabled) + + accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(interchainAccAddr.String(), accountAdrr) + + expParams := types.NewParams(false) + params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + + for _, port := range ports { + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)) + suite.Require().True(store.Has(icatypes.KeyPort(port))) + + capability, found := suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(port)) + suite.Require().True(found) + suite.Require().NotNil(capability) + } + }) + } - expParams := types.NewParams(false) - params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) } func (suite *KeeperTestSuite) TestExportGenesis() { diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 3af1f494f28..e9514cd890c 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -12,23 +12,6 @@ import ( func (suite *KeeperTestSuite) TestInitGenesis() { interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) - testCases := []struct { - name string - malleate func() - }{ - { - "sucess", func() {}, - }, - { - "success: capabilities already initialized", - func() { - capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) - err := suite.chainA.GetSimApp().ICAHostKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID)) - suite.Require().NoError(err) - }, - }, - } - genesisState := genesistypes.HostGenesisState{ ActiveChannels: []genesistypes.ActiveChannel{ { @@ -47,36 +30,26 @@ func (suite *KeeperTestSuite) TestInitGenesis() { Port: icatypes.HostPortID, } - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() - - tc.malleate() + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) - keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) + channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(ibctesting.FirstChannelID, channelID) - channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) - suite.Require().True(found) - suite.Require().Equal(ibctesting.FirstChannelID, channelID) + accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(interchainAccAddr.String(), accountAdrr) - accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) - suite.Require().True(found) - suite.Require().Equal(interchainAccAddr.String(), accountAdrr) + expParams := genesisState.GetParams() + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) - expParams := genesisState.GetParams() - params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)) + suite.Require().True(store.Has(icatypes.KeyPort(icatypes.HostPortID))) - store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)) - suite.Require().True(store.Has(icatypes.KeyPort(icatypes.HostPortID))) - - capability, found := suite.chainA.GetSimApp().ScopedICAHostKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(icatypes.HostPortID)) - suite.Require().True(found) - suite.Require().NotNil(capability) - }) - } + capability, found := suite.chainA.GetSimApp().ScopedICAHostKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(icatypes.HostPortID)) + suite.Require().True(found) + suite.Require().NotNil(capability) } func (suite *KeeperTestSuite) TestGenesisParams() { From cc239e21c94b5239822ac4462fe01b56b76c8925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:53:41 +0200 Subject: [PATCH 4/5] lint lint lint --- .../controller/keeper/genesis_test.go | 6 ++---- .../apps/27-interchain-accounts/host/keeper/genesis_test.go | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go index 24154bde1bc..aab068e6cf1 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -18,7 +17,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { malleate func() }{ { - "sucess", func() {}, + "success", func() {}, }, { "success: capabilities already initialized for first port", @@ -84,7 +83,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().Equal(expParams, params) for _, port := range ports { - store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)) + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.StoreKey)) suite.Require().True(store.Has(icatypes.KeyPort(port))) capability, found := suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(port)) @@ -93,7 +92,6 @@ func (suite *KeeperTestSuite) TestInitGenesis() { } }) } - } func (suite *KeeperTestSuite) TestExportGenesis() { diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index e9514cd890c..72d13d9e320 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -4,7 +4,6 @@ import ( genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" - icahosttypes "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" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v8/testing" @@ -44,7 +43,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) - store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)) + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.StoreKey)) suite.Require().True(store.Has(icatypes.KeyPort(icatypes.HostPortID))) capability, found := suite.chainA.GetSimApp().ScopedICAHostKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(icatypes.HostPortID)) From a36a978780b7f90a91aefff81944434308725262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:25:49 +0200 Subject: [PATCH 5/5] fix: remove verification assertion in e2e as we have not checked for relayer support across genesis retarts --- e2e/tests/upgrades/genesis_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/e2e/tests/upgrades/genesis_test.go b/e2e/tests/upgrades/genesis_test.go index ae998a2b3cb..9728549c184 100644 --- a/e2e/tests/upgrades/genesis_test.go +++ b/e2e/tests/upgrades/genesis_test.go @@ -180,17 +180,6 @@ func (s *GenesisTestSuite) TestIBCGenesis() { s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) }) - - t.Run("verify tokens transferred", func(t *testing.T) { - balance, err := chainB.GetBalance(ctx, chainBAccount.FormattedAddress(), chainB.Config().Denom) - s.Require().NoError(err) - - _, err = chainB.GetBalance(ctx, hostAccount, chainB.Config().Denom) - s.Require().NoError(err) - - expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount - s.Require().Equal(expected, balance.Int64()) - }) }) s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks")