Skip to content

Commit

Permalink
add failing test case for NegotiateAppVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Nov 5, 2021
1 parent e22684b commit 62dd3d3
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions modules/apps/27-interchain-accounts/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
} else {
suite.Require().Error(err)
}

})
}

}

func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
Expand Down Expand Up @@ -483,26 +481,59 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
}

func (suite *InterchainAccountsTestSuite) TestNegotiateAppVersion() {
suite.SetupTest()
path := NewICAPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)
var (
proposedVersion string
)
testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success", func() {}, true,
},
{
"invalid proposed version", func() {
proposedVersion = "invalid version"
}, false,
},
}

module, _, err := suite.chainA.GetSimApp().GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), types.PortID)
suite.Require().NoError(err)
for _, tc := range testCases {
tc := tc

cbs, ok := suite.chainA.GetSimApp().GetIBCKeeper().Router.GetRoute(module)
suite.Require().True(ok)
suite.Run(tc.name, func() {
suite.SetupTest()
path := NewICAPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)

counterpartyPortID, err := types.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
suite.Require().NoError(err)
module, _, err := suite.chainA.GetSimApp().GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), types.PortID)
suite.Require().NoError(err)

counterparty := &channeltypes.Counterparty{
PortId: counterpartyPortID,
ChannelId: path.EndpointB.ChannelID,
}
cbs, ok := suite.chainA.GetSimApp().GetIBCKeeper().Router.GetRoute(module)
suite.Require().True(ok)

counterpartyPortID, err := types.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
suite.Require().NoError(err)

counterparty := &channeltypes.Counterparty{
PortId: counterpartyPortID,
ChannelId: path.EndpointB.ChannelID,
}

proposedVersion = types.VersionPrefix

version, err := cbs.NegotiateAppVersion(suite.chainA.GetContext(), channeltypes.ORDERED, path.EndpointA.ConnectionID, types.PortID, *counterparty, types.VersionPrefix)
suite.Require().NoError(err)
suite.Require().NoError(types.ValidateVersion(version))
suite.Require().Equal(TestVersion, version)
tc.malleate()

version, err := cbs.NegotiateAppVersion(suite.chainA.GetContext(), channeltypes.ORDERED, path.EndpointA.ConnectionID, types.PortID, *counterparty, proposedVersion)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NoError(types.ValidateVersion(version))
suite.Require().Equal(TestVersion, version)
} else {
suite.Require().Error(err)
suite.Require().Empty(version)
}
})
}
}

0 comments on commit 62dd3d3

Please sign in to comment.