@@ -8,113 +8,118 @@ import (
88)
99
1010func (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
8689func (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}
0 commit comments