@@ -4,32 +4,34 @@ use anyhow::Context;
4
4
use async_trait:: async_trait;
5
5
6
6
use mithril_common:: { StdResult , entities:: SignedEntityTypeDiscriminants } ;
7
+ use mithril_protocol_config:: interface:: MithrilNetworkConfigurationProvider ;
7
8
use mithril_signed_entity_preloader:: CardanoTransactionsPreloaderChecker ;
8
-
9
- use crate :: services:: AggregatorClient ;
10
-
11
9
/// CardanoTransactionsPreloaderActivationSigner
12
10
pub struct CardanoTransactionsPreloaderActivationSigner {
13
- aggregator_client : Arc < dyn AggregatorClient > ,
11
+ network_configuration_provider : Arc < dyn MithrilNetworkConfigurationProvider > ,
14
12
}
15
13
16
14
impl CardanoTransactionsPreloaderActivationSigner {
17
15
/// 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
+ }
20
22
}
21
23
}
22
24
23
25
#[ async_trait]
24
26
impl CardanoTransactionsPreloaderChecker for CardanoTransactionsPreloaderActivationSigner {
25
27
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 ( )
29
31
. await
30
- . with_context ( || "An error occurred while calling the Aggregator " ) ?;
32
+ . context ( "An error occurred while retrieving Mithril network configuration " ) ?;
31
33
32
- let activated_signed_entity_types = message . capabilities . signed_entity_types ;
34
+ let activated_signed_entity_types = configuration . available_signed_entity_types ;
33
35
34
36
Ok ( activated_signed_entity_types
35
37
. contains ( & SignedEntityTypeDiscriminants :: CardanoTransactions ) )
@@ -39,32 +41,38 @@ impl CardanoTransactionsPreloaderChecker for CardanoTransactionsPreloaderActivat
39
41
#[ cfg( test) ]
40
42
mod tests {
41
43
use anyhow:: anyhow;
44
+ use mithril_common:: { entities:: SignedEntityTypeDiscriminants , test:: double:: Dummy } ;
45
+ use mithril_protocol_config:: model:: MithrilNetworkConfiguration ;
46
+ use mockall:: mock;
42
47
use std:: collections:: BTreeSet ;
43
48
44
- use mithril_common:: {
45
- entities:: SignedEntityTypeDiscriminants , messages:: AggregatorFeaturesMessage ,
46
- test:: double:: Dummy ,
47
- } ;
49
+ use super :: * ;
48
50
49
- use crate :: services:: { AggregatorClientError , MockAggregatorClient } ;
51
+ mock ! {
52
+ pub MithrilNetworkConfigurationProvider { }
50
53
51
- use super :: * ;
54
+ #[ async_trait]
55
+ impl MithrilNetworkConfigurationProvider for MithrilNetworkConfigurationProvider {
56
+ async fn get( & self ) -> StdResult <MithrilNetworkConfiguration >;
57
+ }
58
+ }
52
59
53
60
#[ tokio:: test]
54
61
async fn preloader_activation_state_activate_preloader_when_cardano_transactions_not_in_aggregator_capabilities ( )
55
62
{
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
+ ) ) ;
68
76
69
77
let is_activated = preloader. is_activated ( ) . await . unwrap ( ) ;
70
78
@@ -74,18 +82,19 @@ mod tests {
74
82
#[ tokio:: test]
75
83
async fn preloader_activation_state_activate_preloader_when_cardano_transactions_in_aggregator_capabilities ( )
76
84
{
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
+ ) ) ;
89
98
90
99
let is_activated = preloader. is_activated ( ) . await . unwrap ( ) ;
91
100
@@ -94,17 +103,15 @@ mod tests {
94
103
95
104
#[ tokio:: test]
96
105
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 ( )
100
109
. 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
+ ) ) ;
108
115
109
116
preloader
110
117
. is_activated ( )
0 commit comments