@@ -262,19 +262,24 @@ impl Configuration {
262
262
pub fn list_allowed_signed_entity_types_discriminants (
263
263
& self ,
264
264
) -> StdResult < Vec < SignedEntityTypeDiscriminants > > {
265
- let mut signed_entity_types = Vec :: new ( ) ;
266
- signed_entity_types. push ( SignedEntityTypeDiscriminants :: MithrilStakeDistribution ) ;
267
- signed_entity_types. push ( SignedEntityTypeDiscriminants :: CardanoImmutableFilesFull ) ;
265
+ let default_discriminants = vec ! [
266
+ SignedEntityTypeDiscriminants :: MithrilStakeDistribution ,
267
+ SignedEntityTypeDiscriminants :: CardanoImmutableFilesFull ,
268
+ ] ;
269
+
270
+ let mut all_discriminants = default_discriminants;
268
271
269
272
let discriminant_names = self . signed_entity_types . clone ( ) . unwrap_or_default ( ) ;
270
- let mut signed_entity_types_appended = discriminant_names
273
+ for discriminant in discriminant_names
271
274
. split ( ',' )
272
275
. filter_map ( |name| SignedEntityTypeDiscriminants :: from_str ( name. trim ( ) ) . ok ( ) )
273
- . filter ( |signed_entity_type| !signed_entity_types. contains ( signed_entity_type) )
274
- . collect :: < Vec < _ > > ( ) ;
275
- signed_entity_types. append ( & mut signed_entity_types_appended) ;
276
+ {
277
+ if !all_discriminants. contains ( & discriminant) {
278
+ all_discriminants. push ( discriminant)
279
+ }
280
+ }
276
281
277
- Ok ( signed_entity_types )
282
+ Ok ( all_discriminants )
278
283
}
279
284
280
285
/// Create the deduplicated list of allowed signed entity types.
@@ -503,21 +508,15 @@ mod test {
503
508
}
504
509
505
510
#[ test]
506
- fn test_list_allowed_signed_entity_types_without_specific_configuration ( ) {
507
- let beacon = fake_data:: beacon ( ) ;
511
+ fn test_list_allowed_signed_entity_types_discriminant_without_specific_configuration ( ) {
508
512
let config = Configuration {
509
513
signed_entity_types : None ,
510
- network : beacon. network . clone ( ) ,
511
514
..Configuration :: new_sample ( )
512
515
} ;
513
- let time_point = TimePoint :: new ( * beacon. epoch , beacon. immutable_file_number ) ;
514
516
515
517
let discriminants = config
516
518
. list_allowed_signed_entity_types_discriminants ( )
517
519
. unwrap ( ) ;
518
- let signed_entity_types = config
519
- . list_allowed_signed_entity_types ( & time_point)
520
- . unwrap ( ) ;
521
520
522
521
assert_eq ! (
523
522
vec![
@@ -526,47 +525,122 @@ mod test {
526
525
] ,
527
526
discriminants
528
527
) ;
528
+ }
529
+
530
+ #[ test]
531
+ fn test_list_allowed_signed_entity_types_discriminant_should_not_return_unknown_signed_entity_types_in_configuration (
532
+ ) {
533
+ let config = Configuration {
534
+ signed_entity_types : Some ( "Unknown" . to_string ( ) ) ,
535
+ ..Configuration :: new_sample ( )
536
+ } ;
537
+
538
+ let discriminants = config
539
+ . list_allowed_signed_entity_types_discriminants ( )
540
+ . unwrap ( ) ;
541
+
529
542
assert_eq ! (
530
543
vec![
531
- SignedEntityType :: MithrilStakeDistribution ( beacon . epoch ) ,
532
- SignedEntityType :: CardanoImmutableFilesFull ( beacon . clone ( ) ) ,
544
+ SignedEntityTypeDiscriminants :: MithrilStakeDistribution ,
545
+ SignedEntityTypeDiscriminants :: CardanoImmutableFilesFull ,
533
546
] ,
534
- signed_entity_types
547
+ discriminants
535
548
) ;
536
549
}
537
550
538
551
#[ test]
539
- fn test_list_allowed_signed_entity_types_with_specific_configuration ( ) {
540
- let beacon = fake_data :: beacon ( ) ;
552
+ fn test_list_allowed_signed_entity_types_discriminant_should_not_duplicate_a_signed_entity_discriminant_type_already_in_default_ones (
553
+ ) {
541
554
let config = Configuration {
542
- network : beacon. network . clone ( ) ,
543
555
signed_entity_types : Some (
544
- "MithrilStakeDistribution,Unknown, CardanoStakeDistribution" . to_string ( ) ,
556
+ "CardanoImmutableFilesFull, MithrilStakeDistribution, CardanoImmutableFilesFull"
557
+ . to_string ( ) ,
545
558
) ,
546
559
..Configuration :: new_sample ( )
547
560
} ;
548
- let time_point = TimePoint :: new ( * beacon. epoch , beacon. immutable_file_number ) ;
549
561
550
562
let discriminants = config
551
563
. list_allowed_signed_entity_types_discriminants ( )
552
564
. unwrap ( ) ;
553
- let signed_entity_types = config
554
- . list_allowed_signed_entity_types ( & time_point)
565
+
566
+ assert_eq ! (
567
+ vec![
568
+ SignedEntityTypeDiscriminants :: MithrilStakeDistribution ,
569
+ SignedEntityTypeDiscriminants :: CardanoImmutableFilesFull ,
570
+ ] ,
571
+ discriminants
572
+ ) ;
573
+ }
574
+
575
+ #[ test]
576
+ fn test_list_allowed_signed_entity_types_discriminants_should_add_signed_entity_types_in_configuration_at_the_end (
577
+ ) {
578
+ let config = Configuration {
579
+ signed_entity_types : Some ( "CardanoStakeDistribution, CardanoTransactions" . to_string ( ) ) ,
580
+ ..Configuration :: new_sample ( )
581
+ } ;
582
+
583
+ let discriminants = config
584
+ . list_allowed_signed_entity_types_discriminants ( )
555
585
. unwrap ( ) ;
556
586
557
587
assert_eq ! (
558
588
vec![
559
589
SignedEntityTypeDiscriminants :: MithrilStakeDistribution ,
560
590
SignedEntityTypeDiscriminants :: CardanoImmutableFilesFull ,
561
591
SignedEntityTypeDiscriminants :: CardanoStakeDistribution ,
592
+ SignedEntityTypeDiscriminants :: CardanoTransactions ,
562
593
] ,
563
594
discriminants
564
595
) ;
596
+ }
597
+
598
+ #[ test]
599
+ fn test_list_allowed_signed_entity_types_discriminants_with_multiple_identical_signed_entity_types_in_configuration_should_not_be_added_several_times (
600
+ ) {
601
+ let config = Configuration {
602
+ signed_entity_types : Some (
603
+ "CardanoStakeDistribution, CardanoStakeDistribution, CardanoStakeDistribution"
604
+ . to_string ( ) ,
605
+ ) ,
606
+ ..Configuration :: new_sample ( )
607
+ } ;
608
+
609
+ let discriminants = config
610
+ . list_allowed_signed_entity_types_discriminants ( )
611
+ . unwrap ( ) ;
612
+
613
+ assert_eq ! (
614
+ vec![
615
+ SignedEntityTypeDiscriminants :: MithrilStakeDistribution ,
616
+ SignedEntityTypeDiscriminants :: CardanoImmutableFilesFull ,
617
+ SignedEntityTypeDiscriminants :: CardanoStakeDistribution ,
618
+ ] ,
619
+ discriminants
620
+ ) ;
621
+ }
622
+
623
+ #[ test]
624
+ fn test_list_allowed_signed_entity_types_with_specific_configuration ( ) {
625
+ let beacon = fake_data:: beacon ( ) ;
626
+ let time_point = TimePoint :: new ( * beacon. epoch , beacon. immutable_file_number ) ;
627
+
628
+ let config = Configuration {
629
+ network : beacon. network . clone ( ) ,
630
+ signed_entity_types : Some ( "CardanoStakeDistribution, CardanoTransactions" . to_string ( ) ) ,
631
+ ..Configuration :: new_sample ( )
632
+ } ;
633
+
634
+ let signed_entity_types = config
635
+ . list_allowed_signed_entity_types ( & time_point)
636
+ . unwrap ( ) ;
637
+
565
638
assert_eq ! (
566
639
vec![
567
640
SignedEntityType :: MithrilStakeDistribution ( beacon. epoch) ,
568
641
SignedEntityType :: CardanoImmutableFilesFull ( beacon. clone( ) ) ,
569
642
SignedEntityType :: CardanoStakeDistribution ( beacon. epoch) ,
643
+ SignedEntityType :: CardanoTransactions ( beacon. clone( ) ) ,
570
644
] ,
571
645
signed_entity_types
572
646
) ;
0 commit comments