@@ -72,6 +72,28 @@ type IntegrationTestSuite struct {
72
72
queryClient types.QueryClient
73
73
}
74
74
75
+ func (suite * IntegrationTestSuite ) initKeepersWithmAccPerms (blockedAddrs map [string ]bool ) (authkeeper.AccountKeeper , keeper.BaseKeeper ) {
76
+ app := suite .app
77
+ maccPerms := simapp .GetMaccPerms ()
78
+ appCodec := simapp .MakeTestEncodingConfig ().Marshaler
79
+
80
+ maccPerms [holder ] = nil
81
+ maccPerms [authtypes .Burner ] = []string {authtypes .Burner }
82
+ maccPerms [authtypes .Minter ] = []string {authtypes .Minter }
83
+ maccPerms [multiPerm ] = []string {authtypes .Burner , authtypes .Minter , authtypes .Staking }
84
+ maccPerms [randomPerm ] = []string {"random" }
85
+ authKeeper := authkeeper .NewAccountKeeper (
86
+ appCodec , app .GetKey (types .StoreKey ), app .GetSubspace (types .ModuleName ),
87
+ authtypes .ProtoBaseAccount , maccPerms ,
88
+ )
89
+ keeper := keeper .NewBaseKeeper (
90
+ appCodec , app .GetKey (types .StoreKey ), authKeeper ,
91
+ app .GetSubspace (types .ModuleName ), blockedAddrs ,
92
+ )
93
+
94
+ return authKeeper , keeper
95
+ }
96
+
75
97
func (suite * IntegrationTestSuite ) SetupTest () {
76
98
app := simapp .Setup (false )
77
99
ctx := app .BaseApp .NewContext (false , tmproto.Header {})
@@ -89,42 +111,41 @@ func (suite *IntegrationTestSuite) SetupTest() {
89
111
}
90
112
91
113
func (suite * IntegrationTestSuite ) TestSupply () {
92
- app , ctx := suite .app , suite .ctx
114
+ _ , ctx := suite .app , suite .ctx
115
+
116
+ require := suite .Require ()
117
+
118
+ // add module accounts to supply keeper
119
+ authKeeper , keeper := suite .initKeepersWithmAccPerms (make (map [string ]bool ))
93
120
94
121
initialPower := int64 (100 )
95
122
initTokens := suite .app .StakingKeeper .TokensFromConsensusPower (suite .ctx , initialPower )
96
-
97
123
totalSupply := sdk .NewCoins (sdk .NewCoin (sdk .DefaultBondDenom , initTokens ))
98
- suite .NoError (app .BankKeeper .MintCoins (ctx , minttypes .ModuleName , totalSupply ))
99
124
100
- total , _ , err := app .BankKeeper .GetPaginatedTotalSupply (ctx , & query.PageRequest {})
101
- suite .Require ().NoError (err )
102
- suite .Require ().Equal (totalSupply , total )
125
+ // set burnerAcc balance
126
+ authKeeper .SetModuleAccount (ctx , burnerAcc )
127
+ require .NoError (keeper .MintCoins (ctx , authtypes .Minter , totalSupply ))
128
+ require .NoError (keeper .SendCoinsFromModuleToAccount (ctx , authtypes .Minter , burnerAcc .GetAddress (), totalSupply ))
129
+
130
+ total , _ , err := keeper .GetPaginatedTotalSupply (ctx , & query.PageRequest {})
131
+ require .NoError (err )
132
+ require .Equal (totalSupply , total )
133
+
134
+ // burning all supplied tokens
135
+ err = keeper .BurnCoins (ctx , authtypes .Burner , totalSupply )
136
+ require .NoError (err )
137
+
138
+ total , _ , err = keeper .GetPaginatedTotalSupply (ctx , & query.PageRequest {})
139
+ require .NoError (err )
140
+ require .Equal (total .String (), "" )
103
141
}
104
142
105
143
func (suite * IntegrationTestSuite ) TestSendCoinsFromModuleToAccount_Blacklist () {
106
- app := simapp .Setup (false )
107
- ctx := app .BaseApp .NewContext (false , tmproto.Header {Height : 1 })
108
- appCodec := app .AppCodec ()
144
+ ctx := suite .ctx
109
145
110
146
// add module accounts to supply keeper
111
- maccPerms := simapp .GetMaccPerms ()
112
- maccPerms [holder ] = nil
113
- maccPerms [authtypes .Burner ] = []string {authtypes .Burner }
114
- maccPerms [authtypes .Minter ] = []string {authtypes .Minter }
115
- maccPerms [multiPerm ] = []string {authtypes .Burner , authtypes .Minter , authtypes .Staking }
116
- maccPerms [randomPerm ] = []string {"random" }
117
-
118
147
addr1 := sdk .AccAddress ([]byte ("addr1_______________" ))
119
-
120
- authKeeper := authkeeper .NewAccountKeeper (
121
- appCodec , app .GetKey (types .StoreKey ), app .GetSubspace (types .ModuleName ),
122
- authtypes .ProtoBaseAccount , maccPerms ,
123
- )
124
- keeper := keeper .NewBaseKeeper (
125
- appCodec , app .GetKey (types .StoreKey ), authKeeper ,
126
- app .GetSubspace (types .ModuleName ), map [string ]bool {addr1 .String (): true },
127
- )
148
+ _ , keeper := suite .initKeepersWithmAccPerms (map [string ]bool {addr1 .String (): true })
128
149
129
150
suite .Require ().NoError (keeper .MintCoins (ctx , minttypes .ModuleName , initCoins ))
130
151
suite .Require ().Error (keeper .SendCoinsFromModuleToAccount (
@@ -133,26 +154,10 @@ func (suite *IntegrationTestSuite) TestSendCoinsFromModuleToAccount_Blacklist()
133
154
}
134
155
135
156
func (suite * IntegrationTestSuite ) TestSupply_SendCoins () {
136
- app := simapp .Setup (false )
137
- ctx := app .BaseApp .NewContext (false , tmproto.Header {Height : 1 })
138
- appCodec := app .AppCodec ()
157
+ ctx := suite .ctx
139
158
140
159
// add module accounts to supply keeper
141
- maccPerms := simapp .GetMaccPerms ()
142
- maccPerms [holder ] = nil
143
- maccPerms [authtypes .Burner ] = []string {authtypes .Burner }
144
- maccPerms [authtypes .Minter ] = []string {authtypes .Minter }
145
- maccPerms [multiPerm ] = []string {authtypes .Burner , authtypes .Minter , authtypes .Staking }
146
- maccPerms [randomPerm ] = []string {"random" }
147
-
148
- authKeeper := authkeeper .NewAccountKeeper (
149
- appCodec , app .GetKey (types .StoreKey ), app .GetSubspace (types .ModuleName ),
150
- authtypes .ProtoBaseAccount , maccPerms ,
151
- )
152
- keeper := keeper .NewBaseKeeper (
153
- appCodec , app .GetKey (types .StoreKey ), authKeeper ,
154
- app .GetSubspace (types .ModuleName ), make (map [string ]bool ),
155
- )
160
+ authKeeper , keeper := suite .initKeepersWithmAccPerms (make (map [string ]bool ))
156
161
157
162
baseAcc := authKeeper .NewAccountWithAddress (ctx , authtypes .NewModuleAddress ("baseAcc" ))
158
163
@@ -203,26 +208,10 @@ func (suite *IntegrationTestSuite) TestSupply_SendCoins() {
203
208
}
204
209
205
210
func (suite * IntegrationTestSuite ) TestSupply_MintCoins () {
206
- app := simapp .Setup (false )
207
- ctx := app .BaseApp .NewContext (false , tmproto.Header {Height : 1 })
208
- appCodec := app .AppCodec ()
211
+ ctx := suite .ctx
209
212
210
213
// add module accounts to supply keeper
211
- maccPerms := simapp .GetMaccPerms ()
212
- maccPerms [holder ] = nil
213
- maccPerms [authtypes .Burner ] = []string {authtypes .Burner }
214
- maccPerms [authtypes .Minter ] = []string {authtypes .Minter }
215
- maccPerms [multiPerm ] = []string {authtypes .Burner , authtypes .Minter , authtypes .Staking }
216
- maccPerms [randomPerm ] = []string {"random" }
217
-
218
- authKeeper := authkeeper .NewAccountKeeper (
219
- appCodec , app .GetKey (types .StoreKey ), app .GetSubspace (types .ModuleName ),
220
- authtypes .ProtoBaseAccount , maccPerms ,
221
- )
222
- keeper := keeper .NewBaseKeeper (
223
- appCodec , app .GetKey (types .StoreKey ), authKeeper ,
224
- app .GetSubspace (types .ModuleName ), make (map [string ]bool ),
225
- )
214
+ authKeeper , keeper := suite .initKeepersWithmAccPerms (make (map [string ]bool ))
226
215
227
216
authKeeper .SetModuleAccount (ctx , burnerAcc )
228
217
authKeeper .SetModuleAccount (ctx , minterAcc )
@@ -264,26 +253,9 @@ func (suite *IntegrationTestSuite) TestSupply_MintCoins() {
264
253
}
265
254
266
255
func (suite * IntegrationTestSuite ) TestSupply_BurnCoins () {
267
- app := simapp .Setup (false )
268
- ctx := app .BaseApp .NewContext (false , tmproto.Header {Height : 1 })
269
- appCodec := simapp .MakeTestEncodingConfig ().Marshaler
270
-
256
+ ctx := suite .ctx
271
257
// add module accounts to supply keeper
272
- maccPerms := simapp .GetMaccPerms ()
273
- maccPerms [holder ] = nil
274
- maccPerms [authtypes .Burner ] = []string {authtypes .Burner }
275
- maccPerms [authtypes .Minter ] = []string {authtypes .Minter }
276
- maccPerms [multiPerm ] = []string {authtypes .Burner , authtypes .Minter , authtypes .Staking }
277
- maccPerms [randomPerm ] = []string {"random" }
278
-
279
- authKeeper := authkeeper .NewAccountKeeper (
280
- appCodec , app .GetKey (types .StoreKey ), app .GetSubspace (types .ModuleName ),
281
- authtypes .ProtoBaseAccount , maccPerms ,
282
- )
283
- keeper := keeper .NewBaseKeeper (
284
- appCodec , app .GetKey (types .StoreKey ), authKeeper ,
285
- app .GetSubspace (types .ModuleName ), make (map [string ]bool ),
286
- )
258
+ authKeeper , keeper := suite .initKeepersWithmAccPerms (make (map [string ]bool ))
287
259
288
260
// set burnerAcc balance
289
261
authKeeper .SetModuleAccount (ctx , burnerAcc )
@@ -349,11 +321,15 @@ func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
349
321
app .BankKeeper .GetAllBalances (ctx , addr2 )
350
322
suite .Require ().Empty (app .BankKeeper .GetAllBalances (ctx , addr2 ))
351
323
352
- sendAmt := sdk .NewCoins (newFooCoin (50 ), newBarCoin (25 ))
324
+ sendAmt := sdk .NewCoins (newFooCoin (50 ), newBarCoin (50 ))
353
325
suite .Require ().NoError (app .BankKeeper .SendCoins (ctx , addr1 , addr2 , sendAmt ))
354
326
355
327
acc2Balances := app .BankKeeper .GetAllBalances (ctx , addr2 )
328
+ acc1Balances = app .BankKeeper .GetAllBalances (ctx , addr1 )
356
329
suite .Require ().Equal (sendAmt , acc2Balances )
330
+ updatedAcc1Bal := balances .Sub (sendAmt )
331
+ suite .Require ().Len (acc1Balances , len (updatedAcc1Bal ))
332
+ suite .Require ().Equal (acc1Balances , updatedAcc1Bal )
357
333
suite .Require ().NotNil (app .AccountKeeper .GetAccount (ctx , addr2 ))
358
334
}
359
335
0 commit comments