@@ -15,25 +15,42 @@ fn epoch_settings(
15
15
) -> impl Filter < Extract = ( impl warp:: Reply , ) , Error = warp:: Rejection > + Clone {
16
16
warp:: path!( "epoch-settings" )
17
17
. and ( warp:: get ( ) )
18
- . and ( middlewares:: with_epoch_service ( dependency_manager) )
18
+ . and ( middlewares:: with_epoch_service ( dependency_manager. clone ( ) ) )
19
+ . and ( middlewares:: with_signed_entity_config (
20
+ dependency_manager. clone ( ) ,
21
+ ) )
22
+ . and ( middlewares:: with_config ( dependency_manager) )
19
23
. and_then ( handlers:: epoch_settings)
20
24
}
21
25
22
26
mod handlers {
23
- use crate :: dependency_injection:: EpochServiceWrapper ;
24
- use crate :: http_server:: routes:: reply;
25
- use mithril_common:: messages:: { EpochSettingsMessage , SignerMessagePart } ;
26
- use slog_scope:: { debug, warn} ;
27
27
use std:: convert:: Infallible ;
28
+
29
+ use slog_scope:: { debug, warn} ;
28
30
use warp:: http:: StatusCode ;
29
31
32
+ use mithril_common:: {
33
+ entities:: { SignedEntityConfig , SignedEntityTypeDiscriminants } ,
34
+ messages:: { EpochSettingsMessage , SignerMessagePart } ,
35
+ } ;
36
+
37
+ use crate :: http_server:: routes:: reply;
38
+ use crate :: { dependency_injection:: EpochServiceWrapper , Configuration } ;
39
+
30
40
/// Epoch Settings
31
41
pub async fn epoch_settings (
32
42
epoch_service : EpochServiceWrapper ,
43
+ signed_entity_config : SignedEntityConfig ,
44
+ configuration : Configuration ,
33
45
) -> Result < impl warp:: Reply , Infallible > {
34
46
debug ! ( "⇄ HTTP SERVER: epoch_settings" ) ;
35
47
let epoch_service = epoch_service. read ( ) . await ;
36
48
49
+ let current_cardano_transactions_signing_config = signed_entity_config
50
+ . list_allowed_signed_entity_types_discriminants ( )
51
+ . contains ( & SignedEntityTypeDiscriminants :: CardanoTransactions )
52
+ . then_some ( configuration. cardano_transactions_signing_config ) ;
53
+
37
54
match (
38
55
epoch_service. epoch_of_current_data ( ) ,
39
56
epoch_service. next_protocol_parameters ( ) ,
@@ -54,6 +71,7 @@ mod handlers {
54
71
next_protocol_parameters : next_protocol_parameters. clone ( ) ,
55
72
current_signers : SignerMessagePart :: from_signers ( current_signers. to_vec ( ) ) ,
56
73
next_signers : SignerMessagePart :: from_signers ( next_signers. to_vec ( ) ) ,
74
+ current_cardano_transactions_signing_config,
57
75
} ;
58
76
Ok ( reply:: json ( & epoch_settings_message, StatusCode :: OK ) )
59
77
}
@@ -71,15 +89,21 @@ mod handlers {
71
89
72
90
#[ cfg( test) ]
73
91
mod tests {
74
- use mithril_common:: {
75
- entities:: Epoch ,
76
- test_utils:: { apispec:: APISpec , MithrilFixtureBuilder } ,
77
- } ;
92
+ use std:: collections:: BTreeSet ;
93
+
78
94
use serde_json:: Value :: Null ;
79
95
use tokio:: sync:: RwLock ;
80
96
use warp:: http:: { Method , StatusCode } ;
81
97
use warp:: test:: request;
82
98
99
+ use mithril_common:: {
100
+ entities:: {
101
+ BlockNumber , CardanoTransactionsSigningConfig , Epoch , SignedEntityTypeDiscriminants ,
102
+ } ,
103
+ messages:: EpochSettingsMessage ,
104
+ test_utils:: { apispec:: APISpec , MithrilFixtureBuilder } ,
105
+ } ;
106
+
83
107
use crate :: http_server:: SERVER_BASE_PATH ;
84
108
use crate :: initialize_dependencies;
85
109
use crate :: services:: FakeEpochService ;
@@ -126,6 +150,95 @@ mod tests {
126
150
. unwrap ( ) ;
127
151
}
128
152
153
+ #[ tokio:: test]
154
+ async fn test_epoch_settings_get_ok_with_cardano_transactions_enabled ( ) {
155
+ let method = Method :: GET . as_str ( ) ;
156
+ let path = "/epoch-settings" ;
157
+ let mut dependency_manager = initialize_dependencies ( ) . await ;
158
+ let fixture = MithrilFixtureBuilder :: default ( ) . with_signers ( 5 ) . build ( ) ;
159
+ let epoch_service = FakeEpochService :: from_fixture ( Epoch ( 5 ) , & fixture) ;
160
+ dependency_manager. epoch_service = Arc :: new ( RwLock :: new ( epoch_service) ) ;
161
+ dependency_manager
162
+ . signed_entity_config
163
+ . allowed_discriminants =
164
+ BTreeSet :: from ( [ SignedEntityTypeDiscriminants :: CardanoTransactions ] ) ;
165
+ let signing_config = CardanoTransactionsSigningConfig {
166
+ security_parameter : BlockNumber ( 70 ) ,
167
+ step : BlockNumber ( 15 ) ,
168
+ } ;
169
+ dependency_manager
170
+ . config
171
+ . cardano_transactions_signing_config = signing_config. clone ( ) ;
172
+
173
+ let response = request ( )
174
+ . method ( method)
175
+ . path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
176
+ . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
177
+ . await ;
178
+
179
+ let response_body: EpochSettingsMessage = serde_json:: from_slice ( response. body ( ) ) . unwrap ( ) ;
180
+
181
+ assert_eq ! (
182
+ response_body. current_cardano_transactions_signing_config,
183
+ Some ( signing_config)
184
+ ) ;
185
+
186
+ APISpec :: verify_conformity (
187
+ APISpec :: get_all_spec_files ( ) ,
188
+ method,
189
+ path,
190
+ "application/json" ,
191
+ & Null ,
192
+ & response,
193
+ & StatusCode :: OK ,
194
+ )
195
+ . unwrap ( ) ;
196
+ }
197
+
198
+ #[ tokio:: test]
199
+ async fn test_epoch_settings_get_ok_with_cardano_transactions_not_enabled ( ) {
200
+ let method = Method :: GET . as_str ( ) ;
201
+ let path = "/epoch-settings" ;
202
+ let mut dependency_manager = initialize_dependencies ( ) . await ;
203
+ let fixture = MithrilFixtureBuilder :: default ( ) . with_signers ( 5 ) . build ( ) ;
204
+ let epoch_service = FakeEpochService :: from_fixture ( Epoch ( 5 ) , & fixture) ;
205
+ dependency_manager. epoch_service = Arc :: new ( RwLock :: new ( epoch_service) ) ;
206
+ dependency_manager
207
+ . signed_entity_config
208
+ . allowed_discriminants = BTreeSet :: new ( ) ;
209
+ let signing_config = CardanoTransactionsSigningConfig {
210
+ security_parameter : BlockNumber ( 70 ) ,
211
+ step : BlockNumber ( 15 ) ,
212
+ } ;
213
+ dependency_manager
214
+ . config
215
+ . cardano_transactions_signing_config = signing_config. clone ( ) ;
216
+
217
+ let response = request ( )
218
+ . method ( method)
219
+ . path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
220
+ . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
221
+ . await ;
222
+
223
+ let response_body: EpochSettingsMessage = serde_json:: from_slice ( response. body ( ) ) . unwrap ( ) ;
224
+
225
+ assert_eq ! (
226
+ response_body. current_cardano_transactions_signing_config,
227
+ None
228
+ ) ;
229
+
230
+ APISpec :: verify_conformity (
231
+ APISpec :: get_all_spec_files ( ) ,
232
+ method,
233
+ path,
234
+ "application/json" ,
235
+ & Null ,
236
+ & response,
237
+ & StatusCode :: OK ,
238
+ )
239
+ . unwrap ( ) ;
240
+ }
241
+
129
242
#[ tokio:: test]
130
243
async fn test_epoch_settings_get_ko_500 ( ) {
131
244
let method = Method :: GET . as_str ( ) ;
0 commit comments