Skip to content

Commit

Permalink
adding default version for ics29
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed Apr 29, 2022
1 parent 092d3fe commit d30f887
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
23 changes: 17 additions & 6 deletions modules/apps/29-fee/ibc_module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fee

import (
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -38,12 +40,21 @@ func (im IBCModule) OnChanOpenInit(
version string,
) (string, error) {
var versionMetadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(version), &versionMetadata); err != nil {
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
// application.
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID,
chanCap, counterparty, version)

if strings.TrimSpace(version) == "" {
// default version
versionMetadata = types.Metadata{
FeeVersion: types.Version,
AppVersion: "",
}
} else {
if err := types.ModuleCdc.UnmarshalJSON([]byte(version), &versionMetadata); err != nil {
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
// application.
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID,
chanCap, counterparty, version)
}
}

if versionMetadata.FeeVersion != types.Version {
Expand Down
10 changes: 7 additions & 3 deletions modules/apps/29-fee/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {
types.Version,
false,
},
{
"passing an empty string returns default version",
"",
true,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -99,7 +104,6 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {
suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, channel.Version)

if tc.expPass {

// check if the channel is fee enabled. If so version string should include metaData
isFeeEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
if isFeeEnabled {
Expand All @@ -113,13 +117,13 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {

suite.Require().Equal(version, string(versionBytes))
} else {
suite.Require().Equal(version, ibcmock.Version)
suite.Require().Equal(ibcmock.Version, version)
}

suite.Require().NoError(err, "unexpected error from version: %s", tc.version)
} else {
suite.Require().Error(err, "error not returned for version: %s", tc.version)
suite.Require().Equal(version, "")
suite.Require().Equal("", version)
}
})
}
Expand Down
5 changes: 5 additions & 0 deletions testing/mock/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"strconv"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -33,6 +34,10 @@ func (im IBCModule) OnChanOpenInit(
ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string,
channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string,
) (string, error) {
if strings.TrimSpace(version) == "" {
version = Version
}

if im.IBCApp.OnChanOpenInit != nil {
return im.IBCApp.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version)
}
Expand Down

0 comments on commit d30f887

Please sign in to comment.