From d30f887090049e4ae6493632332afe6ae18f8526 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 29 Apr 2022 18:41:56 +0200 Subject: [PATCH] adding default version for ics29 --- modules/apps/29-fee/ibc_module.go | 23 +++++++++++++++++------ modules/apps/29-fee/ibc_module_test.go | 10 +++++++--- testing/mock/ibc_module.go | 5 +++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index 0767d310b41..00ea19b56f5 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -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" @@ -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 { diff --git a/modules/apps/29-fee/ibc_module_test.go b/modules/apps/29-fee/ibc_module_test.go index 0bfb8a6b458..025c765e42c 100644 --- a/modules/apps/29-fee/ibc_module_test.go +++ b/modules/apps/29-fee/ibc_module_test.go @@ -54,6 +54,11 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() { types.Version, false, }, + { + "passing an empty string returns default version", + "", + true, + }, } for _, tc := range testCases { @@ -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 { @@ -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) } }) } diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 4c492872da0..69f3c388a8a 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -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" @@ -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) }