Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check active channel is correct #324

Merged
merged 2 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe in tc.expPass this should be expected Channel and in the else it should be an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, this was on auto-merge :D

Copy link
Contributor Author

@seantking seantking Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, your suggestion prob reduces the need to copy pasta expectedChannel = "" in the malleate functions. I'll add it into another PR for the relay tests.


if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}

})
}
}
Expand Down