@@ -17,7 +17,7 @@ import {
17
17
use ( solidity )
18
18
19
19
describe ( 'SBTProxy' , ( ) => {
20
- const init = async ( ) : Promise < {
20
+ const init = async ( shouldAlsoInitializeProxy = true ) : Promise < {
21
21
sbt : Contract
22
22
sbtImplementation : Contract
23
23
sbtProxy : Contract
@@ -32,10 +32,12 @@ describe('SBTProxy', () => {
32
32
ethers . utils . arrayify ( '0x' ) ,
33
33
] )
34
34
const sbt = sbtImplementation . attach ( sbtProxy . address )
35
- await sbt . initialize ( signers . minterUpdater . address , [
36
- signers . minterA . address ,
37
- signers . minterB . address ,
38
- ] )
35
+ if ( shouldAlsoInitializeProxy ) {
36
+ await sbt . initialize ( signers . minterUpdater . address , [
37
+ signers . minterA . address ,
38
+ signers . minterB . address ,
39
+ ] )
40
+ }
39
41
40
42
return { sbt, sbtImplementation, sbtProxy, sbtImplementationB }
41
43
}
@@ -458,6 +460,225 @@ describe('SBTProxy', () => {
458
460
) . to . reverted
459
461
} )
460
462
} )
463
+
464
+ describe ( 'upgradeToAndCall' , ( ) => {
465
+ it ( 'Should upgradeToAndCall (upgrade and initialize smart-contract) correctly if signer is proxyAdmin' , async ( ) => {
466
+ const signers = await getSigners ( )
467
+ const { sbt, sbtProxy, sbtImplementation, sbtImplementationB } =
468
+ await init ( false )
469
+ expect ( sbt . address ) . to . eq ( sbtProxy . address )
470
+ expect (
471
+ await sbtProxy . connect ( signers . proxyAdmin ) . callStatic . implementation ( )
472
+ ) . to . eq ( sbtImplementation . address )
473
+ await expect (
474
+ sbtProxy . connect ( signers . proxyAdminB ) . callStatic . implementation ( )
475
+ ) . to . reverted
476
+ await expect (
477
+ sbtProxy . connect ( signers . userA ) . callStatic . implementation ( )
478
+ ) . to . reverted
479
+ await expect (
480
+ sbtProxy . connect ( signers . userB ) . callStatic . implementation ( )
481
+ ) . to . reverted
482
+ await expect (
483
+ sbtProxy . connect ( signers . minterUpdater ) . callStatic . implementation ( )
484
+ ) . to . reverted
485
+ await expect (
486
+ sbtProxy . connect ( signers . minterA ) . callStatic . implementation ( )
487
+ ) . to . reverted
488
+ await expect (
489
+ sbtProxy . connect ( signers . minterB ) . callStatic . implementation ( )
490
+ ) . to . reverted
491
+ await expect (
492
+ sbtProxy . connect ( signers . minterC ) . callStatic . implementation ( )
493
+ ) . to . reverted
494
+ await expect (
495
+ sbtProxy . connect ( signers . deployer ) . callStatic . implementation ( )
496
+ ) . to . reverted
497
+
498
+ const encodedData = sbtImplementationB
499
+ . connect ( signers . minterUpdater )
500
+ . interface . encodeFunctionData ( 'initialize' , [
501
+ signers . minterUpdater . address ,
502
+ [
503
+ signers . minterA . address ,
504
+ signers . minterB . address ,
505
+ ]
506
+ ] )
507
+ await expect (
508
+ sbtProxy
509
+ . connect ( signers . proxyAdmin )
510
+ . upgradeToAndCall ( sbtImplementationB . address , encodedData )
511
+ )
512
+ . to . emit ( sbtProxy , 'Upgraded' )
513
+ . withArgs ( sbtImplementationB . address )
514
+
515
+ await expect ( sbt . connect ( signers . userA ) . initialize ( signers . minterUpdater . address , [
516
+ signers . minterA . address ,
517
+ signers . minterB . address ,
518
+ ] ) ) . to . revertedWith ( 'Initializable: contract is already initialized' )
519
+
520
+ expect (
521
+ await sbtProxy . connect ( signers . proxyAdmin ) . callStatic . implementation ( )
522
+ ) . to . eq ( sbtImplementationB . address )
523
+ await expect (
524
+ sbtProxy . connect ( signers . proxyAdminB ) . callStatic . implementation ( )
525
+ ) . to . reverted
526
+ await expect (
527
+ sbtProxy . connect ( signers . userA ) . callStatic . implementation ( )
528
+ ) . to . reverted
529
+ await expect (
530
+ sbtProxy . connect ( signers . userB ) . callStatic . implementation ( )
531
+ ) . to . reverted
532
+ await expect (
533
+ sbtProxy . connect ( signers . minterUpdater ) . callStatic . implementation ( )
534
+ ) . to . reverted
535
+ await expect (
536
+ sbtProxy . connect ( signers . minterA ) . callStatic . implementation ( )
537
+ ) . to . reverted
538
+ await expect (
539
+ sbtProxy . connect ( signers . minterB ) . callStatic . implementation ( )
540
+ ) . to . reverted
541
+ await expect (
542
+ sbtProxy . connect ( signers . minterC ) . callStatic . implementation ( )
543
+ ) . to . reverted
544
+ await expect (
545
+ sbtProxy . connect ( signers . deployer ) . callStatic . implementation ( )
546
+ ) . to . reverted
547
+ } )
548
+
549
+ it ( 'Should not upgradeToAndCall (upgrade and initialize smart-contract) correctly if signer is not proxyAdmin' , async ( ) => {
550
+ const signers = await getSigners ( )
551
+ const { sbt, sbtProxy, sbtImplementation, sbtImplementationB } =
552
+ await init ( false )
553
+ expect ( sbt . address ) . to . eq ( sbtProxy . address )
554
+ expect (
555
+ await sbtProxy . connect ( signers . proxyAdmin ) . callStatic . implementation ( )
556
+ ) . to . eq ( sbtImplementation . address )
557
+ await expect (
558
+ sbtProxy . connect ( signers . proxyAdminB ) . callStatic . implementation ( )
559
+ ) . to . reverted
560
+ await expect (
561
+ sbtProxy . connect ( signers . userA ) . callStatic . implementation ( )
562
+ ) . to . reverted
563
+ await expect (
564
+ sbtProxy . connect ( signers . userB ) . callStatic . implementation ( )
565
+ ) . to . reverted
566
+ await expect (
567
+ sbtProxy . connect ( signers . minterUpdater ) . callStatic . implementation ( )
568
+ ) . to . reverted
569
+ await expect (
570
+ sbtProxy . connect ( signers . minterA ) . callStatic . implementation ( )
571
+ ) . to . reverted
572
+ await expect (
573
+ sbtProxy . connect ( signers . minterB ) . callStatic . implementation ( )
574
+ ) . to . reverted
575
+ await expect (
576
+ sbtProxy . connect ( signers . minterC ) . callStatic . implementation ( )
577
+ ) . to . reverted
578
+ await expect (
579
+ sbtProxy . connect ( signers . deployer ) . callStatic . implementation ( )
580
+ ) . to . reverted
581
+
582
+ const encodedData = sbtImplementationB
583
+ . connect ( signers . minterUpdater )
584
+ . interface . encodeFunctionData ( 'initialize' , [
585
+ signers . minterUpdater . address ,
586
+ [
587
+ signers . minterA . address ,
588
+ signers . minterB . address ,
589
+ ]
590
+ ] )
591
+ await expect (
592
+ sbtProxy
593
+ . connect ( signers . proxyAdminB )
594
+ . upgradeToAndCall ( sbtImplementationB . address , encodedData )
595
+ ) . to . revertedWith (
596
+ `function selector was not recognized and there's no fallback function`
597
+ )
598
+ await expect ( sbt . connect ( signers . userA ) . initialize ( signers . minterUpdater . address , [
599
+ signers . minterA . address ,
600
+ signers . minterB . address ,
601
+ ] ) ) . to . not . reverted
602
+ await expect ( sbt . connect ( signers . userA ) . initialize ( signers . minterUpdater . address , [
603
+ signers . minterA . address ,
604
+ signers . minterB . address ,
605
+ ] ) ) . to . revertedWith ( 'Initializable: contract is already initialized' )
606
+
607
+ await expect (
608
+ sbtProxy
609
+ . connect ( signers . deployer )
610
+ . upgradeTo ( sbtImplementationB . address )
611
+ ) . to . revertedWith (
612
+ `function selector was not recognized and there's no fallback function`
613
+ )
614
+ await expect (
615
+ sbtProxy . connect ( signers . userA ) . upgradeTo ( sbtImplementationB . address )
616
+ ) . to . revertedWith (
617
+ `function selector was not recognized and there's no fallback function`
618
+ )
619
+ await expect (
620
+ sbtProxy . connect ( signers . userB ) . upgradeTo ( sbtImplementationB . address )
621
+ ) . to . revertedWith (
622
+ `function selector was not recognized and there's no fallback function`
623
+ )
624
+ await expect (
625
+ sbtProxy
626
+ . connect ( signers . minterUpdater )
627
+ . upgradeTo ( sbtImplementationB . address )
628
+ ) . to . revertedWith (
629
+ `function selector was not recognized and there's no fallback function`
630
+ )
631
+ await expect (
632
+ sbtProxy
633
+ . connect ( signers . minterA )
634
+ . upgradeTo ( sbtImplementationB . address )
635
+ ) . to . revertedWith (
636
+ `function selector was not recognized and there's no fallback function`
637
+ )
638
+ await expect (
639
+ sbtProxy
640
+ . connect ( signers . minterB )
641
+ . upgradeTo ( sbtImplementationB . address )
642
+ ) . to . revertedWith (
643
+ `function selector was not recognized and there's no fallback function`
644
+ )
645
+ await expect (
646
+ sbtProxy
647
+ . connect ( signers . minterC )
648
+ . upgradeTo ( sbtImplementationB . address )
649
+ ) . to . revertedWith (
650
+ `function selector was not recognized and there's no fallback function`
651
+ )
652
+
653
+ expect (
654
+ await sbtProxy . connect ( signers . proxyAdmin ) . callStatic . implementation ( )
655
+ ) . to . eq ( sbtImplementation . address )
656
+ await expect (
657
+ sbtProxy . connect ( signers . proxyAdminB ) . callStatic . implementation ( )
658
+ ) . to . reverted
659
+ await expect (
660
+ sbtProxy . connect ( signers . userA ) . callStatic . implementation ( )
661
+ ) . to . reverted
662
+ await expect (
663
+ sbtProxy . connect ( signers . userB ) . callStatic . implementation ( )
664
+ ) . to . reverted
665
+ await expect (
666
+ sbtProxy . connect ( signers . minterUpdater ) . callStatic . implementation ( )
667
+ ) . to . reverted
668
+ await expect (
669
+ sbtProxy . connect ( signers . minterA ) . callStatic . implementation ( )
670
+ ) . to . reverted
671
+ await expect (
672
+ sbtProxy . connect ( signers . minterB ) . callStatic . implementation ( )
673
+ ) . to . reverted
674
+ await expect (
675
+ sbtProxy . connect ( signers . minterC ) . callStatic . implementation ( )
676
+ ) . to . reverted
677
+ await expect (
678
+ sbtProxy . connect ( signers . deployer ) . callStatic . implementation ( )
679
+ ) . to . reverted
680
+ } )
681
+ } )
461
682
} )
462
683
463
684
describe ( '----SBT logic tests------------' , ( ) => {
0 commit comments