Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for msgSV.GovCloseChannel #695

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions x/interchainstaking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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"
Expand Down Expand Up @@ -493,3 +497,84 @@ func (suite *KeeperTestSuite) TestSignalIntent() {
})
}
}

func (suite *KeeperTestSuite) TestGovCloseChannel() {
testCase := []struct {
name string
malleate func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel
expecErr error
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
}{
{
name: "invalid authority",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel {
return &icstypes.MsgGovCloseChannel{
ChannelId: "",
PortId: "",
Authority: testAddress,
}
},
expecErr: govtypes.ErrInvalidSigner,
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
},
{
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,
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "invalid connection state",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel {
ctx := suite.chainA.GetContext()
k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper
channels := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx)

return &icstypes.MsgGovCloseChannel{
ChannelId: channels[0].ChannelId,
PortId: channels[0].PortId,
Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)),
}
},
expecErr: connectiontypes.ErrInvalidConnectionState,
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
},
{
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
channels := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx)

return &icstypes.MsgGovCloseChannel{
ChannelId: channels[0].ChannelId,
PortId: channels[0].PortId,
Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)),
}
},
expecErr: nil,
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
},
}
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 {
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
suite.ErrorIs(tc.expecErr, err)
joe-bowman marked this conversation as resolved.
Show resolved Hide resolved
return
}
suite.NoError(err)
})
}
}