@@ -9,8 +9,11 @@ import BN from "bn.js";
9
9
import { CompoundUtils } from "@utils/CompoundUtils" ;
10
10
import { toWei } from "web3-utils" ;
11
11
import { governorAddress } from "compound-protocol/scenario/src/Value/GovernorValue" ;
12
+ import { expandEvent } from "compound-protocol/scenario/src/Macro" ;
12
13
13
14
const GovernanceExecutor : b . GovernanceExecutorContract = artifacts . require ( "GovernanceExecutor" ) ;
15
+ const EmergencyMock : b . EmergencyMockContract = artifacts . require ( "EmergencyMock" ) ;
16
+ const Avatar : b . AvatarContract = artifacts . require ( "Avatar" ) ;
14
17
15
18
const chai = require ( "chai" ) ;
16
19
const expect = chai . expect ;
@@ -226,22 +229,144 @@ contract("GovernanceExecutor", async (accounts) => {
226
229
} ) ;
227
230
228
231
describe ( "GovernanceExecutor.reqUpgradeWhitelist()" , async ( ) => {
229
- it ( "only owner can request to whitelist a function" ) ;
232
+ let mock : b . EmergencyMockInstance ;
230
233
231
- it ( "non-owner cannot request to whitelist a function" ) ;
234
+ beforeEach ( async ( ) => {
235
+ mock = await EmergencyMock . new ( ) ;
236
+ } ) ;
237
+
238
+ it ( "only owner can request to whitelist a function" , async ( ) => {
239
+ const setXCallData = await mock . setX . call ( 777 ) ;
240
+ const sig = setXCallData . substring ( 0 , 10 ) ; // 2 chars per byte + "0x"
241
+
242
+ const tx = await governanceExecutor . reqSetWhitelistCall ( mock . address , sig , true , {
243
+ from : a . deployer ,
244
+ } ) ;
245
+ expectEvent ( tx , "RequestSetWhitelistCall" , {
246
+ target : mock . address ,
247
+ functionSig : sig ,
248
+ list : true ,
249
+ } ) ;
250
+ } ) ;
251
+
252
+ it ( "non-owner cannot request to whitelist a function" , async ( ) => {
253
+ const setXCallData = await mock . setX . call ( 777 ) ;
254
+ const sig = setXCallData . substring ( 0 , 10 ) ; // 2 chars per byte + "0x"
255
+
256
+ await expectRevert (
257
+ governanceExecutor . reqSetWhitelistCall ( mock . address , sig , true , { from : a . other } ) ,
258
+ "caller is not the owner" ,
259
+ ) ;
260
+ } ) ;
232
261
} ) ;
233
262
234
263
describe ( "GovernanceExecutor.dropUpgradeWhitelist()" , async ( ) => {
235
- it ( "only owner can drop whitelist request" ) ;
264
+ let mock : b . EmergencyMockInstance ;
265
+ let fnSig : string ;
266
+
267
+ beforeEach ( async ( ) => {
268
+ mock = await EmergencyMock . new ( ) ;
236
269
237
- it ( "non-owner cannot drop a whitelist request" ) ;
270
+ const setXCallData = await mock . setX . call ( 777 ) ;
271
+ fnSig = setXCallData . substring ( 0 , 10 ) ; // 2 chars per byte + "0x"
272
+ const tx = await governanceExecutor . reqSetWhitelistCall ( mock . address , fnSig , true , {
273
+ from : a . deployer ,
274
+ } ) ;
275
+ } ) ;
276
+
277
+ it ( "only owner can drop whitelist request" , async ( ) => {
278
+ await governanceExecutor . dropWhitelistCall ( mock . address , fnSig , true , { from : a . deployer } ) ;
279
+ } ) ;
280
+
281
+ it ( "non-owner cannot drop a whitelist request" , async ( ) => {
282
+ await expectRevert (
283
+ governanceExecutor . dropWhitelistCall ( mock . address , fnSig , true , { from : a . other } ) ,
284
+ "Ownable: caller is not the owner" ,
285
+ ) ;
286
+ } ) ;
238
287
} ) ;
239
288
240
289
describe ( "GovernanceExecutor.execUpgradeWhitelist()" , async ( ) => {
241
- it ( "should execute whitelist request" ) ;
290
+ let mock : b . EmergencyMockInstance ;
291
+ let data : string ;
292
+ let fnSig : string ;
293
+ let avatar1 : b . AvatarInstance ;
294
+
295
+ beforeEach ( async ( ) => {
296
+ await registry . newAvatar ( { from : a . user1 } ) ;
297
+ avatar1 = await Avatar . at ( await registry . avatarOf ( a . user1 ) ) ;
298
+ mock = await EmergencyMock . new ( ) ;
299
+
300
+ data = await mock . setX . call ( 777 ) ;
301
+ fnSig = data . substring ( 0 , 10 ) ; // 2 chars per byte + "0x"
302
+ const tx = await governanceExecutor . reqSetWhitelistCall ( mock . address , fnSig , true , {
303
+ from : a . deployer ,
304
+ } ) ;
305
+
306
+ // Registry owner must be GovernanceExecutor
307
+ await bProtocol . registry . transferOwnership ( governanceExecutor . address , { from : a . deployer } ) ;
308
+ } ) ;
309
+
310
+ it ( "should execute whitelist request" , async ( ) => {
311
+ await expectRevert (
312
+ avatar1 . emergencyCall ( mock . address , data , { from : a . user1 } ) ,
313
+ "not-listed" ,
314
+ ) ;
242
315
243
- it ( "should fail when delay not over yet" ) ;
316
+ await time . increase ( TWO_DAYS ) ;
317
+
318
+ const tx = await governanceExecutor . execSetWhitelistCall ( mock . address , fnSig , true ) ;
319
+ expectEvent ( tx , "WhitelistCallUpdated" , {
320
+ target : mock . address ,
321
+ functionSig : fnSig ,
322
+ list : true ,
323
+ } ) ;
324
+
325
+ expect ( await mock . x ( ) ) . to . be . bignumber . equal ( new BN ( 5 ) ) ;
326
+ await avatar1 . emergencyCall ( mock . address , data , { from : a . user1 } ) ;
327
+ expect ( await mock . x ( ) ) . to . be . bignumber . equal ( new BN ( 777 ) ) ;
328
+ } ) ;
329
+
330
+ it ( "should fail when delay not over yet" , async ( ) => {
331
+ await expectRevert (
332
+ avatar1 . emergencyCall ( mock . address , data , { from : a . user1 } ) ,
333
+ "not-listed" ,
334
+ ) ;
244
335
245
- it ( "should fail when request is invalid" ) ;
336
+ await time . increase ( ONE_DAY ) ;
337
+
338
+ await expectRevert (
339
+ governanceExecutor . execSetWhitelistCall ( mock . address , fnSig , true ) ,
340
+ "delay-not-over" ,
341
+ ) ;
342
+
343
+ expect ( await mock . x ( ) ) . to . be . bignumber . equal ( new BN ( 5 ) ) ;
344
+ await expectRevert (
345
+ avatar1 . emergencyCall ( mock . address , data , { from : a . user1 } ) ,
346
+ "not-listed" ,
347
+ ) ;
348
+ expect ( await mock . x ( ) ) . to . be . bignumber . equal ( new BN ( 5 ) ) ;
349
+ } ) ;
350
+
351
+ it ( "should fail when request is invalid" , async ( ) => {
352
+ await expectRevert (
353
+ avatar1 . emergencyCall ( mock . address , data , { from : a . user1 } ) ,
354
+ "not-listed" ,
355
+ ) ;
356
+
357
+ await time . increase ( TWO_DAYS ) ;
358
+
359
+ await expectRevert (
360
+ governanceExecutor . execSetWhitelistCall ( mock . address , fnSig , false ) ,
361
+ "request-not-valid" ,
362
+ ) ;
363
+
364
+ expect ( await mock . x ( ) ) . to . be . bignumber . equal ( new BN ( 5 ) ) ;
365
+ await expectRevert (
366
+ avatar1 . emergencyCall ( mock . address , data , { from : a . user1 } ) ,
367
+ "not-listed" ,
368
+ ) ;
369
+ expect ( await mock . x ( ) ) . to . be . bignumber . equal ( new BN ( 5 ) ) ;
370
+ } ) ;
246
371
} ) ;
247
372
} ) ;
0 commit comments