Skip to content

Commit

Permalink
Test for GovReopenChannel (#725)
Browse files Browse the repository at this point in the history
* Test for GovReopenChannel

* add assert for case pass

---------

Co-authored-by: Joe Bowman <[email protected]>
  • Loading branch information
DongLieu and Joe Bowman authored Oct 26, 2023
1 parent 0af6442 commit 64173b8
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions x/interchainstaking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"errors"
"fmt"
"time"

Expand All @@ -10,8 +11,10 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/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"
tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types"

"github.com/quicksilver-zone/quicksilver/utils/addressutils"
icskeeper "github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper"
Expand Down Expand Up @@ -584,3 +587,106 @@ func (suite *KeeperTestSuite) TestGovCloseChannel() {
})
}
}

func (suite *KeeperTestSuite) TestGovReopenChannel() {
testCase := []struct {
name string
malleate func(suite *KeeperTestSuite) *icstypes.MsgGovReopenChannel
expecErr error
}{
{
name: "invalid connection id",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovReopenChannel {
return &icstypes.MsgGovReopenChannel{
ConnectionId: "",
PortId: "",
Authority: "",
}
},
expecErr: fmt.Errorf("unable to obtain chain id: invalid connection id, \"%s\" not found", ""),
},
{
name: "chainID / connectsionID mismatch",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovReopenChannel {
return &icstypes.MsgGovReopenChannel{
ConnectionId: suite.path.EndpointA.ConnectionID,
PortId: "",
Authority: "",
}
},
expecErr: fmt.Errorf("chainID / connectionID mismatch. Connection: %s, Port: %s", "testchain2", ""),
},
{
name: "existing active channel",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovReopenChannel {
k := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper
ctx := suite.chainA.GetContext()
channels := suite.GetQuicksilverApp(suite.chainA).IBCKeeper.ChannelKeeper.GetAllChannels(ctx)
return &icstypes.MsgGovReopenChannel{
ConnectionId: suite.path.EndpointA.ConnectionID,
PortId: channels[0].PortId,
Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), k.AccountKeeper.GetModuleAddress(govtypes.ModuleName)),
}
},
expecErr: errors.New("existing active channel channel-7 for portID icacontroller-testchain2.delegate on connection connection-0 for owner testchain2.delegate: active channel already set for this owner"),
},
{
name: "pass",
malleate: func(suite *KeeperTestSuite) *icstypes.MsgGovReopenChannel {
quicksilver := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()
connectionID := "connection-1"
portID := "icacontroller-testchain2.delegate"
channelID := "channel-9"

version := []*connectiontypes.Version{
{Identifier: "1", Features: []string{"ORDER_ORDERED", "ORDER_UNORDERED"}},
}
connectionEnd := connectiontypes.ConnectionEnd{ClientId: "09-tendermint-1", State: connectiontypes.OPEN, Versions: version}
quicksilver.IBCKeeper.ConnectionKeeper.SetConnection(ctx, connectionID, connectionEnd)

_, f := quicksilver.IBCKeeper.ConnectionKeeper.GetConnection(ctx, connectionID)
suite.True(f)

channelSet := channeltypes.Channel{
State: channeltypes.TRYOPEN,
Ordering: channeltypes.NONE,
Counterparty: channeltypes.NewCounterparty(portID, channelID),
ConnectionHops: []string{connectionID},
}
quicksilver.IBCKeeper.ChannelKeeper.SetChannel(ctx, portID, channelID, channelSet)

quicksilver.IBCKeeper.ClientKeeper.SetClientState(ctx, connectionEnd.ClientId, &tmclienttypes.ClientState{ChainId: suite.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}})

return &icstypes.MsgGovReopenChannel{
ConnectionId: connectionID,
PortId: portID,
Authority: sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), quicksilver.InterchainstakingKeeper.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.GovReopenChannel(ctx, msg)
if tc.expecErr != nil {
suite.Equal(tc.expecErr.Error(), err.Error())
return
}
suite.NoError(err)

// Check connection for port has been set
conn, err := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetConnectionForPort(ctx, msg.PortId)
suite.NoError(err)
suite.Equal(conn, msg.ConnectionId)
})
}
}

0 comments on commit 64173b8

Please sign in to comment.