Skip to content

Commit

Permalink
Merge branch 'main' into minh/get-active-validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman authored Oct 23, 2023
2 parents 21f5271 + 1ed5da2 commit d72c8f3
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 1 deletion.
197 changes: 197 additions & 0 deletions x/interchainstaking/keeper/callbacks_test.go

Large diffs are not rendered by default.

91 changes: 91 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,11 @@ 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"
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"
Expand Down Expand Up @@ -493,3 +498,89 @@ func (suite *KeeperTestSuite) TestSignalIntent() {
})
}
}

func (suite *KeeperTestSuite) TestGovCloseChannel() {
testCase := []struct {
name string
malleate func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel
expectErr error
}{
{
name: "invalid authority",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovCloseChannel {
return &icstypes.MsgGovCloseChannel{
ChannelId: "",
PortId: "",
Authority: testAddress,
}
},
expectErr: 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)),
}
},
expectErr: capabilitytypes.ErrCapabilityNotFound,
},
{
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)),
}
},
expectErr: 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
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)),
}
},
expectErr: 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.expectErr != nil {
suite.ErrorIs(tc.expectErr, err)
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)
})
}
}
2 changes: 1 addition & 1 deletion x/interchainstaking/types/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (a *ICAAccount) IncrementBalanceWaitgroup() {
}

func (a *ICAAccount) DecrementBalanceWaitgroup() error {
if a.BalanceWaitgroup <= 0 {
if a.BalanceWaitgroup == 0 {
return errors.New("unable to decrement the balance waitgroup below 0")
}
a.BalanceWaitgroup--
Expand Down

0 comments on commit d72c8f3

Please sign in to comment.