@@ -391,6 +391,8 @@ impl MessageService for MithrilMessageService {
391391
392392#[ cfg( test) ]
393393mod tests {
394+ use std:: collections:: BTreeMap ;
395+
394396 use mithril_common:: entities:: { BlockNumber , CardanoDbBeacon , Certificate , SignedEntityType } ;
395397 use mithril_common:: test:: double:: { Dummy , fake_data} ;
396398 use tokio:: sync:: RwLock ;
@@ -400,13 +402,15 @@ mod tests {
400402 EpochSettingsStore , ImmutableFileDigestRepository , SignedEntityStore ,
401403 } ;
402404 use crate :: database:: test_helper:: main_db_connection;
405+ use crate :: entities:: AggregatorEpochSettings ;
403406 use crate :: services:: FakeEpochService ;
404407
405408 use super :: * ;
406409
407410 struct MessageServiceBuilder {
408411 certificates : Vec < Certificate > ,
409412 signed_entity_records : Vec < SignedEntityRecord > ,
413+ epoch_settings_map : BTreeMap < Epoch , AggregatorEpochSettings > ,
410414 immutable_file_digest_messages : Vec < CardanoDatabaseDigestListItemMessage > ,
411415 epoch_service : Option < FakeEpochService > ,
412416 }
@@ -416,6 +420,7 @@ mod tests {
416420 Self {
417421 certificates : Vec :: new ( ) ,
418422 signed_entity_records : Vec :: new ( ) ,
423+ epoch_settings_map : BTreeMap :: new ( ) ,
419424 immutable_file_digest_messages : Vec :: new ( ) ,
420425 epoch_service : None ,
421426 }
@@ -436,6 +441,15 @@ mod tests {
436441 self
437442 }
438443
444+ fn with_epoch_settings (
445+ mut self ,
446+ epoch_settings_map : BTreeMap < Epoch , AggregatorEpochSettings > ,
447+ ) -> Self {
448+ self . epoch_settings_map = epoch_settings_map;
449+
450+ self
451+ }
452+
439453 fn with_immutable_file_digest_messages (
440454 mut self ,
441455 digests : & [ CardanoDatabaseDigestListItemMessage ] ,
@@ -455,7 +469,7 @@ mod tests {
455469 let connection = Arc :: new ( main_db_connection ( ) . unwrap ( ) ) ;
456470 let certificate_repository = CertificateRepository :: new ( connection. clone ( ) ) ;
457471 let signed_entity_store = SignedEntityStore :: new ( connection. clone ( ) ) ;
458- let epoch_settings_storer = EpochSettingsStore :: new ( connection. clone ( ) , None ) ;
472+ let epoch_settings_store = EpochSettingsStore :: new ( connection. clone ( ) , None ) ;
459473 let immutable_file_digest_mapper =
460474 ImmutableFileDigestRepository :: new ( connection. clone ( ) ) ;
461475 let epoch_service = self . epoch_service . unwrap_or ( FakeEpochService :: without_data ( ) ) ;
@@ -468,6 +482,13 @@ mod tests {
468482 signed_entity_store. store_signed_entity ( & record) . await . unwrap ( ) ;
469483 }
470484
485+ for ( epoch, epoch_settings) in self . epoch_settings_map {
486+ epoch_settings_store
487+ . save_epoch_settings ( epoch, epoch_settings)
488+ . await
489+ . unwrap ( ) ;
490+ }
491+
471492 for digest_message in self . immutable_file_digest_messages {
472493 immutable_file_digest_mapper
473494 . upsert_immutable_file_digest (
@@ -481,7 +502,7 @@ mod tests {
481502 MithrilMessageService :: new (
482503 Arc :: new ( certificate_repository) ,
483504 Arc :: new ( signed_entity_store) ,
484- Arc :: new ( epoch_settings_storer ) ,
505+ Arc :: new ( epoch_settings_store ) ,
485506 Arc :: new ( immutable_file_digest_mapper) ,
486507 Arc :: new ( RwLock :: new ( epoch_service) ) ,
487508 )
@@ -645,6 +666,154 @@ mod tests {
645666 }
646667 }
647668
669+ mod protocol_configuration {
670+ use mithril_common:: entities:: { CardanoTransactionsSigningConfig , ProtocolParameters } ;
671+
672+ use crate :: entities:: AggregatorEpochSettings ;
673+
674+ use super :: * ;
675+
676+ #[ tokio:: test]
677+ async fn get_protocol_configuration_message ( ) {
678+ let epoch = Epoch ( 4 ) ;
679+ let aggregator_epoch_settings = AggregatorEpochSettings {
680+ protocol_parameters : ProtocolParameters :: new ( 5 , 100 , 0.65 ) ,
681+ cardano_transactions_signing_config : CardanoTransactionsSigningConfig {
682+ security_parameter : BlockNumber ( 0 ) ,
683+ step : BlockNumber ( 15 ) ,
684+ } ,
685+ } ;
686+ let message_service = MessageServiceBuilder :: new ( )
687+ . with_epoch_settings ( BTreeMap :: from ( [ ( epoch, aggregator_epoch_settings) ] ) )
688+ . build ( )
689+ . await ;
690+
691+ let message = message_service
692+ . get_protocol_configuration_message ( epoch, SignedEntityTypeDiscriminants :: all ( ) )
693+ . await
694+ . unwrap ( )
695+ . expect ( "Protocol configuration message should exist." ) ;
696+
697+ assert_eq ! (
698+ message. protocol_parameters,
699+ ProtocolParameters :: new( 5 , 100 , 0.65 )
700+ ) ;
701+ assert_eq ! (
702+ message. cardano_transactions_signing_config,
703+ Some ( CardanoTransactionsSigningConfig {
704+ security_parameter: BlockNumber ( 0 ) ,
705+ step: BlockNumber ( 15 )
706+ } )
707+ ) ;
708+ assert_eq ! (
709+ message. available_signed_entity_types,
710+ SignedEntityTypeDiscriminants :: all( )
711+ ) ;
712+ }
713+
714+ #[ tokio:: test]
715+ async fn get_protocol_configuration_message_with_multiple_epochs_settings_stored ( ) {
716+ let message_service = MessageServiceBuilder :: new ( )
717+ . with_epoch_settings ( BTreeMap :: from ( [
718+ (
719+ Epoch ( 7 ) ,
720+ AggregatorEpochSettings {
721+ protocol_parameters : ProtocolParameters :: new ( 1 , 10 , 0.11 ) ,
722+ ..Dummy :: dummy ( )
723+ } ,
724+ ) ,
725+ (
726+ Epoch ( 8 ) ,
727+ AggregatorEpochSettings {
728+ protocol_parameters : ProtocolParameters :: new ( 2 , 20 , 0.22 ) ,
729+ ..Dummy :: dummy ( )
730+ } ,
731+ ) ,
732+ (
733+ Epoch ( 9 ) ,
734+ AggregatorEpochSettings {
735+ protocol_parameters : ProtocolParameters :: new ( 3 , 30 , 0.33 ) ,
736+ ..Dummy :: dummy ( )
737+ } ,
738+ ) ,
739+ ] ) )
740+ . build ( )
741+ . await ;
742+
743+ let message = message_service
744+ . get_protocol_configuration_message ( Epoch ( 8 ) , SignedEntityTypeDiscriminants :: all ( ) )
745+ . await
746+ . unwrap ( )
747+ . expect ( "Protocol configuration message should exist." ) ;
748+
749+ assert_eq ! (
750+ message. protocol_parameters,
751+ ProtocolParameters :: new( 2 , 20 , 0.22 )
752+ ) ;
753+ }
754+
755+ #[ tokio:: test]
756+ async fn get_protocol_configuration_message_with_cardano_transactions_enabled ( ) {
757+ let epoch = Epoch ( 4 ) ;
758+ let message_service = MessageServiceBuilder :: new ( )
759+ . with_epoch_settings ( BTreeMap :: from ( [ ( epoch, AggregatorEpochSettings :: dummy ( ) ) ] ) )
760+ . build ( )
761+ . await ;
762+
763+ let message = message_service
764+ . get_protocol_configuration_message (
765+ epoch,
766+ BTreeSet :: from ( [ SignedEntityTypeDiscriminants :: CardanoTransactions ] ) ,
767+ )
768+ . await
769+ . unwrap ( )
770+ . expect ( "Protocol configuration message should exist." ) ;
771+
772+ assert ! ( message. cardano_transactions_signing_config. is_some( ) ) ;
773+ }
774+
775+ #[ tokio:: test]
776+ async fn get_protocol_configuration_message_without_cardano_transactions_does_not_return_signing_config ( )
777+ {
778+ let epoch = Epoch ( 4 ) ;
779+ let message_service = MessageServiceBuilder :: new ( )
780+ . with_epoch_settings ( BTreeMap :: from ( [ ( epoch, AggregatorEpochSettings :: dummy ( ) ) ] ) )
781+ . build ( )
782+ . await ;
783+
784+ let message = message_service
785+ . get_protocol_configuration_message ( epoch, BTreeSet :: new ( ) )
786+ . await
787+ . unwrap ( )
788+ . expect ( "Protocol configuration message should exist." ) ;
789+
790+ assert_eq ! ( message. cardano_transactions_signing_config, None ) ;
791+ }
792+
793+ #[ tokio:: test]
794+ async fn get_protocol_configuration_message_return_none_if_epoch_not_found ( ) {
795+ let epoch_number = 7 ;
796+ let epoch_without_correspondence = epoch_number + 42 ;
797+ let message_service = MessageServiceBuilder :: new ( )
798+ . with_epoch_settings ( BTreeMap :: from ( [ (
799+ Epoch ( epoch_number) ,
800+ AggregatorEpochSettings :: dummy ( ) ,
801+ ) ] ) )
802+ . build ( )
803+ . await ;
804+
805+ let message = message_service
806+ . get_protocol_configuration_message (
807+ Epoch ( epoch_without_correspondence) ,
808+ SignedEntityTypeDiscriminants :: all ( ) ,
809+ )
810+ . await
811+ . unwrap ( ) ;
812+
813+ assert_eq ! ( message, None ) ;
814+ }
815+ }
816+
648817 mod certificate {
649818 use super :: * ;
650819
0 commit comments