From 09c053a498fd070c2a0d3de2d813d010308d0b6a Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 30 Aug 2022 14:59:13 +0200 Subject: [PATCH 1/9] feat: implementing SubmitTx gRPC endpoint --- .../controller/keeper/msg_server.go | 26 ++++ .../controller/keeper/msg_server_test.go | 128 +++++++++++++++++- 2 files changed, 151 insertions(+), 3 deletions(-) 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 aaf50bcb930..51939cc728d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -4,8 +4,12 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v5/modules/core/24-host" ) var _ types.MsgServer = Keeper{} @@ -26,5 +30,27 @@ func (k Keeper) RegisterAccount(goCtx context.Context, msg *types.MsgRegisterAcc // SubmitTx defines a rpc handler for MsgSubmitTx func (k Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + portID, err := icatypes.NewControllerPortID(msg.Owner) + if err != nil { + return nil, err + } + + channelID, found := k.GetActiveChannelID(ctx, msg.ConnectionId, portID) + if !found { + return nil, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) + } + + chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) + if !found { + return nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } + + _, err = k.SendTx(ctx, chanCap, msg.ConnectionId, portID, msg.PacketData, msg.TimeoutTimestamp) + if err != nil { + return nil, err + } + return &types.MsgSubmitTxResponse{}, nil } 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 461d16dfb44..322037a243f 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 @@ -1,9 +1,16 @@ package keeper_test import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" sdktypes "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" + clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v5/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v5/testing" @@ -11,7 +18,7 @@ import ( func (suite *KeeperTestSuite) TestRegisterAccount() { var ( - msg *icatypes.MsgRegisterAccount + msg *icacontrollertypes.MsgRegisterAccount expectedChannelID = "channel-0" ) @@ -63,7 +70,7 @@ func (suite *KeeperTestSuite) TestRegisterAccount() { path := NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) - msg = icatypes.NewMsgRegisterAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") + msg = icacontrollertypes.NewMsgRegisterAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") tc.malleate() @@ -85,3 +92,118 @@ func (suite *KeeperTestSuite) TestRegisterAccount() { } } } + +func (suite *KeeperTestSuite) TestSubmitTx() { + var ( + path *ibctesting.Path + owner string + connectionId string + icaMsg sdk.Msg + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", func() { + owner = TestOwnerAddress + connectionId = path.EndpointA.ConnectionID + }, + true, + }, + /* + { + "failure - owner address is empty", func() { + owner = "" + connectionId = path.EndpointA.ConnectionID + }, + }, + { + "failure - active channel does not exist for connection ID", func() { + owner = TestOwnerAddress + connectionId = "connection-100" + }, + }, + { + "failure - active channel does not exist for port ID", func() { + owner = "cosmos153lf4zntqt33a4v0sm5cytrxyqn78q7kz8j8x5" + connectionId = path.EndpointA.ConnectionID + }, + }, + { + "failure - module does not own channel capability", func() { + owner = TestOwnerAddress + connectionId = path.EndpointA.ConnectionID + icaMsg = &banktypes.MsgSend{ + FromAddress: "source-address", + ToAddress: "destination-address", + Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + } + }, + }, + */ + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + path = NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + tc.malleate() // malleate mutates test data + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + portID, err := icatypes.NewControllerPortID(TestOwnerAddress) + suite.Require().NoError(err) + + // Get the address of the interchain account stored in state during handshake step + interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ConnectionID, portID) + suite.Require().True(found) + + icaAddr, err := sdk.AccAddressFromBech32(interchainAccountAddr) + suite.Require().NoError(err) + + // Check if account is created + interchainAccount := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), icaAddr) + suite.Require().Equal(interchainAccount.GetAddress().String(), interchainAccountAddr) + + // Create bank transfer message to execute on the host + icaMsg = &banktypes.MsgSend{ + FromAddress: interchainAccountAddr, + ToAddress: suite.chainB.SenderAccount.GetAddress().String(), + Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + } + + data, err := icatypes.SerializeCosmosTx(suite.chainA.Codec, []sdk.Msg{icaMsg}) + suite.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: data, + Memo: "memo", + } + + // timeoutTimestamp set to max value with the unsigned bit shifted to sastisfy hermes timestamp conversion + // it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp + timeoutTimestamp := suite.chainA.GetContext().BlockTime().Add(time.Minute).UnixNano() + + msg := types.NewMsgSubmitTx(owner, connectionId, clienttypes.NewHeight(0, 0), uint64(timeoutTimestamp), packetData) + res, err := suite.chainA.GetSimApp().ICAControllerKeeper.SubmitTx(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + } else { + suite.Require().Error(err) + suite.Require().Nil(res) + } + }) + } +} From 5168cfd90e7c62dee21a513893c76716afb2cb9e Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 31 Aug 2022 14:48:48 +0200 Subject: [PATCH 2/9] test: adding failure cases --- .../controller/keeper/msg_server_test.go | 46 ++++++++----------- 1 file changed, 18 insertions(+), 28 deletions(-) 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 322037a243f..aa64b111c4e 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 @@ -113,37 +113,27 @@ func (suite *KeeperTestSuite) TestSubmitTx() { }, true, }, - /* - { - "failure - owner address is empty", func() { - owner = "" - connectionId = path.EndpointA.ConnectionID - }, - }, - { - "failure - active channel does not exist for connection ID", func() { - owner = TestOwnerAddress - connectionId = "connection-100" - }, + { + "failure - owner address is empty", func() { + owner = "" + connectionId = path.EndpointA.ConnectionID }, - { - "failure - active channel does not exist for port ID", func() { - owner = "cosmos153lf4zntqt33a4v0sm5cytrxyqn78q7kz8j8x5" - connectionId = path.EndpointA.ConnectionID - }, + false, + }, + { + "failure - active channel does not exist for connection ID", func() { + owner = TestOwnerAddress + connectionId = "connection-100" }, - { - "failure - module does not own channel capability", func() { - owner = TestOwnerAddress - connectionId = path.EndpointA.ConnectionID - icaMsg = &banktypes.MsgSend{ - FromAddress: "source-address", - ToAddress: "destination-address", - Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), - } - }, + false, + }, + { + "failure - active channel does not exist for port ID", func() { + owner = "cosmos153lf4zntqt33a4v0sm5cytrxyqn78q7kz8j8x5" + connectionId = path.EndpointA.ConnectionID }, - */ + false, + }, } for _, tc := range testCases { From c83cb4cb5b7b43d90a8e74ae2b8fc9a973f85ecd Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 31 Aug 2022 15:09:16 +0200 Subject: [PATCH 3/9] add capability test --- .../controller/keeper/msg_server_test.go | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) 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 aa64b111c4e..10b2646f6d7 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 @@ -97,7 +97,7 @@ func (suite *KeeperTestSuite) TestSubmitTx() { var ( path *ibctesting.Path owner string - connectionId string + connectionID string icaMsg sdk.Msg ) @@ -109,28 +109,36 @@ func (suite *KeeperTestSuite) TestSubmitTx() { { "success", func() { owner = TestOwnerAddress - connectionId = path.EndpointA.ConnectionID }, true, }, { "failure - owner address is empty", func() { owner = "" - connectionId = path.EndpointA.ConnectionID }, false, }, { "failure - active channel does not exist for connection ID", func() { owner = TestOwnerAddress - connectionId = "connection-100" + connectionID = "connection-100" }, false, }, { "failure - active channel does not exist for port ID", func() { - owner = "cosmos153lf4zntqt33a4v0sm5cytrxyqn78q7kz8j8x5" - connectionId = path.EndpointA.ConnectionID + owner = TestAccAddress.String() + }, + false, + }, + { + "failure - controller module does not own capability for this channel", func() { + owner = TestAccAddress.String() + portID, err := icatypes.NewControllerPortID(owner) + suite.Require().NoError(err) + + // set the active channel with the incorrect portID in order to reach the capability check + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), connectionID, portID, path.EndpointA.ChannelID) }, false, }, @@ -145,8 +153,6 @@ func (suite *KeeperTestSuite) TestSubmitTx() { path = NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) - tc.malleate() // malleate mutates test data - err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) @@ -183,8 +189,11 @@ func (suite *KeeperTestSuite) TestSubmitTx() { // timeoutTimestamp set to max value with the unsigned bit shifted to sastisfy hermes timestamp conversion // it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp timeoutTimestamp := suite.chainA.GetContext().BlockTime().Add(time.Minute).UnixNano() + connectionID = path.EndpointA.ConnectionID + + tc.malleate() // malleate mutates test data - msg := types.NewMsgSubmitTx(owner, connectionId, clienttypes.NewHeight(0, 0), uint64(timeoutTimestamp), packetData) + msg := types.NewMsgSubmitTx(owner, connectionID, clienttypes.NewHeight(0, 0), uint64(timeoutTimestamp), packetData) res, err := suite.chainA.GetSimApp().ICAControllerKeeper.SubmitTx(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tc.expPass { From d64f950550eca42f0345e5b2b0970b8304d37ace Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 31 Aug 2022 15:09:51 +0200 Subject: [PATCH 4/9] chore: comment --- .../controller/keeper/msg_server_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 10b2646f6d7..f41f85f63b8 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 @@ -159,18 +159,18 @@ func (suite *KeeperTestSuite) TestSubmitTx() { portID, err := icatypes.NewControllerPortID(TestOwnerAddress) suite.Require().NoError(err) - // Get the address of the interchain account stored in state during handshake step + // get the address of the interchain account stored in state during handshake step interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ConnectionID, portID) suite.Require().True(found) icaAddr, err := sdk.AccAddressFromBech32(interchainAccountAddr) suite.Require().NoError(err) - // Check if account is created + // check if account is created interchainAccount := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), icaAddr) suite.Require().Equal(interchainAccount.GetAddress().String(), interchainAccountAddr) - // Create bank transfer message to execute on the host + // create bank transfer message to execute on the host icaMsg = &banktypes.MsgSend{ FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), From 06a5bd6461394a521df97726a9357816a731dfb2 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 31 Aug 2022 15:18:26 +0200 Subject: [PATCH 5/9] chore: cleanup --- .../controller/keeper/msg_server_test.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) 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 f41f85f63b8..8c6be264f96 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 @@ -163,14 +163,7 @@ func (suite *KeeperTestSuite) TestSubmitTx() { interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ConnectionID, portID) suite.Require().True(found) - icaAddr, err := sdk.AccAddressFromBech32(interchainAccountAddr) - suite.Require().NoError(err) - - // check if account is created - interchainAccount := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), icaAddr) - suite.Require().Equal(interchainAccount.GetAddress().String(), interchainAccountAddr) - - // create bank transfer message to execute on the host + // create bank transfer message that will execute on the host chain icaMsg = &banktypes.MsgSend{ FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), @@ -186,8 +179,6 @@ func (suite *KeeperTestSuite) TestSubmitTx() { Memo: "memo", } - // timeoutTimestamp set to max value with the unsigned bit shifted to sastisfy hermes timestamp conversion - // it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp timeoutTimestamp := suite.chainA.GetContext().BlockTime().Add(time.Minute).UnixNano() connectionID = path.EndpointA.ConnectionID From 743001a9bc8489d76537f40bdad662c9440293eb Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 31 Aug 2022 15:26:39 +0200 Subject: [PATCH 6/9] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 621401a5030..cb568c72c7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality. + ### Bug Fixes * (makefile) [\#1785](https://github.com/cosmos/ibc-go/pull/1785) Fetch the correct versions of protocol buffers dependencies from tendermint, cosmos-sdk, and ics23. From 9bed0f5c3cb0a670a36f02c9702c6df7bf84c7fe Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 31 Aug 2022 17:15:03 +0200 Subject: [PATCH 7/9] import & sequence --- .../27-interchain-accounts/controller/keeper/msg_server.go | 4 ++-- .../controller/keeper/msg_server_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) 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 51939cc728d..c5cfd108d3d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -47,10 +47,10 @@ func (k Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types. return nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } - _, err = k.SendTx(ctx, chanCap, msg.ConnectionId, portID, msg.PacketData, msg.TimeoutTimestamp) + seq, err := k.SendTx(ctx, chanCap, msg.ConnectionId, portID, msg.PacketData, msg.TimeoutTimestamp) if err != nil { return nil, err } - return &types.MsgSubmitTxResponse{}, nil + return &types.MsgSubmitTxResponse{Sequence: seq}, nil } 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 8c6be264f96..428a025160e 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 @@ -8,7 +8,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" - icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" + controllertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -18,7 +18,7 @@ import ( func (suite *KeeperTestSuite) TestRegisterAccount() { var ( - msg *icacontrollertypes.MsgRegisterAccount + msg *controllertypes.MsgRegisterAccount expectedChannelID = "channel-0" ) @@ -70,7 +70,7 @@ func (suite *KeeperTestSuite) TestRegisterAccount() { path := NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) - msg = icacontrollertypes.NewMsgRegisterAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") + msg = controllertypes.NewMsgRegisterAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") tc.malleate() From 084712ade6d9c03de83a7532bcc1f4724a5321e4 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 1 Sep 2022 08:58:21 +0200 Subject: [PATCH 8/9] nits --- .../controller/keeper/msg_server_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 428a025160e..e99790b9331 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 @@ -108,7 +108,6 @@ func (suite *KeeperTestSuite) TestSubmitTx() { }{ { "success", func() { - owner = TestOwnerAddress }, true, }, @@ -150,10 +149,11 @@ func (suite *KeeperTestSuite) TestSubmitTx() { suite.Run(tc.name, func() { suite.SetupTest() + owner = TestOwnerAddress path = NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) - err := SetupICAPath(path, TestOwnerAddress) + err := SetupICAPath(path, owner) suite.Require().NoError(err) portID, err := icatypes.NewControllerPortID(TestOwnerAddress) @@ -179,12 +179,12 @@ func (suite *KeeperTestSuite) TestSubmitTx() { Memo: "memo", } - timeoutTimestamp := suite.chainA.GetContext().BlockTime().Add(time.Minute).UnixNano() + timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().Add(time.Minute).UnixNano()) connectionID = path.EndpointA.ConnectionID tc.malleate() // malleate mutates test data - msg := types.NewMsgSubmitTx(owner, connectionID, clienttypes.NewHeight(0, 0), uint64(timeoutTimestamp), packetData) + msg := types.NewMsgSubmitTx(owner, connectionID, clienttypes.ZeroHeight(), timeoutTimestamp, packetData) res, err := suite.chainA.GetSimApp().ICAControllerKeeper.SubmitTx(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tc.expPass { From 74c9fbc17316c15c3a8066d21f67ab444e553bcd Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 1 Sep 2022 09:20:41 +0200 Subject: [PATCH 9/9] refactor: clean up tests --- .../controller/keeper/msg_server_test.go | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) 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 e99790b9331..38aa673015c 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 @@ -95,10 +95,8 @@ func (suite *KeeperTestSuite) TestRegisterAccount() { func (suite *KeeperTestSuite) TestSubmitTx() { var ( - path *ibctesting.Path - owner string - connectionID string - icaMsg sdk.Msg + path *ibctesting.Path + msg *controllertypes.MsgSubmitTx ) testCases := []struct { @@ -113,31 +111,31 @@ func (suite *KeeperTestSuite) TestSubmitTx() { }, { "failure - owner address is empty", func() { - owner = "" + msg.Owner = "" }, false, }, { "failure - active channel does not exist for connection ID", func() { - owner = TestOwnerAddress - connectionID = "connection-100" + msg.Owner = TestOwnerAddress + msg.ConnectionId = "connection-100" }, false, }, { "failure - active channel does not exist for port ID", func() { - owner = TestAccAddress.String() + msg.Owner = TestAccAddress.String() }, false, }, { "failure - controller module does not own capability for this channel", func() { - owner = TestAccAddress.String() - portID, err := icatypes.NewControllerPortID(owner) + msg.Owner = TestAccAddress.String() + portID, err := icatypes.NewControllerPortID(msg.Owner) suite.Require().NoError(err) // set the active channel with the incorrect portID in order to reach the capability check - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), connectionID, portID, path.EndpointA.ChannelID) + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), path.EndpointA.ConnectionID, portID, path.EndpointA.ChannelID) }, false, }, @@ -149,7 +147,7 @@ func (suite *KeeperTestSuite) TestSubmitTx() { suite.Run(tc.name, func() { suite.SetupTest() - owner = TestOwnerAddress + owner := TestOwnerAddress path = NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) @@ -164,7 +162,7 @@ func (suite *KeeperTestSuite) TestSubmitTx() { suite.Require().True(found) // create bank transfer message that will execute on the host chain - icaMsg = &banktypes.MsgSend{ + icaMsg := &banktypes.MsgSend{ FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), @@ -180,11 +178,11 @@ func (suite *KeeperTestSuite) TestSubmitTx() { } timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().Add(time.Minute).UnixNano()) - connectionID = path.EndpointA.ConnectionID + connectionID := path.EndpointA.ConnectionID - tc.malleate() // malleate mutates test data + msg = types.NewMsgSubmitTx(owner, connectionID, clienttypes.ZeroHeight(), timeoutTimestamp, packetData) - msg := types.NewMsgSubmitTx(owner, connectionID, clienttypes.ZeroHeight(), timeoutTimestamp, packetData) + tc.malleate() // malleate mutates test data res, err := suite.chainA.GetSimApp().ICAControllerKeeper.SubmitTx(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tc.expPass {