@@ -567,6 +567,61 @@ func TestReduceAggregator_Aggregate(t *testing.T) {
567567 },
568568 expectedState : map [string ]any {"Price" : int64 (1 )},
569569 },
570+ {
571+ name : "handle nils gracefully" ,
572+ fields : []aggregators.AggregationField {
573+ {
574+ InputKey : "FeedID" ,
575+ OutputKey : "FeedID" ,
576+ Method : "mode" ,
577+ },
578+ {
579+ InputKey : "BenchmarkPrice" ,
580+ OutputKey : "Price" ,
581+ Method : "median" ,
582+ DeviationString : "10" ,
583+ DeviationType : "percent" ,
584+ },
585+ {
586+ InputKey : "Timestamp" ,
587+ OutputKey : "Timestamp" ,
588+ Method : "median" ,
589+ DeviationString : "100" ,
590+ DeviationType : "absolute" ,
591+ },
592+ },
593+ extraConfig : map [string ]any {},
594+ observationsFactory : func () map [commontypes.OracleID ][]values.Value {
595+ mockValue , err := values .WrapMap (map [string ]any {
596+ "FeedID" : idABytes [:],
597+ "BenchmarkPrice" : uint64 (100 ),
598+ "Timestamp" : 12341414929 ,
599+ })
600+ require .NoError (t , err )
601+ mockValueWithNil , err := values .WrapMap (map [string ]any {
602+ "FeedID" : idABytes [:],
603+ "BenchmarkPrice" : uint64 (100 ),
604+ "Timestamp" : 12341414929 ,
605+ })
606+ mockValueWithNil .Underlying ["BenchmarkPrice" ] = nil // simulate failed wraping of uint64
607+ return map [commontypes.OracleID ][]values.Value {1 : {mockValue }, 2 : {mockValue }, 3 : {mockValue }, 4 : {mockValueWithNil }}
608+ },
609+ shouldReport : true ,
610+ expectedOutcome : map [string ]any {
611+ "Reports" : []any {
612+ map [string ]any {
613+ "FeedID" : idABytes [:],
614+ "Timestamp" : int64 (12341414929 ),
615+ "Price" : uint64 (100 ),
616+ },
617+ },
618+ },
619+ expectedState : map [string ]any {
620+ "FeedID" : idABytes [:],
621+ "Timestamp" : int64 (12341414929 ),
622+ "Price" : uint64 (100 ),
623+ },
624+ },
570625 }
571626 for _ , tt := range cases {
572627 t .Run (tt .name , func (t * testing.T ) {
0 commit comments