Skip to content

Commit

Permalink
test: check active channel is correct (#324)
Browse files Browse the repository at this point in the history
* test: check active channel is correct

* test: adding version string check
  • Loading branch information
seantking committed Aug 13, 2021
1 parent 9d3f02c commit b4d82a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions modules/apps/27-interchain-accounts/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
func (suite *KeeperTestSuite) TestOnChanOpenAck() {
var (
path *ibctesting.Path
expectedChannel string
counterpartyVersion string
)

Expand All @@ -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 {
Expand All @@ -214,19 +220,23 @@ 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

err = suite.chainA.GetSimApp().ICAKeeper.OnChanOpenAck(suite.chainA.GetContext(),
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)
}

})
}
}
Expand Down

0 comments on commit b4d82a2

Please sign in to comment.