From b4d82a261ab6f61f1ce298ba1de0db2a2c7eeb43 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 13 Aug 2021 12:08:16 +0200 Subject: [PATCH] test: check active channel is correct (#324) * test: check active channel is correct * test: adding version string check --- .../27-interchain-accounts/keeper/handshake.go | 4 ++++ .../keeper/handshake_test.go | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/keeper/handshake.go b/modules/apps/27-interchain-accounts/keeper/handshake.go index 647ef2e7d55..c226b226ba9 100644 --- a/modules/apps/27-interchain-accounts/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/keeper/handshake.go @@ -95,6 +95,10 @@ func (k Keeper) OnChanOpenAck( channelID string, counterpartyVersion string, ) error { + if counterpartyVersion != types.Version { + return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) + } + k.SetActiveChannel(ctx, portID, channelID) return nil diff --git a/modules/apps/27-interchain-accounts/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/keeper/handshake_test.go index 253aff5f5d9..279cc2109e2 100644 --- a/modules/apps/27-interchain-accounts/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/keeper/handshake_test.go @@ -185,6 +185,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { func (suite *KeeperTestSuite) TestOnChanOpenAck() { var ( path *ibctesting.Path + expectedChannel string counterpartyVersion string ) @@ -193,10 +194,15 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() { malleate func() expPass bool }{ - { "success", func() {}, true, }, + { + "invalid counterparty version", func() { + expectedChannel = "" + counterpartyVersion = "version" + }, false, + }, } for _, tc := range testCases { @@ -214,6 +220,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) + expectedChannel = path.EndpointA.ChannelID tc.malleate() // explicitly change fields in channel and testChannel @@ -221,12 +228,15 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterpartyVersion, ) + activeChannel, _ := suite.chainA.GetSimApp().ICAKeeper.GetActiveChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + + suite.Require().Equal(activeChannel, expectedChannel) + if tc.expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) } - }) } }