@@ -31,8 +31,9 @@ func (suite *InterchainAccountsTestSuite) SetupTest() {
31
31
}
32
32
33
33
func (suite * InterchainAccountsTestSuite ) TestInitModule () {
34
+ // setup and basic testing
34
35
app := simapp .NewSimApp (log .NewNopLogger (), dbm .NewMemDB (), nil , true , map [int64 ]bool {}, simapp .DefaultNodeHome , 5 , simapp .MakeTestEncodingConfig (), simapp.EmptyAppOptions {})
35
- icamodule , ok := app .GetModuleManager ().Modules [types .ModuleName ].(ica.AppModule )
36
+ appModule , ok := app .GetModuleManager ().Modules [types .ModuleName ].(ica.AppModule )
36
37
suite .Require ().True (ok )
37
38
38
39
header := tmproto.Header {
@@ -58,17 +59,74 @@ func (suite *InterchainAccountsTestSuite) TestInitModule() {
58
59
expAllowMessages := []string {"sdk.Msg" }
59
60
hostParams .HostEnabled = true
60
61
hostParams .AllowMessages = expAllowMessages
61
-
62
62
suite .Require ().False (app .IBCKeeper .PortKeeper .IsBound (ctx , types .PortID ))
63
63
64
- icamodule .InitModule (ctx , controllerParams , hostParams )
64
+ testCases := []struct {
65
+ name string
66
+ malleate func ()
67
+ expControllerPass bool
68
+ expHostPass bool
69
+ }{
70
+ {
71
+ "both controller and host set" , func () {
72
+ var ok bool
73
+ appModule , ok = app .GetModuleManager ().Modules [types .ModuleName ].(ica.AppModule )
74
+ suite .Require ().True (ok )
75
+ }, true , true ,
76
+ },
77
+ {
78
+ "neither controller or host is set" , func () {
79
+ appModule = ica .NewAppModule (nil , nil )
80
+ }, false , false ,
81
+ },
82
+ {
83
+ "only controller is set" , func () {
84
+ appModule = ica .NewAppModule (& app .ICAControllerKeeper , nil )
85
+ }, true , false ,
86
+ },
87
+ {
88
+ "only host is set" , func () {
89
+ appModule = ica .NewAppModule (nil , & app .ICAHostKeeper )
90
+ }, false , true ,
91
+ },
92
+ }
93
+
94
+ for _ , tc := range testCases {
95
+ tc := tc
96
+
97
+ suite .Run (tc .name , func () {
98
+ suite .SetupTest () // reset
99
+
100
+ // reset app state
101
+ app = simapp .NewSimApp (log .NewNopLogger (), dbm .NewMemDB (), nil , true , map [int64 ]bool {}, simapp .DefaultNodeHome , 5 , simapp .MakeTestEncodingConfig (), simapp.EmptyAppOptions {})
102
+ header := tmproto.Header {
103
+ ChainID : "testchain" ,
104
+ Height : 1 ,
105
+ Time : suite .coordinator .CurrentTime .UTC (),
106
+ }
107
+
108
+ ctx := app .GetBaseApp ().NewContext (true , header )
65
109
66
- controllerParams = app .ICAControllerKeeper .GetParams (ctx )
67
- suite .Require ().True (controllerParams .ControllerEnabled )
110
+ tc .malleate ()
68
111
69
- hostParams = app .ICAHostKeeper .GetParams (ctx )
70
- suite .Require ().True (hostParams .HostEnabled )
71
- suite .Require ().Equal (expAllowMessages , hostParams .AllowMessages )
112
+ suite .Require ().NotPanics (func () {
113
+ appModule .InitModule (ctx , controllerParams , hostParams )
114
+ })
115
+
116
+ if tc .expControllerPass {
117
+ controllerParams = app .ICAControllerKeeper .GetParams (ctx )
118
+ suite .Require ().True (controllerParams .ControllerEnabled )
119
+ }
120
+
121
+ if tc .expHostPass {
122
+ hostParams = app .ICAHostKeeper .GetParams (ctx )
123
+ suite .Require ().True (hostParams .HostEnabled )
124
+ suite .Require ().Equal (expAllowMessages , hostParams .AllowMessages )
125
+
126
+ suite .Require ().True (app .IBCKeeper .PortKeeper .IsBound (ctx , types .PortID ))
127
+ }
128
+
129
+ })
130
+ }
72
131
73
- suite .Require ().True (app .IBCKeeper .PortKeeper .IsBound (ctx , types .PortID ))
74
132
}
0 commit comments