Skip to content

Commit ee63b2b

Browse files
committed
feat: update /epoch-routes with current_cardano_transactions_signing_config
1 parent 694734a commit ee63b2b

File tree

1 file changed

+122
-9
lines changed

1 file changed

+122
-9
lines changed

mithril-aggregator/src/http_server/routes/epoch_routes.rs

Lines changed: 122 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,42 @@ fn epoch_settings(
1515
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
1616
warp::path!("epoch-settings")
1717
.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))
1923
.and_then(handlers::epoch_settings)
2024
}
2125

2226
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};
2727
use std::convert::Infallible;
28+
29+
use slog_scope::{debug, warn};
2830
use warp::http::StatusCode;
2931

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+
3040
/// Epoch Settings
3141
pub async fn epoch_settings(
3242
epoch_service: EpochServiceWrapper,
43+
signed_entity_config: SignedEntityConfig,
44+
configuration: Configuration,
3345
) -> Result<impl warp::Reply, Infallible> {
3446
debug!("⇄ HTTP SERVER: epoch_settings");
3547
let epoch_service = epoch_service.read().await;
3648

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+
3754
match (
3855
epoch_service.epoch_of_current_data(),
3956
epoch_service.next_protocol_parameters(),
@@ -54,6 +71,7 @@ mod handlers {
5471
next_protocol_parameters: next_protocol_parameters.clone(),
5572
current_signers: SignerMessagePart::from_signers(current_signers.to_vec()),
5673
next_signers: SignerMessagePart::from_signers(next_signers.to_vec()),
74+
current_cardano_transactions_signing_config,
5775
};
5876
Ok(reply::json(&epoch_settings_message, StatusCode::OK))
5977
}
@@ -71,15 +89,21 @@ mod handlers {
7189

7290
#[cfg(test)]
7391
mod tests {
74-
use mithril_common::{
75-
entities::Epoch,
76-
test_utils::{apispec::APISpec, MithrilFixtureBuilder},
77-
};
92+
use std::collections::BTreeSet;
93+
7894
use serde_json::Value::Null;
7995
use tokio::sync::RwLock;
8096
use warp::http::{Method, StatusCode};
8197
use warp::test::request;
8298

99+
use mithril_common::{
100+
entities::{
101+
BlockNumber, CardanoTransactionsSigningConfig, Epoch, SignedEntityTypeDiscriminants,
102+
},
103+
messages::EpochSettingsMessage,
104+
test_utils::{apispec::APISpec, MithrilFixtureBuilder},
105+
};
106+
83107
use crate::http_server::SERVER_BASE_PATH;
84108
use crate::initialize_dependencies;
85109
use crate::services::FakeEpochService;
@@ -126,6 +150,95 @@ mod tests {
126150
.unwrap();
127151
}
128152

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+
129242
#[tokio::test]
130243
async fn test_epoch_settings_get_ko_500() {
131244
let method = Method::GET.as_str();

0 commit comments

Comments
 (0)