Skip to content

Commit

Permalink
update tests --> msgserver
Browse files Browse the repository at this point in the history
  • Loading branch information
charleenfei committed Dec 12, 2023
1 parent b653ffd commit cf83651
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
39 changes: 1 addition & 38 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,32 +1218,6 @@ func (suite *KeeperTestSuite) TestChanUpgradeCancel() {
},
expError: nil,
},
{
name: "sender is authority, upgrade can be cancelled in FLUSHING state even with invalid error receipt upgrade sequence",
malleate: func() {
isAuthority = true

channel := path.EndpointA.GetChannel()
channel.State = types.FLUSHING
path.EndpointA.SetChannel(channel)

var ok bool
errorReceipt, ok = suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.GetUpgradeErrorReceipt(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
suite.Require().True(ok)

errorReceipt.Sequence = path.EndpointA.GetChannel().UpgradeSequence - 1

suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.SetUpgradeErrorReceipt(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, errorReceipt)

suite.coordinator.CommitBlock(suite.chainB)

suite.Require().NoError(path.EndpointA.UpdateClient())

upgradeErrorReceiptKey := host.ChannelUpgradeErrorKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
errorReceiptProof, proofHeight = suite.chainB.QueryProof(upgradeErrorReceiptKey)
},
expError: nil,
},
{
name: "sender is authority, upgrade cannot be cancelled in FLUSHCOMPLETE with invalid error receipt",
malleate: func() {
Expand All @@ -1253,7 +1227,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeCancel() {
expError: commitmenttypes.ErrInvalidProof,
},
{
name: "sender is authority, upgrade cannot be cancalled in FLUSHCOMPLETE with error receipt sequence less than channel upgrade sequence",
name: "sender is authority, upgrade cannot be cancelled in FLUSHCOMPLETE with error receipt sequence less than channel upgrade sequence",
malleate: func() {
isAuthority = true

Expand Down Expand Up @@ -1353,17 +1327,6 @@ func (suite *KeeperTestSuite) TestChanUpgradeCancel() {
},
expError: commitmenttypes.ErrInvalidProof,
},
{
name: "sender is authority, channel is flushing, cancel succeeds with empty proof",
malleate: func() {
isAuthority = true
errorReceiptProof = nil
channel := path.EndpointA.GetChannel()
channel.State = types.FLUSHING
path.EndpointA.SetChannel(channel)
},
expError: nil,
},
}

for _, tc := range tests {
Expand Down
14 changes: 6 additions & 8 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,13 +1047,6 @@ func (k Keeper) ChannelUpgradeTimeout(goCtx context.Context, msg *channeltypes.M
// ChannelUpgradeCancel defines a rpc handler method for MsgChannelUpgradeCancel.
func (k Keeper) ChannelUpgradeCancel(goCtx context.Context, msg *channeltypes.MsgChannelUpgradeCancel) (*channeltypes.MsgChannelUpgradeCancelResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

cbs, ok := app.(porttypes.UpgradableModule)
if !ok {
ctx.Logger().Error("channel upgrade cancel failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module))
return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)
}

module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId)
if err != nil {
ctx.Logger().Error("channel upgrade cancel failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
Expand All @@ -1066,6 +1059,12 @@ func (k Keeper) ChannelUpgradeCancel(goCtx context.Context, msg *channeltypes.Ms
return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)
}

cbs, ok := app.(porttypes.UpgradableModule)
if !ok {
ctx.Logger().Error("channel upgrade cancel failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module))
return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)
}

channel, found := k.ChannelKeeper.GetChannel(ctx, msg.PortId, msg.ChannelId)
if !found {
return nil, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", msg.PortId, msg.ChannelId)
Expand All @@ -1082,7 +1081,6 @@ func (k Keeper) ChannelUpgradeCancel(goCtx context.Context, msg *channeltypes.Ms
ctx.Logger().Info("channel upgrade cancel succeeded", "port-id", msg.PortId, "channel-id", msg.ChannelId)

return &channeltypes.MsgChannelUpgradeCancelResponse{}, nil

}

if err := k.ChannelKeeper.ChanUpgradeCancel(ctx, msg.PortId, msg.ChannelId, msg.ErrorReceipt, msg.ProofErrorReceipt, msg.ProofHeight, isAuthority); err != nil {
Expand Down
44 changes: 44 additions & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,50 @@ func (suite *KeeperTestSuite) TestChannelUpgradeCancel() {
suite.Require().Equal(uint64(3), channel.UpgradeSequence)
},
},
{
"success: keeper is authority & channel state in FLUSHING, can be cancelled even with invalid error receipt",
func() {
msg.Signer = suite.chainA.App.GetIBCKeeper().GetAuthority()
msg.ProofErrorReceipt = []byte("invalid proof")

channel := path.EndpointA.GetChannel()
channel.State = channeltypes.FLUSHING
channel.UpgradeSequence = uint64(1)
path.EndpointA.SetChannel(channel)
},
func(res *channeltypes.MsgChannelUpgradeCancelResponse, err error) {
suite.Require().NoError(err)
suite.Require().NotNil(res)

channel := path.EndpointA.GetChannel()
// Channel state should be reverted back to open.
suite.Require().Equal(channeltypes.OPEN, channel.State)
// Upgrade sequence should be changed to match initial upgrade sequence.
suite.Require().Equal(uint64(1), channel.UpgradeSequence)
},
},
{
"success: keeper is authority & channel state in FLUSHING, can be cancelled even with empty error receipt",
func() {
msg.Signer = suite.chainA.App.GetIBCKeeper().GetAuthority()
msg.ProofErrorReceipt = nil

channel := path.EndpointA.GetChannel()
channel.State = channeltypes.FLUSHING
channel.UpgradeSequence = uint64(1)
path.EndpointA.SetChannel(channel)
},
func(res *channeltypes.MsgChannelUpgradeCancelResponse, err error) {
suite.Require().NoError(err)
suite.Require().NotNil(res)

channel := path.EndpointA.GetChannel()
// Channel state should be reverted back to open.
suite.Require().Equal(channeltypes.OPEN, channel.State)
// Upgrade sequence should be changed to match initial upgrade sequence.
suite.Require().Equal(uint64(1), channel.UpgradeSequence)
},
},
{
"capability not found",
func() {
Expand Down

0 comments on commit cf83651

Please sign in to comment.