@@ -4,32 +4,34 @@ use anyhow::Context;
44use async_trait:: async_trait;
55
66use mithril_common:: { StdResult , entities:: SignedEntityTypeDiscriminants } ;
7+ use mithril_protocol_config:: interface:: MithrilNetworkConfigurationProvider ;
78use mithril_signed_entity_preloader:: CardanoTransactionsPreloaderChecker ;
8-
9- use crate :: services:: AggregatorClient ;
10-
119/// CardanoTransactionsPreloaderActivationSigner
1210pub struct CardanoTransactionsPreloaderActivationSigner {
13- aggregator_client : Arc < dyn AggregatorClient > ,
11+ network_configuration_provider : Arc < dyn MithrilNetworkConfigurationProvider > ,
1412}
1513
1614impl CardanoTransactionsPreloaderActivationSigner {
1715 /// Create a new instance of `CardanoTransactionsPreloaderActivationSigner`
18- pub fn new ( aggregator_client : Arc < dyn AggregatorClient > ) -> Self {
19- Self { aggregator_client }
16+ pub fn new (
17+ network_configuration_provider : Arc < dyn MithrilNetworkConfigurationProvider > ,
18+ ) -> Self {
19+ Self {
20+ network_configuration_provider,
21+ }
2022 }
2123}
2224
2325#[ async_trait]
2426impl CardanoTransactionsPreloaderChecker for CardanoTransactionsPreloaderActivationSigner {
2527 async fn is_activated ( & self ) -> StdResult < bool > {
26- let message = self
27- . aggregator_client
28- . retrieve_aggregator_features ( )
28+ let configuration = self
29+ . network_configuration_provider
30+ . get ( )
2931 . await
30- . with_context ( || "An error occurred while calling the Aggregator " ) ?;
32+ . context ( "An error occurred while retrieving Mithril network configuration " ) ?;
3133
32- let activated_signed_entity_types = message . capabilities . signed_entity_types ;
34+ let activated_signed_entity_types = configuration . available_signed_entity_types ;
3335
3436 Ok ( activated_signed_entity_types
3537 . contains ( & SignedEntityTypeDiscriminants :: CardanoTransactions ) )
@@ -39,32 +41,38 @@ impl CardanoTransactionsPreloaderChecker for CardanoTransactionsPreloaderActivat
3941#[ cfg( test) ]
4042mod tests {
4143 use anyhow:: anyhow;
44+ use mithril_common:: { entities:: SignedEntityTypeDiscriminants , test:: double:: Dummy } ;
45+ use mithril_protocol_config:: model:: MithrilNetworkConfiguration ;
46+ use mockall:: mock;
4247 use std:: collections:: BTreeSet ;
4348
44- use mithril_common:: {
45- entities:: SignedEntityTypeDiscriminants , messages:: AggregatorFeaturesMessage ,
46- test:: double:: Dummy ,
47- } ;
49+ use super :: * ;
4850
49- use crate :: services:: { AggregatorClientError , MockAggregatorClient } ;
51+ mock ! {
52+ pub MithrilNetworkConfigurationProvider { }
5053
51- use super :: * ;
54+ #[ async_trait]
55+ impl MithrilNetworkConfigurationProvider for MithrilNetworkConfigurationProvider {
56+ async fn get( & self ) -> StdResult <MithrilNetworkConfiguration >;
57+ }
58+ }
5259
5360 #[ tokio:: test]
5461 async fn preloader_activation_state_activate_preloader_when_cardano_transactions_not_in_aggregator_capabilities ( )
5562 {
56- let mut aggregator_client = MockAggregatorClient :: new ( ) ;
57- aggregator_client
58- . expect_retrieve_aggregator_features ( )
59- . times ( 1 )
60- . returning ( || {
61- let mut message = AggregatorFeaturesMessage :: dummy ( ) ;
62- message. capabilities . signed_entity_types =
63- BTreeSet :: from ( [ SignedEntityTypeDiscriminants :: MithrilStakeDistribution ] ) ;
64- Ok ( message)
65- } ) ;
66- let preloader =
67- CardanoTransactionsPreloaderActivationSigner :: new ( Arc :: new ( aggregator_client) ) ;
63+ let mut network_configuration_provider = MockMithrilNetworkConfigurationProvider :: new ( ) ;
64+ network_configuration_provider. expect_get ( ) . times ( 1 ) . returning ( || {
65+ Ok ( MithrilNetworkConfiguration {
66+ available_signed_entity_types : BTreeSet :: from ( [
67+ SignedEntityTypeDiscriminants :: MithrilStakeDistribution ,
68+ ] ) ,
69+ ..Dummy :: dummy ( )
70+ } )
71+ } ) ;
72+
73+ let preloader = CardanoTransactionsPreloaderActivationSigner :: new ( Arc :: new (
74+ network_configuration_provider,
75+ ) ) ;
6876
6977 let is_activated = preloader. is_activated ( ) . await . unwrap ( ) ;
7078
@@ -74,18 +82,19 @@ mod tests {
7482 #[ tokio:: test]
7583 async fn preloader_activation_state_activate_preloader_when_cardano_transactions_in_aggregator_capabilities ( )
7684 {
77- let mut aggregator_client = MockAggregatorClient :: new ( ) ;
78- aggregator_client
79- . expect_retrieve_aggregator_features ( )
80- . times ( 1 )
81- . returning ( || {
82- let mut message = AggregatorFeaturesMessage :: dummy ( ) ;
83- message. capabilities . signed_entity_types =
84- BTreeSet :: from ( [ SignedEntityTypeDiscriminants :: CardanoTransactions ] ) ;
85- Ok ( message)
86- } ) ;
87- let preloader =
88- CardanoTransactionsPreloaderActivationSigner :: new ( Arc :: new ( aggregator_client) ) ;
85+ let mut network_configuration_provider = MockMithrilNetworkConfigurationProvider :: new ( ) ;
86+ network_configuration_provider. expect_get ( ) . times ( 1 ) . returning ( || {
87+ Ok ( MithrilNetworkConfiguration {
88+ available_signed_entity_types : BTreeSet :: from ( [
89+ SignedEntityTypeDiscriminants :: CardanoTransactions ,
90+ ] ) ,
91+ ..Dummy :: dummy ( )
92+ } )
93+ } ) ;
94+
95+ let preloader = CardanoTransactionsPreloaderActivationSigner :: new ( Arc :: new (
96+ network_configuration_provider,
97+ ) ) ;
8998
9099 let is_activated = preloader. is_activated ( ) . await . unwrap ( ) ;
91100
@@ -94,17 +103,15 @@ mod tests {
94103
95104 #[ tokio:: test]
96105 async fn preloader_activation_state_activate_preloader_when_aggregator_call_fails ( ) {
97- let mut aggregator_client = MockAggregatorClient :: new ( ) ;
98- aggregator_client
99- . expect_retrieve_aggregator_features ( )
106+ let mut network_configuration_provider = MockMithrilNetworkConfigurationProvider :: new ( ) ;
107+ network_configuration_provider
108+ . expect_get ( )
100109 . times ( 1 )
101- . returning ( || {
102- Err ( AggregatorClientError :: RemoteServerTechnical ( anyhow ! (
103- "Aggregator call failed"
104- ) ) )
105- } ) ;
106- let preloader =
107- CardanoTransactionsPreloaderActivationSigner :: new ( Arc :: new ( aggregator_client) ) ;
110+ . returning ( || Err ( anyhow ! ( "Aggregator call failure" ) ) ) ;
111+
112+ let preloader = CardanoTransactionsPreloaderActivationSigner :: new ( Arc :: new (
113+ network_configuration_provider,
114+ ) ) ;
108115
109116 preloader
110117 . is_activated ( )
0 commit comments