Skip to content

Commit

Permalink
test both ORDERED and UNORDERED channels in most (probably all) tests…
Browse files Browse the repository at this point in the history
… involving something with ICA
  • Loading branch information
crodriguezvega committed Jun 5, 2024
1 parent 5a7d723 commit bbba1e5
Show file tree
Hide file tree
Showing 16 changed files with 2,683 additions and 2,529 deletions.
1,159 changes: 598 additions & 561 deletions modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go

Large diffs are not rendered by default.

195 changes: 100 additions & 95 deletions modules/apps/27-interchain-accounts/controller/keeper/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,113 +8,118 @@ import (
)

func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
var (
owner string
path *ibctesting.Path
err error
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success", func() {}, true,
},
{
"port is already bound for owner but capability is claimed by another module",
func() {
capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID))
suite.Require().NoError(err)
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
var (
owner string
path *ibctesting.Path
err error
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success", func() {}, true,
},
false,
},
{
"fails to generate port-id",
func() {
owner = ""
{
"port is already bound for owner but capability is claimed by another module",
func() {
capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID))
suite.Require().NoError(err)
},
false,
},
false,
},
{
"MsgChanOpenInit fails - channel is already active & in state OPEN",
func() {
portID, err := icatypes.NewControllerPortID(TestOwnerAddress)
suite.Require().NoError(err)

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
channel := channeltypes.Channel{
State: channeltypes.OPEN,
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: TestVersion,
}
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel)
{
"fails to generate port-id",
func() {
owner = ""
},
false,
},
false,
},
}
for _, tc := range testCases {
tc := tc
{
"MsgChanOpenInit fails - channel is already active & in state OPEN",
func() {
portID, err := icatypes.NewControllerPortID(TestOwnerAddress)
suite.Require().NoError(err)

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
channel := channeltypes.Channel{
State: channeltypes.OPEN,
Ordering: ordering,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: TestVersion,
}
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel)
},
false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest()
suite.Run(tc.name, func() {
suite.SetupTest()

owner = TestOwnerAddress // must be explicitly changed
owner = TestOwnerAddress // must be explicitly changed

path = NewICAPath(suite.chainA, suite.chainB)
path.SetupConnections()
path = NewICAPath(suite.chainA, suite.chainB, ordering)
path.SetupConnections()

tc.malleate() // malleate mutates test data
tc.malleate() // malleate mutates test data

err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), path.EndpointA.ConnectionID, owner, TestVersion, channeltypes.ORDERED)
err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), path.EndpointA.ConnectionID, owner, TestVersion, ordering)

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

func (suite *KeeperTestSuite) TestRegisterSameOwnerMultipleConnections() {
suite.SetupTest()

owner := TestOwnerAddress

pathAToB := NewICAPath(suite.chainA, suite.chainB)
pathAToB.SetupConnections()

pathAToC := NewICAPath(suite.chainA, suite.chainC)
pathAToC.SetupConnections()

// build ICS27 metadata with connection identifiers for path A->B
metadata := &icatypes.Metadata{
Version: icatypes.Version,
ControllerConnectionId: pathAToB.EndpointA.ConnectionID,
HostConnectionId: pathAToB.EndpointB.ConnectionID,
Encoding: icatypes.EncodingProtobuf,
TxType: icatypes.TxTypeSDKMultiMsg,
}

err := suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToB.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), channeltypes.ORDERED)
suite.Require().NoError(err)

// build ICS27 metadata with connection identifiers for path A->C
metadata = &icatypes.Metadata{
Version: icatypes.Version,
ControllerConnectionId: pathAToC.EndpointA.ConnectionID,
HostConnectionId: pathAToC.EndpointB.ConnectionID,
Encoding: icatypes.EncodingProtobuf,
TxType: icatypes.TxTypeSDKMultiMsg,
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
suite.SetupTest()

owner := TestOwnerAddress

pathAToB := NewICAPath(suite.chainA, suite.chainB, ordering)
pathAToB.SetupConnections()

pathAToC := NewICAPath(suite.chainA, suite.chainC, ordering)
pathAToC.SetupConnections()

// build ICS27 metadata with connection identifiers for path A->B
metadata := &icatypes.Metadata{
Version: icatypes.Version,
ControllerConnectionId: pathAToB.EndpointA.ConnectionID,
HostConnectionId: pathAToB.EndpointB.ConnectionID,
Encoding: icatypes.EncodingProtobuf,
TxType: icatypes.TxTypeSDKMultiMsg,
}

err := suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToB.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), ordering)
suite.Require().NoError(err)

// build ICS27 metadata with connection identifiers for path A->C
metadata = &icatypes.Metadata{
Version: icatypes.Version,
ControllerConnectionId: pathAToC.EndpointA.ConnectionID,
HostConnectionId: pathAToC.EndpointB.ConnectionID,
Encoding: icatypes.EncodingProtobuf,
TxType: icatypes.TxTypeSDKMultiMsg,
}

err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToC.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), ordering)
suite.Require().NoError(err)
}

err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToC.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), channeltypes.ORDERED)
suite.Require().NoError(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)
Expand Down Expand Up @@ -95,28 +96,30 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
}

func (suite *KeeperTestSuite) TestExportGenesis() {
suite.SetupTest()
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path.SetupConnections()
path := NewICAPath(suite.chainA, suite.chainB, ordering)
path.SetupConnections()

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

interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(exists)
interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(exists)

genesisState := keeper.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper)
genesisState := keeper.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper)

suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
suite.Require().True(genesisState.ActiveChannels[0].IsMiddlewareEnabled)
suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
suite.Require().True(genesisState.ActiveChannels[0].IsMiddlewareEnabled)

suite.Require().Equal(interchainAccAddr, genesisState.InterchainAccounts[0].AccountAddress)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId)
suite.Require().Equal(interchainAccAddr, genesisState.InterchainAccounts[0].AccountAddress)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId)

suite.Require().Equal([]string{TestPortID}, genesisState.GetPorts())
suite.Require().Equal([]string{TestPortID}, genesisState.GetPorts())

expParams := types.DefaultParams()
suite.Require().Equal(expParams, genesisState.GetParams())
expParams := types.DefaultParams()
suite.Require().Equal(expParams, genesisState.GetParams())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

Expand Down Expand Up @@ -41,37 +42,39 @@ func (suite *KeeperTestSuite) TestQueryInterchainAccount() {
},
}

for _, tc := range testCases {
tc := tc
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest()
suite.Run(tc.name, func() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path.SetupConnections()
path := NewICAPath(suite.chainA, suite.chainB, ordering)
path.SetupConnections()

err := SetupICAPath(path, ibctesting.TestAccAddress)
suite.Require().NoError(err)
err := SetupICAPath(path, ibctesting.TestAccAddress)
suite.Require().NoError(err)

req = &types.QueryInterchainAccountRequest{
ConnectionId: ibctesting.FirstConnectionID,
Owner: ibctesting.TestAccAddress,
}
req = &types.QueryInterchainAccountRequest{
ConnectionId: ibctesting.FirstConnectionID,
Owner: ibctesting.TestAccAddress,
}

tc.malleate()
tc.malleate()

res, err := suite.chainA.GetSimApp().ICAControllerKeeper.InterchainAccount(suite.chainA.GetContext(), req)
res, err := suite.chainA.GetSimApp().ICAControllerKeeper.InterchainAccount(suite.chainA.GetContext(), req)

if tc.expPass {
expAddress, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(exists)
if tc.expPass {
expAddress, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(exists)

suite.Require().NoError(err)
suite.Require().Equal(expAddress, res.Address)
} else {
suite.Require().Error(err)
}
})
suite.Require().NoError(err)
suite.Require().Equal(expAddress, res.Address)
} else {
suite.Require().Error(err)
}
})
}
}
}

Expand Down
Loading

0 comments on commit bbba1e5

Please sign in to comment.