Skip to content

Commit bbba1e5

Browse files
test both ORDERED and UNORDERED channels in most (probably all) tests involving something with ICA
1 parent 5a7d723 commit bbba1e5

File tree

16 files changed

+2683
-2529
lines changed

16 files changed

+2683
-2529
lines changed

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

Lines changed: 598 additions & 561 deletions
Large diffs are not rendered by default.

modules/apps/27-interchain-accounts/controller/keeper/account_test.go

Lines changed: 100 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -8,113 +8,118 @@ import (
88
)
99

1010
func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
11-
var (
12-
owner string
13-
path *ibctesting.Path
14-
err error
15-
)
16-
17-
testCases := []struct {
18-
name string
19-
malleate func()
20-
expPass bool
21-
}{
22-
{
23-
"success", func() {}, true,
24-
},
25-
{
26-
"port is already bound for owner but capability is claimed by another module",
27-
func() {
28-
capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
29-
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID))
30-
suite.Require().NoError(err)
11+
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
12+
var (
13+
owner string
14+
path *ibctesting.Path
15+
err error
16+
)
17+
18+
testCases := []struct {
19+
name string
20+
malleate func()
21+
expPass bool
22+
}{
23+
{
24+
"success", func() {}, true,
3125
},
32-
false,
33-
},
34-
{
35-
"fails to generate port-id",
36-
func() {
37-
owner = ""
26+
{
27+
"port is already bound for owner but capability is claimed by another module",
28+
func() {
29+
capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
30+
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID))
31+
suite.Require().NoError(err)
32+
},
33+
false,
3834
},
39-
false,
40-
},
41-
{
42-
"MsgChanOpenInit fails - channel is already active & in state OPEN",
43-
func() {
44-
portID, err := icatypes.NewControllerPortID(TestOwnerAddress)
45-
suite.Require().NoError(err)
46-
47-
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID)
48-
49-
counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
50-
channel := channeltypes.Channel{
51-
State: channeltypes.OPEN,
52-
Ordering: channeltypes.ORDERED,
53-
Counterparty: counterparty,
54-
ConnectionHops: []string{path.EndpointA.ConnectionID},
55-
Version: TestVersion,
56-
}
57-
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel)
35+
{
36+
"fails to generate port-id",
37+
func() {
38+
owner = ""
39+
},
40+
false,
5841
},
59-
false,
60-
},
61-
}
62-
for _, tc := range testCases {
63-
tc := tc
42+
{
43+
"MsgChanOpenInit fails - channel is already active & in state OPEN",
44+
func() {
45+
portID, err := icatypes.NewControllerPortID(TestOwnerAddress)
46+
suite.Require().NoError(err)
47+
48+
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID)
49+
50+
counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
51+
channel := channeltypes.Channel{
52+
State: channeltypes.OPEN,
53+
Ordering: ordering,
54+
Counterparty: counterparty,
55+
ConnectionHops: []string{path.EndpointA.ConnectionID},
56+
Version: TestVersion,
57+
}
58+
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel)
59+
},
60+
false,
61+
},
62+
}
63+
64+
for _, tc := range testCases {
65+
tc := tc
6466

65-
suite.Run(tc.name, func() {
66-
suite.SetupTest()
67+
suite.Run(tc.name, func() {
68+
suite.SetupTest()
6769

68-
owner = TestOwnerAddress // must be explicitly changed
70+
owner = TestOwnerAddress // must be explicitly changed
6971

70-
path = NewICAPath(suite.chainA, suite.chainB)
71-
path.SetupConnections()
72+
path = NewICAPath(suite.chainA, suite.chainB, ordering)
73+
path.SetupConnections()
7274

73-
tc.malleate() // malleate mutates test data
75+
tc.malleate() // malleate mutates test data
7476

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

77-
if tc.expPass {
78-
suite.Require().NoError(err)
79-
} else {
80-
suite.Require().Error(err)
81-
}
82-
})
79+
if tc.expPass {
80+
suite.Require().NoError(err)
81+
} else {
82+
suite.Require().Error(err)
83+
}
84+
})
85+
}
8386
}
8487
}
8588

8689
func (suite *KeeperTestSuite) TestRegisterSameOwnerMultipleConnections() {
87-
suite.SetupTest()
88-
89-
owner := TestOwnerAddress
90-
91-
pathAToB := NewICAPath(suite.chainA, suite.chainB)
92-
pathAToB.SetupConnections()
93-
94-
pathAToC := NewICAPath(suite.chainA, suite.chainC)
95-
pathAToC.SetupConnections()
96-
97-
// build ICS27 metadata with connection identifiers for path A->B
98-
metadata := &icatypes.Metadata{
99-
Version: icatypes.Version,
100-
ControllerConnectionId: pathAToB.EndpointA.ConnectionID,
101-
HostConnectionId: pathAToB.EndpointB.ConnectionID,
102-
Encoding: icatypes.EncodingProtobuf,
103-
TxType: icatypes.TxTypeSDKMultiMsg,
104-
}
105-
106-
err := suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToB.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), channeltypes.ORDERED)
107-
suite.Require().NoError(err)
108-
109-
// build ICS27 metadata with connection identifiers for path A->C
110-
metadata = &icatypes.Metadata{
111-
Version: icatypes.Version,
112-
ControllerConnectionId: pathAToC.EndpointA.ConnectionID,
113-
HostConnectionId: pathAToC.EndpointB.ConnectionID,
114-
Encoding: icatypes.EncodingProtobuf,
115-
TxType: icatypes.TxTypeSDKMultiMsg,
90+
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
91+
suite.SetupTest()
92+
93+
owner := TestOwnerAddress
94+
95+
pathAToB := NewICAPath(suite.chainA, suite.chainB, ordering)
96+
pathAToB.SetupConnections()
97+
98+
pathAToC := NewICAPath(suite.chainA, suite.chainC, ordering)
99+
pathAToC.SetupConnections()
100+
101+
// build ICS27 metadata with connection identifiers for path A->B
102+
metadata := &icatypes.Metadata{
103+
Version: icatypes.Version,
104+
ControllerConnectionId: pathAToB.EndpointA.ConnectionID,
105+
HostConnectionId: pathAToB.EndpointB.ConnectionID,
106+
Encoding: icatypes.EncodingProtobuf,
107+
TxType: icatypes.TxTypeSDKMultiMsg,
108+
}
109+
110+
err := suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToB.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), ordering)
111+
suite.Require().NoError(err)
112+
113+
// build ICS27 metadata with connection identifiers for path A->C
114+
metadata = &icatypes.Metadata{
115+
Version: icatypes.Version,
116+
ControllerConnectionId: pathAToC.EndpointA.ConnectionID,
117+
HostConnectionId: pathAToC.EndpointB.ConnectionID,
118+
Encoding: icatypes.EncodingProtobuf,
119+
TxType: icatypes.TxTypeSDKMultiMsg,
120+
}
121+
122+
err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToC.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), ordering)
123+
suite.Require().NoError(err)
116124
}
117-
118-
err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToC.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata)), channeltypes.ORDERED)
119-
suite.Require().NoError(err)
120125
}

modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
66
genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types"
77
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
8+
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
89
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
910
ibctesting "github.com/cosmos/ibc-go/v8/testing"
1011
)
@@ -95,28 +96,30 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
9596
}
9697

9798
func (suite *KeeperTestSuite) TestExportGenesis() {
98-
suite.SetupTest()
99+
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
100+
suite.SetupTest()
99101

100-
path := NewICAPath(suite.chainA, suite.chainB)
101-
path.SetupConnections()
102+
path := NewICAPath(suite.chainA, suite.chainB, ordering)
103+
path.SetupConnections()
102104

103-
err := SetupICAPath(path, TestOwnerAddress)
104-
suite.Require().NoError(err)
105+
err := SetupICAPath(path, TestOwnerAddress)
106+
suite.Require().NoError(err)
105107

106-
interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
107-
suite.Require().True(exists)
108+
interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
109+
suite.Require().True(exists)
108110

109-
genesisState := keeper.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper)
111+
genesisState := keeper.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper)
110112

111-
suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId)
112-
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
113-
suite.Require().True(genesisState.ActiveChannels[0].IsMiddlewareEnabled)
113+
suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId)
114+
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
115+
suite.Require().True(genesisState.ActiveChannels[0].IsMiddlewareEnabled)
114116

115-
suite.Require().Equal(interchainAccAddr, genesisState.InterchainAccounts[0].AccountAddress)
116-
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId)
117+
suite.Require().Equal(interchainAccAddr, genesisState.InterchainAccounts[0].AccountAddress)
118+
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId)
117119

118-
suite.Require().Equal([]string{TestPortID}, genesisState.GetPorts())
120+
suite.Require().Equal([]string{TestPortID}, genesisState.GetPorts())
119121

120-
expParams := types.DefaultParams()
121-
suite.Require().Equal(expParams, genesisState.GetParams())
122+
expParams := types.DefaultParams()
123+
suite.Require().Equal(expParams, genesisState.GetParams())
124+
}
122125
}

modules/apps/27-interchain-accounts/controller/keeper/grpc_query_test.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper_test
22

33
import (
44
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
5+
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
56
ibctesting "github.com/cosmos/ibc-go/v8/testing"
67
)
78

@@ -41,37 +42,39 @@ func (suite *KeeperTestSuite) TestQueryInterchainAccount() {
4142
},
4243
}
4344

44-
for _, tc := range testCases {
45-
tc := tc
45+
for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
46+
for _, tc := range testCases {
47+
tc := tc
4648

47-
suite.Run(tc.name, func() {
48-
suite.SetupTest()
49+
suite.Run(tc.name, func() {
50+
suite.SetupTest()
4951

50-
path := NewICAPath(suite.chainA, suite.chainB)
51-
path.SetupConnections()
52+
path := NewICAPath(suite.chainA, suite.chainB, ordering)
53+
path.SetupConnections()
5254

53-
err := SetupICAPath(path, ibctesting.TestAccAddress)
54-
suite.Require().NoError(err)
55+
err := SetupICAPath(path, ibctesting.TestAccAddress)
56+
suite.Require().NoError(err)
5557

56-
req = &types.QueryInterchainAccountRequest{
57-
ConnectionId: ibctesting.FirstConnectionID,
58-
Owner: ibctesting.TestAccAddress,
59-
}
58+
req = &types.QueryInterchainAccountRequest{
59+
ConnectionId: ibctesting.FirstConnectionID,
60+
Owner: ibctesting.TestAccAddress,
61+
}
6062

61-
tc.malleate()
63+
tc.malleate()
6264

63-
res, err := suite.chainA.GetSimApp().ICAControllerKeeper.InterchainAccount(suite.chainA.GetContext(), req)
65+
res, err := suite.chainA.GetSimApp().ICAControllerKeeper.InterchainAccount(suite.chainA.GetContext(), req)
6466

65-
if tc.expPass {
66-
expAddress, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
67-
suite.Require().True(exists)
67+
if tc.expPass {
68+
expAddress, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
69+
suite.Require().True(exists)
6870

69-
suite.Require().NoError(err)
70-
suite.Require().Equal(expAddress, res.Address)
71-
} else {
72-
suite.Require().Error(err)
73-
}
74-
})
71+
suite.Require().NoError(err)
72+
suite.Require().Equal(expAddress, res.Address)
73+
} else {
74+
suite.Require().Error(err)
75+
}
76+
})
77+
}
7578
}
7679
}
7780

0 commit comments

Comments
 (0)