@@ -38,7 +38,13 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy() {
38
38
} ) ;
39
39
40
40
beforeEach ( async function ( ) {
41
- Object . assign ( this , await this . createProxyWithImpersonatedProxyAdmin ( this . implementationV0 , '0x' ) ) ;
41
+ Object . assign (
42
+ this ,
43
+ await this . createProxyWithImpersonatedProxyAdmin (
44
+ this . implementationV0 ,
45
+ this . implementation . interface . encodeFunctionData ( 'initialize' , [ 100n , 'test' , [ 1 , 2 , 3 ] ] ) ,
46
+ ) ,
47
+ ) ;
42
48
} ) ;
43
49
44
50
describe ( 'implementation' , function ( ) {
@@ -239,7 +245,13 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy() {
239
245
this . clashingImplV0 = await ethers . deployContract ( 'ClashingImplementation' ) ;
240
246
this . clashingImplV1 = await ethers . deployContract ( 'ClashingImplementation' ) ;
241
247
242
- Object . assign ( this , await this . createProxyWithImpersonatedProxyAdmin ( this . clashingImplV0 , '0x' ) ) ;
248
+ Object . assign (
249
+ this ,
250
+ await this . createProxyWithImpersonatedProxyAdmin (
251
+ this . clashingImplV0 ,
252
+ this . clashingImplV0 . interface . encodeFunctionData ( 'initialize' ) ,
253
+ ) ,
254
+ ) ;
243
255
} ) ;
244
256
245
257
it ( 'proxy admin cannot call delegated functions' , async function ( ) {
@@ -267,91 +279,87 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy() {
267
279
} ) ;
268
280
269
281
describe ( 'regression' , function ( ) {
270
- const initializeData = '0x' ;
282
+ beforeEach ( async function ( ) {
283
+ this . impl1 = await ethers . deployContract ( 'Implementation1' ) ;
284
+ this . impl2 = await ethers . deployContract ( 'Implementation2' ) ;
285
+ this . impl3 = await ethers . deployContract ( 'Implementation3' ) ;
286
+ this . impl4 = await ethers . deployContract ( 'Implementation4' ) ;
287
+ this . initializeData = this . impl1 . interface . encodeFunctionData ( 'initialize' ) ;
288
+ } ) ;
271
289
272
290
it ( 'should add new function' , async function ( ) {
273
- const impl1 = await ethers . deployContract ( 'Implementation1' ) ;
274
- const impl2 = await ethers . deployContract ( 'Implementation2' ) ;
275
291
const { instance, proxy, proxyAdminAsSigner } = await this . createProxyWithImpersonatedProxyAdmin (
276
- impl1 ,
277
- initializeData ,
292
+ this . impl1 ,
293
+ this . initializeData ,
278
294
) ;
279
295
280
296
await instance . setValue ( 42n ) ;
281
297
282
298
// `getValue` is not available in impl1
283
- await expect ( impl2 . attach ( instance ) . getValue ( ) ) . to . be . reverted ;
299
+ await expect ( this . impl2 . attach ( instance ) . getValue ( ) ) . to . be . reverted ;
284
300
285
301
// do upgrade
286
- await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( impl2 , '0x' ) ;
302
+ await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( this . impl2 , '0x' ) ;
287
303
288
304
// `getValue` is available in impl2
289
- expect ( await impl2 . attach ( instance ) . getValue ( ) ) . to . equal ( 42n ) ;
305
+ expect ( await this . impl2 . attach ( instance ) . getValue ( ) ) . to . equal ( 42n ) ;
290
306
} ) ;
291
307
292
308
it ( 'should remove function' , async function ( ) {
293
- const impl1 = await ethers . deployContract ( 'Implementation1' ) ;
294
- const impl2 = await ethers . deployContract ( 'Implementation2' ) ;
295
309
const { instance, proxy, proxyAdminAsSigner } = await this . createProxyWithImpersonatedProxyAdmin (
296
- impl2 ,
297
- initializeData ,
310
+ this . impl2 ,
311
+ this . initializeData ,
298
312
) ;
299
313
300
314
await instance . setValue ( 42n ) ;
301
315
302
316
// `getValue` is available in impl2
303
- expect ( await impl2 . attach ( instance ) . getValue ( ) ) . to . equal ( 42n ) ;
317
+ expect ( await this . impl2 . attach ( instance ) . getValue ( ) ) . to . equal ( 42n ) ;
304
318
305
319
// do downgrade
306
- await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( impl1 , '0x' ) ;
320
+ await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( this . impl1 , '0x' ) ;
307
321
308
322
// `getValue` is not available in impl1
309
- await expect ( impl2 . attach ( instance ) . getValue ( ) ) . to . be . reverted ;
323
+ await expect ( this . impl2 . attach ( instance ) . getValue ( ) ) . to . be . reverted ;
310
324
} ) ;
311
325
312
326
it ( 'should change function signature' , async function ( ) {
313
- const impl1 = await ethers . deployContract ( 'Implementation1' ) ;
314
- const impl3 = await ethers . deployContract ( 'Implementation3' ) ;
315
327
const { instance, proxy, proxyAdminAsSigner } = await this . createProxyWithImpersonatedProxyAdmin (
316
- impl1 ,
317
- initializeData ,
328
+ this . impl1 ,
329
+ this . initializeData ,
318
330
) ;
319
331
320
332
await instance . setValue ( 42n ) ;
321
333
322
- await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( impl3 , '0x' ) ;
334
+ await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( this . impl3 , '0x' ) ;
323
335
324
- expect ( await impl3 . attach ( instance ) . getValue ( 8n ) ) . to . equal ( 50n ) ;
336
+ expect ( await this . impl3 . attach ( instance ) . getValue ( 8n ) ) . to . equal ( 50n ) ;
325
337
} ) ;
326
338
327
339
it ( 'should add fallback function' , async function ( ) {
328
- const impl1 = await ethers . deployContract ( 'Implementation1' ) ;
329
- const impl4 = await ethers . deployContract ( 'Implementation4' ) ;
330
340
const { instance, proxy, proxyAdminAsSigner } = await this . createProxyWithImpersonatedProxyAdmin (
331
- impl1 ,
332
- initializeData ,
341
+ this . impl1 ,
342
+ this . initializeData ,
333
343
) ;
334
344
335
- await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( impl4 , '0x' ) ;
345
+ await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( this . impl4 , '0x' ) ;
336
346
337
347
await this . other . sendTransaction ( { to : proxy } ) ;
338
348
339
- expect ( await impl4 . attach ( instance ) . getValue ( ) ) . to . equal ( 1n ) ;
349
+ expect ( await this . impl4 . attach ( instance ) . getValue ( ) ) . to . equal ( 1n ) ;
340
350
} ) ;
341
351
342
352
it ( 'should remove fallback function' , async function ( ) {
343
- const impl2 = await ethers . deployContract ( 'Implementation2' ) ;
344
- const impl4 = await ethers . deployContract ( 'Implementation4' ) ;
345
353
const { instance, proxy, proxyAdminAsSigner } = await this . createProxyWithImpersonatedProxyAdmin (
346
- impl4 ,
347
- initializeData ,
354
+ this . impl4 ,
355
+ this . initializeData ,
348
356
) ;
349
357
350
- await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( impl2 , '0x' ) ;
358
+ await proxy . connect ( proxyAdminAsSigner ) . upgradeToAndCall ( this . impl2 , '0x' ) ;
351
359
352
360
await expect ( this . other . sendTransaction ( { to : proxy } ) ) . to . be . reverted ;
353
361
354
- expect ( await impl2 . attach ( instance ) . getValue ( ) ) . to . equal ( 0n ) ;
362
+ expect ( await this . impl2 . attach ( instance ) . getValue ( ) ) . to . equal ( 0n ) ;
355
363
} ) ;
356
364
} ) ;
357
365
} ;
0 commit comments