Skip to content

Commit

Permalink
adding testing app overrides for upgrade handshake app callback handl…
Browse files Browse the repository at this point in the history
…ers (#3812)
  • Loading branch information
damiannolan authored Jun 12, 2023
1 parent e6c224c commit 05416ee
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
36 changes: 36 additions & 0 deletions testing/mock/ibc_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,42 @@ type IBCApp struct {
packet channeltypes.Packet,
relayer sdk.AccAddress,
) error

OnChanUpgradeInit func(
ctx sdk.Context,
portID, channelID string,
order channeltypes.Order,
connectionHops []string,
sequence uint64,
version, previousVersion string,
) (string, error)

OnChanUpgradeTry func(
ctx sdk.Context,
portID, channelID string,
order channeltypes.Order,
connectionHops []string,
counterpartyVersion string,
) (string, error)

OnChanUpgradeAck func(
ctx sdk.Context,
portID,
channelID,
counterpartyVersion string,
) error

OnChanUpgradeOpen func(
ctx sdk.Context,
portID,
channelID string,
) error

OnChanUpgradeRestore func(
ctx sdk.Context,
portID,
channelID string,
) error
}

// NewIBCApp returns a IBCApp. An empty PortID indicates the mock app doesn't bind/claim ports.
Expand Down
20 changes: 20 additions & 0 deletions testing/mock/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,46 @@ func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet,

// OnChanUpgradeInit implements the IBCModule interface
func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, sequence uint64, version, previousVersion string) (string, error) {
if im.IBCApp.OnChanUpgradeInit != nil {
return im.IBCApp.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, sequence, version, previousVersion)
}

return version, nil
}

// OnChanUpgradeTry implements the IBCModule interface
func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, counterpartyVersion string) (string, error) {
if im.IBCApp.OnChanUpgradeTry != nil {
return im.IBCApp.OnChanUpgradeTry(ctx, portID, channelID, order, connectionHops, counterpartyVersion)
}

return counterpartyVersion, nil
}

// OnChanUpgradeAck implements the IBCModule interface
func (im IBCModule) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error {
if im.IBCApp.OnChanUpgradeAck != nil {
return im.IBCApp.OnChanUpgradeAck(ctx, portID, channelID, counterpartyVersion)
}

return nil
}

// OnChanUpgradeOpen implements the IBCModule interface
func (im IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string) error {
if im.IBCApp.OnChanUpgradeOpen != nil {
return im.IBCApp.OnChanUpgradeOpen(ctx, portID, channelID)
}

return nil
}

// OnChanUpgradeRestore implements the IBCModule interface
func (im IBCModule) OnChanUpgradeRestore(ctx sdk.Context, portID, channelID string) error {
if im.IBCApp.OnChanUpgradeRestore != nil {
return im.IBCApp.OnChanUpgradeRestore(ctx, portID, channelID)
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ type SimApp struct {

// make IBC modules public for test purposes
// these modules are never directly routed to by the IBC Router
IBCMockModule ibcmock.IBCModule
ICAAuthModule ibcmock.IBCModule
FeeMockModule ibcmock.IBCModule

Expand Down Expand Up @@ -455,6 +456,7 @@ func NewSimApp(

// The mock module is used for testing IBC
mockIBCModule := ibcmock.NewIBCModule(&mockModule, ibcmock.NewIBCApp(ibcmock.ModuleName, scopedIBCMockKeeper))
app.IBCMockModule = mockIBCModule
ibcRouter.AddRoute(ibcmock.ModuleName, mockIBCModule)

// Create Transfer Stack
Expand Down

0 comments on commit 05416ee

Please sign in to comment.