Skip to content

Commit

Permalink
Pass appVersion to callback if version can be parsed. (#5468)
Browse files Browse the repository at this point in the history
* Pass appVersion to callback if version can be parsed.

* Assert on rest of values passed.
  • Loading branch information
DimitrisJim authored Dec 20, 2023
1 parent 2ef99d1 commit 5bad8f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
5 changes: 2 additions & 3 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID str
panic(errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack"))
}

// discard the version metadata returned as upgrade fields have already been validated in previous handshake steps.
_, err := types.MetadataFromVersion(version)
versionMetadata, err := types.MetadataFromVersion(version)
if err != nil {
// set fee disabled and passthrough to the next middleware or application in callstack.
im.keeper.DeleteFeeEnabled(ctx, portID, channelID)
Expand All @@ -438,7 +437,7 @@ func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID str

// set fee enabled and passthrough to the next middleware of application in callstack.
im.keeper.SetFeeEnabled(ctx, portID, channelID)
cbs.OnChanUpgradeOpen(ctx, portID, channelID, order, connectionHops, version)
cbs.OnChanUpgradeOpen(ctx, portID, channelID, order, connectionHops, versionMetadata.AppVersion)
}

// OnChanUpgradeRestore implements the IBCModule interface
Expand Down
27 changes: 23 additions & 4 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,16 @@ func (suite *FeeTestSuite) TestOnChanUpgradeOpen() {
}{
{
"success: enable fees",
func() {},
func() {
// Assert in callback that correct upgrade information is passed
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeOpen = func(_ sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) {
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, portID)
suite.Require().Equal(path.EndpointA.ChannelID, channelID)
suite.Require().Equal(channeltypes.UNORDERED, order)
suite.Require().Equal([]string{path.EndpointA.ConnectionID}, connectionHops)
suite.Require().Equal(ibcmock.Version, version)
}
},
true,
},
{
Expand All @@ -1353,17 +1362,27 @@ func (suite *FeeTestSuite) TestOnChanUpgradeOpen() {
// create a new path using a fee enabled channel and downgrade it to disable fees
path = ibctesting.NewPath(suite.chainA, suite.chainB)

mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version}))
mockFeeVersion := &types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version}
mockFeeVersionBz := string(types.ModuleCdc.MustMarshalJSON(mockFeeVersion))
path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort
path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort
path.EndpointA.ChannelConfig.Version = mockFeeVersion
path.EndpointB.ChannelConfig.Version = mockFeeVersion
path.EndpointA.ChannelConfig.Version = mockFeeVersionBz
path.EndpointB.ChannelConfig.Version = mockFeeVersionBz

upgradeVersion := ibcmock.Version
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion

suite.coordinator.Setup(path)

// Assert in callback that correct version is passed
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeOpen = func(_ sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) {
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, portID)
suite.Require().Equal(path.EndpointA.ChannelID, channelID)
suite.Require().Equal(channeltypes.UNORDERED, order)
suite.Require().Equal([]string{path.EndpointA.ConnectionID}, connectionHops)
suite.Require().Equal(mockFeeVersion.AppVersion, version)
}
},
false,
},
Expand Down

0 comments on commit 5bad8f2

Please sign in to comment.