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: adding ica test for multiple controllers, single host #816

Merged
merged 7 commits into from
Feb 2, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
Expand Down Expand Up @@ -46,16 +47,18 @@ type InterchainAccountsTestSuite struct {
// testing chains used for convenience and readability
chainA *ibctesting.TestChain
chainB *ibctesting.TestChain
chainC *ibctesting.TestChain
}

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

func (suite *InterchainAccountsTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3))
}

func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
Expand Down Expand Up @@ -89,6 +92,7 @@ func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) erro
// update port/channel ids
endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence)
endpoint.ChannelConfig.PortID = portID
endpoint.ChannelConfig.Version = TestVersion

return nil
}
Expand Down Expand Up @@ -632,3 +636,67 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {
})
}
}

func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() {
var (
pathAToB *ibctesting.Path
pathCToB *ibctesting.Path
)

testCases := []struct {
msg string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
}

for _, tc := range testCases {
suite.Run(tc.msg, func() {
suite.SetupTest() // reset

// Setup a new path from A(controller) -> B(host)
pathAToB = NewICAPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(pathAToB)

err := SetupICAPath(pathAToB, TestOwnerAddress)
suite.Require().NoError(err)

// Setup a new path from C(controller) -> B(host)
// NOTE: Here the version metadata is overridden to include to the next host connection sequence (i.e. chainB's connection to chainC)
nextConnectionSeq := suite.chainB.App.GetIBCKeeper().ConnectionKeeper.GetNextConnectionSequence(suite.chainB.GetContext())
TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{
Version: icatypes.Version,
ControllerConnectionId: ibctesting.FirstConnectionID,
HostConnectionId: connectiontypes.FormatConnectionIdentifier(nextConnectionSeq),
}))
pathCToB = NewICAPath(suite.chainC, suite.chainB)
suite.coordinator.SetupConnections(pathCToB)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

err = SetupICAPath(pathCToB, TestOwnerAddress)
suite.Require().NoError(err)

tc.malleate() // malleate mutates test data

accAddressChainA, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), pathAToB.EndpointB.ConnectionID, pathAToB.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

accAddressChainC, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), pathCToB.EndpointB.ConnectionID, pathCToB.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

suite.Require().NotEqual(accAddressChainA, accAddressChainC)

chainAChannelID, found := suite.chainB.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainB.GetContext(), pathAToB.EndpointB.ConnectionID, pathAToB.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

chainCChannelID, found := suite.chainB.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainB.GetContext(), pathCToB.EndpointB.ConnectionID, pathCToB.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

suite.Require().NotEqual(chainAChannelID, chainCChannelID)
})
}
}