Skip to content

Commit 83c3e41

Browse files
authored
test: adding ica test for multiple controllers, single host (#816)
* adding test for multiple controllers, single host * updating inline comments * updating todos with correct ports * reorder to use pathCToB.Endpoint for connection IDs
1 parent 8cba0eb commit 83c3e41

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

modules/apps/27-interchain-accounts/controller/ibc_module_test.go

+69-1
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ type InterchainAccountsTestSuite struct {
4646
// testing chains used for convenience and readability
4747
chainA *ibctesting.TestChain
4848
chainB *ibctesting.TestChain
49+
chainC *ibctesting.TestChain
4950
}
5051

5152
func TestICATestSuite(t *testing.T) {
5253
suite.Run(t, new(InterchainAccountsTestSuite))
5354
}
5455

5556
func (suite *InterchainAccountsTestSuite) SetupTest() {
56-
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
57+
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3)
5758
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
5859
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))
60+
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3))
5961
}
6062

6163
func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
@@ -89,6 +91,7 @@ func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) erro
8991
// update port/channel ids
9092
endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence)
9193
endpoint.ChannelConfig.PortID = portID
94+
endpoint.ChannelConfig.Version = TestVersion
9295

9396
return nil
9497
}
@@ -632,3 +635,68 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
632635
})
633636
}
634637
}
638+
639+
func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() {
640+
var (
641+
pathAToB *ibctesting.Path
642+
pathCToB *ibctesting.Path
643+
)
644+
645+
testCases := []struct {
646+
msg string
647+
malleate func()
648+
expPass bool
649+
}{
650+
{
651+
"success",
652+
func() {},
653+
true,
654+
},
655+
}
656+
657+
for _, tc := range testCases {
658+
suite.Run(tc.msg, func() {
659+
suite.SetupTest() // reset
660+
661+
// Setup a new path from A(controller) -> B(host)
662+
pathAToB = NewICAPath(suite.chainA, suite.chainB)
663+
suite.coordinator.SetupConnections(pathAToB)
664+
665+
err := SetupICAPath(pathAToB, TestOwnerAddress)
666+
suite.Require().NoError(err)
667+
668+
// Setup a new path from C(controller) -> B(host)
669+
pathCToB = NewICAPath(suite.chainC, suite.chainB)
670+
suite.coordinator.SetupConnections(pathCToB)
671+
672+
// NOTE: Here the version metadata is overridden to include to the next host connection sequence (i.e. chainB's connection to chainC)
673+
// SetupICAPath() will set endpoint.ChannelConfig.Version to TestVersion
674+
TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{
675+
Version: icatypes.Version,
676+
ControllerConnectionId: pathCToB.EndpointA.ConnectionID,
677+
HostConnectionId: pathCToB.EndpointB.ConnectionID,
678+
}))
679+
680+
err = SetupICAPath(pathCToB, TestOwnerAddress)
681+
suite.Require().NoError(err)
682+
683+
tc.malleate() // malleate mutates test data
684+
685+
accAddressChainA, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), pathAToB.EndpointB.ConnectionID, pathAToB.EndpointA.ChannelConfig.PortID)
686+
suite.Require().True(found)
687+
688+
accAddressChainC, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), pathCToB.EndpointB.ConnectionID, pathCToB.EndpointA.ChannelConfig.PortID)
689+
suite.Require().True(found)
690+
691+
suite.Require().NotEqual(accAddressChainA, accAddressChainC)
692+
693+
chainAChannelID, found := suite.chainB.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainB.GetContext(), pathAToB.EndpointB.ConnectionID, pathAToB.EndpointA.ChannelConfig.PortID)
694+
suite.Require().True(found)
695+
696+
chainCChannelID, found := suite.chainB.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainB.GetContext(), pathCToB.EndpointB.ConnectionID, pathCToB.EndpointA.ChannelConfig.PortID)
697+
suite.Require().True(found)
698+
699+
suite.Require().NotEqual(chainAChannelID, chainCChannelID)
700+
})
701+
}
702+
}

0 commit comments

Comments
 (0)