2
2
* Shared test patterns and utilities to reduce duplication across test files
3
3
*/
4
4
5
- const { expect } = require ( 'chai' )
6
- const { ethers } = require ( 'hardhat' )
5
+ import { expect } from 'chai'
6
+ import { ethers } from 'hardhat'
7
7
8
8
// Type definitions for test utilities
9
9
export interface TestAccounts {
@@ -71,7 +71,7 @@ export function shouldEnforceGovernorRole<T>(
71
71
72
72
await expect (
73
73
( contract as any ) . connect ( testAccounts . nonGovernor ) [ methodName ] ( ...methodArgs ) ,
74
- ) . to . be . revertedWithCustomError ( contract , 'AccessControlUnauthorizedAccount' )
74
+ ) . to . be . revertedWithCustomError ( contract as any , 'AccessControlUnauthorizedAccount' )
75
75
} )
76
76
77
77
it ( `should allow governor to call ${ methodName } ` , async function ( ) {
@@ -100,7 +100,7 @@ export function shouldEnforceRoleAccess<T>(
100
100
101
101
await expect (
102
102
( contract as any ) . connect ( testAccounts . nonGovernor ) [ methodName ] ( ...methodArgs ) ,
103
- ) . to . be . revertedWithCustomError ( contract , 'AccessControlUnauthorizedAccount' )
103
+ ) . to . be . revertedWithCustomError ( contract as any , 'AccessControlUnauthorizedAccount' )
104
104
} )
105
105
}
106
106
}
@@ -161,6 +161,7 @@ export function shouldInitializeCorrectly<T>(contractGetter: () => T, expectedVa
161
161
Object . entries ( expectedValues ) . forEach ( ( [ property , expectedValue ] ) => {
162
162
it ( `should set ${ property } correctly during initialization` , async function ( ) {
163
163
const contract = contractGetter ( )
164
+ // Type assertion is necessary here since we're accessing dynamic properties
164
165
const actualValue = await ( contract as any ) [ property ] ( )
165
166
expect ( actualValue ) . to . equal ( expectedValue )
166
167
} )
@@ -171,7 +172,7 @@ export function shouldInitializeCorrectly<T>(contractGetter: () => T, expectedVa
171
172
const accounts = this . parent . ctx . accounts
172
173
173
174
await expect ( ( contract as any ) . initialize ( accounts . governor . address ) ) . to . be . revertedWithCustomError (
174
- contract ,
175
+ contract as any ,
175
176
'InvalidInitialization' ,
176
177
)
177
178
} )
@@ -278,7 +279,7 @@ export function shouldEnforceAccessControl<T>(
278
279
const contract = contractGetter ( )
279
280
await expect (
280
281
( contract as any ) . connect ( accounts . nonGovernor ) [ method . name ] ( ...method . args ) ,
281
- ) . to . be . revertedWithCustomError ( contract , 'AccessControlUnauthorizedAccount' )
282
+ ) . to . be . revertedWithCustomError ( contract as any , 'AccessControlUnauthorizedAccount' )
282
283
} )
283
284
284
285
allowedRoles . forEach ( ( role ) => {
@@ -335,7 +336,7 @@ export function shouldInitializeProperly<T>(
335
336
const contract = contractGetter ( )
336
337
await expect (
337
338
( contract as any ) [ reinitializationTest . method ] ( ...reinitializationTest . args ) ,
338
- ) . to . be . revertedWithCustomError ( contract , reinitializationTest . expectedError )
339
+ ) . to . be . revertedWithCustomError ( contract as any , reinitializationTest . expectedError )
339
340
} )
340
341
}
341
342
} )
@@ -377,7 +378,7 @@ export function shouldHandlePausability<T>(
377
378
it ( 'should revert when non-PAUSE_ROLE tries to pause' , async function ( ) {
378
379
const contract = contractGetter ( )
379
380
await expect ( ( contract as any ) . connect ( accounts . nonGovernor ) . pause ( ) ) . to . be . revertedWithCustomError (
380
- contract ,
381
+ contract as any ,
381
382
'AccessControlUnauthorizedAccount' ,
382
383
)
383
384
} )
@@ -400,7 +401,7 @@ export function shouldHandlePausability<T>(
400
401
401
402
await expect (
402
403
( contract as any ) . connect ( caller ) [ operation . name ] ( ...operation . args ) ,
403
- ) . to . be . revertedWithCustomError ( contract , 'EnforcedPause' )
404
+ ) . to . be . revertedWithCustomError ( contract as any , 'EnforcedPause' )
404
405
} )
405
406
} )
406
407
} )
@@ -455,7 +456,7 @@ export function shouldManageRoles<T>(
455
456
const contract = contractGetter ( )
456
457
await expect (
457
458
( contract as any ) . connect ( accounts . nonGovernor ) . grantRole ( roleConfig . role , accounts . user . address ) ,
458
- ) . to . be . revertedWithCustomError ( contract , 'AccessControlUnauthorizedAccount' )
459
+ ) . to . be . revertedWithCustomError ( contract as any , 'AccessControlUnauthorizedAccount' )
459
460
} )
460
461
} )
461
462
} )
@@ -520,7 +521,7 @@ export function shouldValidateInputs<T>(
520
521
test . caller === 'operator' ? accounts . operator : test . caller === 'user' ? accounts . user : accounts . governor
521
522
522
523
await expect ( ( contract as any ) . connect ( caller ) [ test . method ] ( ...test . args ) ) . to . be . revertedWithCustomError (
523
- contract ,
524
+ contract as any ,
524
525
test . expectedError ,
525
526
)
526
527
} )
0 commit comments