@@ -507,6 +507,7 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
507
507
var tokenConfigFactory ;
508
508
509
509
var alternativeTokenConfig ;
510
+ var alternativeTokenConfig2 ;
510
511
511
512
var oracleStub1 ;
512
513
var oracleStub2 ;
@@ -519,6 +520,8 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
519
520
520
521
var newAggregationStrategy ;
521
522
var newValidationStrategy ;
523
+ var newAggregationStrategy2 ;
524
+ var newValidationStrategy2 ;
522
525
523
526
beforeEach ( async function ( ) {
524
527
const aggregatorDeployment = await deployFunction ( ) ;
@@ -549,7 +552,9 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
549
552
DEFAULT_AGGREGATION_STRATEGY_BYTECODE
550
553
) ;
551
554
newAggregationStrategy = await aggregationStrategyFactory . deploy ( newAveragingStrategy . address ) ;
555
+ newAggregationStrategy2 = await aggregationStrategyFactory . deploy ( newAveragingStrategy . address ) ;
552
556
await newAggregationStrategy . deployed ( ) ;
557
+ await newAggregationStrategy2 . deployed ( ) ;
553
558
554
559
const validationStrategyFactory = await ethers . getContractFactory (
555
560
DEFAULT_VALIDATION_STRATEGY_ABI ,
@@ -562,7 +567,15 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
562
567
1 ,
563
568
100000
564
569
) ;
570
+ newValidationStrategy2 = await validationStrategyFactory . deploy (
571
+ DEFAULT_QUOTE_TOKEN_DECIMALS ,
572
+ 0 ,
573
+ 0 ,
574
+ 1 ,
575
+ 100000
576
+ ) ;
565
577
await newValidationStrategy . deployed ( ) ;
578
+ await newValidationStrategy2 . deployed ( ) ;
566
579
567
580
const oracleStubFactory = await ethers . getContractFactory ( "MockOracle" ) ;
568
581
oracleStub1 = await oracleStubFactory . deploy ( DEFAULT_QUOTE_TOKEN_ADDRESS , DEFAULT_LIQUIDITY_DECIMALS ) ;
@@ -589,6 +602,12 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
589
602
2 ,
590
603
[ oracleStub1 . address , oracleStub2 . address ]
591
604
) ;
605
+ alternativeTokenConfig2 = await tokenConfigFactory . deploy (
606
+ newAggregationStrategy2 . address ,
607
+ newValidationStrategy2 . address ,
608
+ 3 ,
609
+ [ oracleStub1 . address , oracleStub2 . address , oracleStub3 . address ]
610
+ ) ;
592
611
} ) ;
593
612
594
613
it ( "Overrides the default config" , async function ( ) {
@@ -612,6 +631,111 @@ function describeManagedAggregatorOracleTests(contractName, deployFunction) {
612
631
expect ( await oracle . getOracles ( GRT ) ) . to . not . have . lengthOf ( 1 ) ;
613
632
} ) ;
614
633
634
+ it ( "Changes the default config" , async function ( ) {
635
+ const tx = await oracle . setTokenConfig ( ethers . constants . AddressZero , alternativeTokenConfig . address ) ;
636
+ const receipt = await tx . wait ( ) ;
637
+
638
+ expect ( receipt )
639
+ . to . emit ( oracle , "TokenConfigUpdated" )
640
+ . withArgs ( ethers . constants . AddressZero , ethers . constants . AddressZero , alternativeTokenConfig . address ) ;
641
+
642
+ // Check that the functions return the new values
643
+ expect ( await oracle . aggregationStrategy ( WETH ) ) . to . equal ( await alternativeTokenConfig . aggregationStrategy ( ) ) ;
644
+ expect ( await oracle . validationStrategy ( WETH ) ) . to . equal ( await alternativeTokenConfig . validationStrategy ( ) ) ;
645
+ expect ( await oracle . minimumResponses ( WETH ) ) . to . equal ( await alternativeTokenConfig . minimumResponses ( ) ) ;
646
+ expect ( await oracle . getOracles ( WETH ) ) . to . eql ( await alternativeTokenConfig . oracles ( ) ) ; // eql = deep equality
647
+
648
+ // Sanity check that the functions return values other than the default
649
+ expect ( await oracle . aggregationStrategy ( WETH ) ) . to . not . equal ( aggregationStrategy ) ;
650
+ expect ( await oracle . validationStrategy ( WETH ) ) . to . not . equal ( validationStrategy ) ;
651
+ expect ( await oracle . minimumResponses ( WETH ) ) . to . not . equal ( 1 ) ;
652
+ expect ( await oracle . getOracles ( WETH ) ) . to . not . have . lengthOf ( 1 ) ;
653
+ } ) ;
654
+
655
+ it ( "Changing the default config does not affect the token-specific config" , async function ( ) {
656
+ // Set a token-specific config
657
+ const tx = await oracle . setTokenConfig ( WETH , alternativeTokenConfig2 . address ) ;
658
+ const receipt = await tx . wait ( ) ;
659
+
660
+ expect ( receipt )
661
+ . to . emit ( oracle , "TokenConfigUpdated" )
662
+ . withArgs ( WETH , ethers . constants . AddressZero , alternativeTokenConfig2 . address ) ;
663
+
664
+ // Check that the functions return the new values
665
+ expect ( await oracle . aggregationStrategy ( WETH ) ) . to . equal (
666
+ await alternativeTokenConfig2 . aggregationStrategy ( )
667
+ ) ;
668
+ expect ( await oracle . validationStrategy ( WETH ) ) . to . equal ( await alternativeTokenConfig2 . validationStrategy ( ) ) ;
669
+ expect ( await oracle . minimumResponses ( WETH ) ) . to . equal ( await alternativeTokenConfig2 . minimumResponses ( ) ) ;
670
+ expect ( await oracle . getOracles ( WETH ) ) . to . eql ( await alternativeTokenConfig2 . oracles ( ) ) ; // eql = deep equality
671
+
672
+ // Change the default config
673
+ const tx2 = await oracle . setTokenConfig ( ethers . constants . AddressZero , alternativeTokenConfig . address ) ;
674
+ const receipt2 = await tx2 . wait ( ) ;
675
+
676
+ expect ( receipt2 )
677
+ . to . emit ( oracle , "TokenConfigUpdated" )
678
+ . withArgs ( ethers . constants . AddressZero , ethers . constants . AddressZero , alternativeTokenConfig . address ) ;
679
+
680
+ // Check that the token-specific config is still the same
681
+ expect ( await oracle . aggregationStrategy ( WETH ) ) . to . equal (
682
+ await alternativeTokenConfig2 . aggregationStrategy ( )
683
+ ) ;
684
+ expect ( await oracle . validationStrategy ( WETH ) ) . to . equal ( await alternativeTokenConfig2 . validationStrategy ( ) ) ;
685
+ expect ( await oracle . minimumResponses ( WETH ) ) . to . equal ( await alternativeTokenConfig2 . minimumResponses ( ) ) ;
686
+ expect ( await oracle . getOracles ( WETH ) ) . to . eql ( await alternativeTokenConfig2 . oracles ( ) ) ; // eql = deep equality
687
+ } ) ;
688
+
689
+ it ( "The config reverts to the default if the new config is the zero address" , async function ( ) {
690
+ // First set the config to something other than the default
691
+ const tx = await oracle . setTokenConfig ( GRT , alternativeTokenConfig . address ) ;
692
+ const receipt = await tx . wait ( ) ;
693
+ expect ( receipt )
694
+ . to . emit ( oracle , "TokenConfigUpdated" )
695
+ . withArgs ( GRT , ethers . constants . AddressZero , alternativeTokenConfig . address ) ;
696
+
697
+ // Then set the config to the zero address
698
+ const tx2 = await oracle . setTokenConfig ( GRT , ethers . constants . AddressZero ) ;
699
+ const receipt2 = await tx2 . wait ( ) ;
700
+ expect ( receipt2 )
701
+ . to . emit ( oracle , "TokenConfigUpdated" )
702
+ . withArgs ( GRT , alternativeTokenConfig . address , ethers . constants . AddressZero ) ;
703
+
704
+ expect ( await oracle . aggregationStrategy ( GRT ) ) . to . equal ( aggregationStrategy ) ;
705
+ expect ( await oracle . validationStrategy ( GRT ) ) . to . equal ( validationStrategy ) ;
706
+ expect ( await oracle . minimumResponses ( GRT ) ) . to . equal ( 1 ) ;
707
+ expect ( await oracle . getOracles ( GRT ) ) . to . have . lengthOf ( 1 ) ;
708
+ } ) ;
709
+
710
+ it ( "The config reverts to a new default if the new config is the zero address" , async function ( ) {
711
+ // Change the default config
712
+ const tx1 = await oracle . setTokenConfig ( ethers . constants . AddressZero , alternativeTokenConfig2 . address ) ;
713
+ const receipt1 = await tx1 . wait ( ) ;
714
+
715
+ expect ( receipt1 )
716
+ . to . emit ( oracle , "TokenConfigUpdated" )
717
+ . withArgs ( ethers . constants . AddressZero , ethers . constants . AddressZero , alternativeTokenConfig2 . address ) ;
718
+
719
+ // Set the config to something other than the default
720
+ const tx = await oracle . setTokenConfig ( GRT , alternativeTokenConfig . address ) ;
721
+ const receipt = await tx . wait ( ) ;
722
+ expect ( receipt )
723
+ . to . emit ( oracle , "TokenConfigUpdated" )
724
+ . withArgs ( GRT , ethers . constants . AddressZero , alternativeTokenConfig . address ) ;
725
+
726
+ // Then set the config to the zero address
727
+ const tx2 = await oracle . setTokenConfig ( GRT , ethers . constants . AddressZero ) ;
728
+ const receipt2 = await tx2 . wait ( ) ;
729
+ expect ( receipt2 )
730
+ . to . emit ( oracle , "TokenConfigUpdated" )
731
+ . withArgs ( GRT , alternativeTokenConfig . address , ethers . constants . AddressZero ) ;
732
+
733
+ expect ( await oracle . aggregationStrategy ( GRT ) ) . to . equal ( await alternativeTokenConfig2 . aggregationStrategy ( ) ) ;
734
+ expect ( await oracle . validationStrategy ( GRT ) ) . to . equal ( await alternativeTokenConfig2 . validationStrategy ( ) ) ;
735
+ expect ( await oracle . minimumResponses ( GRT ) ) . to . equal ( await alternativeTokenConfig2 . minimumResponses ( ) ) ;
736
+ expect ( await oracle . getOracles ( GRT ) ) . to . eql ( await alternativeTokenConfig2 . oracles ( ) ) ; // eql = deep equality
737
+ } ) ;
738
+
615
739
it ( "Works with 8 oracles" , async function ( ) {
616
740
const alternativeTokenConfigWith8Oracles = await tokenConfigFactory . deploy (
617
741
newAggregationStrategy . address ,
0 commit comments