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

chore: remove capabilities methods from testing #7269

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 0 additions & 6 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,11 @@ func (suite *KeeperTestSuite) TestHandleRecvPacket() {
_, err := suite.chainB.App.GetIBCKeeper().RecvPacket(suite.chainB.GetContext(), msg)
suite.Require().NoError(err)

// check that callback state was handled correctly
_, exists := suite.chainB.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainB.GetContext(), ibcmock.GetMockRecvCanaryCapabilityName(packet))
if tc.expRevert {
suite.Require().False(exists, "capability exists in store even after callback reverted")

// context events should contain error events
suite.Require().Contains(events, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0])
suite.Require().NotContains(events, ibcmock.NewMockRecvPacketEvent())
} else {
suite.Require().True(exists, "callback state not persisted when revert is false")

if tc.replay {
// context should not contain application events
suite.Require().NotContains(events, ibcmock.NewMockRecvPacketEvent())
Expand Down
39 changes: 0 additions & 39 deletions testing/mock/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package mock
import (
"bytes"
"context"
"fmt"
"reflect"
"strconv"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -113,14 +111,6 @@ func (im IBCModule) OnRecvPacket(ctx context.Context, channelVersion string, pac
return im.IBCApp.OnRecvPacket(ctx, channelVersion, packet, relayer)
}

// set state by claiming capability to check if revert happens return
capName := GetMockRecvCanaryCapabilityName(packet)
if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil {
// application callback called twice on same packet sequence
// must never occur
panic(err)
}

sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
sdkCtx.EventManager().EmitEvent(NewMockRecvPacketEvent())

Expand All @@ -139,13 +129,6 @@ func (im IBCModule) OnAcknowledgementPacket(ctx context.Context, channelVersion
return im.IBCApp.OnAcknowledgementPacket(ctx, channelVersion, packet, acknowledgement, relayer)
}

capName := GetMockAckCanaryCapabilityName(packet)
if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil {
// application callback called twice on same packet sequence
// must never occur
panic(err)
}

sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
sdkCtx.EventManager().EmitEvent(NewMockAckPacketEvent())

Expand All @@ -158,13 +141,6 @@ func (im IBCModule) OnTimeoutPacket(ctx context.Context, channelVersion string,
return im.IBCApp.OnTimeoutPacket(ctx, channelVersion, packet, relayer)
}

capName := GetMockTimeoutCanaryCapabilityName(packet)
if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil {
// application callback called twice on same packet sequence
// must never occur
panic(err)
}

sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
sdkCtx.EventManager().EmitEvent(NewMockTimeoutPacketEvent())

Expand Down Expand Up @@ -213,18 +189,3 @@ func (IBCModule) UnmarshalPacketData(ctx context.Context, portID string, channel
}
return nil, "", MockApplicationCallbackError
}

// GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality.
func GetMockRecvCanaryCapabilityName(packet channeltypes.Packet) string {
return fmt.Sprintf("%s%s%s%s", MockRecvCanaryCapabilityName, packet.GetDestPort(), packet.GetDestChannel(), strconv.Itoa(int(packet.GetSequence())))
}

// GetMockAckCanaryCapabilityName generates a capability name for OnAcknowledgementPacket functionality.
func GetMockAckCanaryCapabilityName(packet channeltypes.Packet) string {
return fmt.Sprintf("%s%s%s%s", MockAckCanaryCapabilityName, packet.GetSourcePort(), packet.GetSourceChannel(), strconv.Itoa(int(packet.GetSequence())))
}

// GetMockTimeoutCanaryCapabilityName generates a capability name for OnTimeoutacket functionality.
func GetMockTimeoutCanaryCapabilityName(packet channeltypes.Packet) string {
return fmt.Sprintf("%s%s%s%s", MockTimeoutCanaryCapabilityName, packet.GetSourcePort(), packet.GetSourceChannel(), strconv.Itoa(int(packet.GetSequence())))
}
33 changes: 0 additions & 33 deletions testing/mock/ibc_module_test.go

This file was deleted.

22 changes: 0 additions & 22 deletions testing/mock/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ func (im BlockUpgradeMiddleware) OnRecvPacket(ctx context.Context, channelVersio
return im.IBCApp.OnRecvPacket(ctx, channelVersion, packet, relayer)
}

// set state by claiming capability to check if revert happens return
capName := GetMockRecvCanaryCapabilityName(packet)
if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil {
// application callback called twice on same packet sequence
// must never occur
panic(err)
}

if bytes.Equal(MockPacketData, packet.GetData()) {
return MockAcknowledgement
} else if bytes.Equal(MockAsyncPacketData, packet.GetData()) {
Expand All @@ -127,13 +119,6 @@ func (im BlockUpgradeMiddleware) OnAcknowledgementPacket(ctx context.Context, ch
return im.IBCApp.OnAcknowledgementPacket(ctx, channelVersion, packet, acknowledgement, relayer)
}

capName := GetMockAckCanaryCapabilityName(packet)
if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil {
// application callback called twice on same packet sequence
// must never occur
panic(err)
}

return nil
}

Expand All @@ -143,13 +128,6 @@ func (im BlockUpgradeMiddleware) OnTimeoutPacket(ctx context.Context, channelVer
return im.IBCApp.OnTimeoutPacket(ctx, channelVersion, packet, relayer)
}

capName := GetMockTimeoutCanaryCapabilityName(packet)
if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil {
// application callback called twice on same packet sequence
// must never occur
panic(err)
}

return nil
}

Expand Down
Loading