From 6b604027dfb9df991de249ea97991b0462deab6b Mon Sep 17 00:00:00 2001 From: DongLieu Date: Wed, 11 Oct 2023 16:06:23 +0700 Subject: [PATCH 1/6] Test for msgSV.GovCloseChannel --- x/interchainstaking/keeper/msg_server_test.go | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 7e3d8c8a0..242b7da41 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -7,6 +7,9 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + connectiontypes "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types" "github.com/quicksilver-zone/quicksilver/utils/addressutils" icskeeper "github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper" @@ -493,3 +496,84 @@ func (suite *KeeperTestSuite) TestSignalIntent() { }) } } + +func (suite *KeeperTestSuite) TestGovCloseChannel() { + testCase := []struct { + name string + malleate func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel + expecErr error + }{ + { + name: "invalid authority", + malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel { + return &icstypes.MsgGovCloseChannel{ + ChannelId: "", + PortId: "", + Authority: testAddress, + } + }, + expecErr: govtypes.ErrInvalidSigner, + }, + { + name: "capability not found", + malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel { + k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + + return &icstypes.MsgGovCloseChannel{ + ChannelId: "", + PortId: "", + Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), + } + }, + expecErr: capabilitytypes.ErrCapabilityNotFound, + }, + { + name: "invalid connection state", + malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel { + ctx := suite.chainA.GetContext() + k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + chanals := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx) + + return &icstypes.MsgGovCloseChannel{ + ChannelId: chanals[0].ChannelId, + PortId: chanals[0].PortId, + Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), + } + }, + expecErr: connectiontypes.ErrInvalidConnectionState, + }, + { + name: "closes an ICA channel success", + malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel { + ctx := suite.chainA.GetContext() + suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ConnectionKeeper.SetConnection(ctx, suite.path.EndpointA.ConnectionID, connectiontypes.ConnectionEnd{ClientId: "07-tendermint-0", State: connectiontypes.OPEN}) + k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + chanals := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx) + + return &icstypes.MsgGovCloseChannel{ + ChannelId: chanals[0].ChannelId, + PortId: chanals[0].PortId, + Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), + } + }, + expecErr: nil, + }, + } + for _, tc := range testCase { + suite.Run(tc.name, func() { + suite.SetupTest() + suite.setupTestZones() + + msg := tc.malleate(suite) + msgSrv := icskeeper.NewMsgServerImpl(*suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + ctx := suite.chainA.GetContext() + + _, err := msgSrv.GovCloseChannel(ctx, msg) + if tc.expecErr != nil { + suite.ErrorIs(tc.expecErr, err) + return + } + suite.NoError(err) + }) + } +} From 1de344e2e91b286862802dbd38c336ccff742dec Mon Sep 17 00:00:00 2001 From: DongLieu Date: Fri, 13 Oct 2023 11:33:44 +0700 Subject: [PATCH 2/6] rename --- x/interchainstaking/keeper/msg_server_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 242b7da41..73ccdfff6 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -532,11 +532,11 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel { ctx := suite.chainA.GetContext() k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper - chanals := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx) + channels := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx) return &icstypes.MsgGovCloseChannel{ - ChannelId: chanals[0].ChannelId, - PortId: chanals[0].PortId, + ChannelId: channels[0].ChannelId, + PortId: channels[0].PortId, Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), } }, @@ -548,11 +548,11 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { ctx := suite.chainA.GetContext() suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ConnectionKeeper.SetConnection(ctx, suite.path.EndpointA.ConnectionID, connectiontypes.ConnectionEnd{ClientId: "07-tendermint-0", State: connectiontypes.OPEN}) k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper - chanals := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx) + channels := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx) return &icstypes.MsgGovCloseChannel{ - ChannelId: chanals[0].ChannelId, - PortId: chanals[0].PortId, + ChannelId: channels[0].ChannelId, + PortId: channels[0].PortId, Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), } }, From e0272c6c10fd9d54a86d8f3cd6bd4fd308404f8b Mon Sep 17 00:00:00 2001 From: DongLieu Date: Fri, 13 Oct 2023 12:19:44 +0700 Subject: [PATCH 3/6] lint --- x/interchainstaking/keeper/msg_server_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 73ccdfff6..069878a3f 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + connectiontypes "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types" "github.com/quicksilver-zone/quicksilver/utils/addressutils" From db3369c9ecaf07574166edf372d0a9c027389b7c Mon Sep 17 00:00:00 2001 From: DongLieu Date: Tue, 17 Oct 2023 16:28:49 +0700 Subject: [PATCH 4/6] add check closed --- x/interchainstaking/keeper/msg_server_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 069878a3f..4c2786672 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -11,6 +11,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" connectiontypes "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" "github.com/quicksilver-zone/quicksilver/utils/addressutils" icskeeper "github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper" @@ -575,6 +576,11 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { return } suite.NoError(err) + + // check state channel is CLOSED + channel, found := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetChannel(ctx, msg.PortId, msg.ChannelId) + suite.True(found) + suite.True(channel.State == channeltypes.CLOSED) }) } } From 18035dea821131869551a7acdb95fe726031c379 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Thu, 19 Oct 2023 09:56:46 +0100 Subject: [PATCH 5/6] Apply suggestions from code review s/expecErr/expectErr/ --- x/interchainstaking/keeper/msg_server_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 4c2786672..b0b6c9fa3 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -503,7 +503,7 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { testCase := []struct { name string malleate func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel - expecErr error + expectErr error }{ { name: "invalid authority", @@ -514,7 +514,7 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { Authority: testAddress, } }, - expecErr: govtypes.ErrInvalidSigner, + expectErr: govtypes.ErrInvalidSigner, }, { name: "capability not found", @@ -527,7 +527,7 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), } }, - expecErr: capabilitytypes.ErrCapabilityNotFound, + expectErr: capabilitytypes.ErrCapabilityNotFound, }, { name: "invalid connection state", @@ -542,7 +542,7 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), } }, - expecErr: connectiontypes.ErrInvalidConnectionState, + expectErr: connectiontypes.ErrInvalidConnectionState, }, { name: "closes an ICA channel success", @@ -558,7 +558,7 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)), } }, - expecErr: nil, + expectErr: nil, }, } for _, tc := range testCase { @@ -571,8 +571,8 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() { ctx := suite.chainA.GetContext() _, err := msgSrv.GovCloseChannel(ctx, msg) - if tc.expecErr != nil { - suite.ErrorIs(tc.expecErr, err) + if tc.expectErr != nil { + suite.ErrorIs(tc.expectErr, err) return } suite.NoError(err) From ba358fa601e7844c0b3b898545c7a6c475c4ed07 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Thu, 19 Oct 2023 16:23:04 +0700 Subject: [PATCH 6/6] lint --- x/interchainstaking/keeper/msg_server_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index b0b6c9fa3..5a9fe29f7 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -501,8 +501,8 @@ func (suite *KeeperTestSuite) TestSignalIntent() { func (suite *KeeperTestSuite) TestGovCloseChannel() { testCase := []struct { - name string - malleate func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel + name string + malleate func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel expectErr error }{ {