|
| 1 | +use crate::{interface::MithrilNetworkConfigurationProvider, model::MithrilNetworkConfiguration}; |
| 2 | +use async_trait::async_trait; |
| 3 | +use mithril_common::StdResult; |
| 4 | + |
| 5 | +/// A fake [MithrilNetworkConfigurationProvider] that return [MithrilNetworkConfiguration] |
| 6 | +pub struct FakeMithrilNetworkConfigurationProvider { |
| 7 | + configuration: MithrilNetworkConfiguration, |
| 8 | +} |
| 9 | + |
| 10 | +impl FakeMithrilNetworkConfigurationProvider { |
| 11 | + /// Create a new [FakeMithrilNetworkConfigurationProvider] |
| 12 | + pub fn from_mithril_network_configuration(configuration: MithrilNetworkConfiguration) -> Self { |
| 13 | + Self { configuration } |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +#[cfg_attr(target_family = "wasm", async_trait(?Send))] |
| 18 | +#[cfg_attr(not(target_family = "wasm"), async_trait)] |
| 19 | +impl MithrilNetworkConfigurationProvider for FakeMithrilNetworkConfigurationProvider { |
| 20 | + async fn get(&self) -> StdResult<MithrilNetworkConfiguration> { |
| 21 | + Ok(self.configuration.clone()) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +#[cfg(test)] |
| 26 | +mod tests { |
| 27 | + use std::collections::{BTreeSet, HashMap}; |
| 28 | + |
| 29 | + use mithril_common::{ |
| 30 | + StdResult, |
| 31 | + entities::{BlockNumber, CardanoTransactionsSigningConfig, SignedEntityTypeDiscriminants}, |
| 32 | + }; |
| 33 | + |
| 34 | + use super::*; |
| 35 | + use crate::{model::SignedEntityTypeConfiguration, test::double::fake_data}; |
| 36 | + |
| 37 | + #[tokio::test] |
| 38 | + async fn fake_mithril_network_configuration_provider_returns_configuration() -> StdResult<()> { |
| 39 | + let mut available_signed_entity_types = BTreeSet::new(); |
| 40 | + available_signed_entity_types.insert(SignedEntityTypeDiscriminants::CardanoTransactions); |
| 41 | + |
| 42 | + let mut signed_entity_types_config = HashMap::new(); |
| 43 | + signed_entity_types_config.insert( |
| 44 | + SignedEntityTypeDiscriminants::CardanoTransactions, |
| 45 | + SignedEntityTypeConfiguration::CardanoTransactions(CardanoTransactionsSigningConfig { |
| 46 | + security_parameter: BlockNumber(13), |
| 47 | + step: BlockNumber(26), |
| 48 | + }), |
| 49 | + ); |
| 50 | + |
| 51 | + let configuration = fake_data::mithril_network_configuration( |
| 52 | + 42, |
| 53 | + 1, |
| 54 | + 2, |
| 55 | + 0.123, |
| 56 | + available_signed_entity_types, |
| 57 | + signed_entity_types_config, |
| 58 | + ); |
| 59 | + let provider = FakeMithrilNetworkConfigurationProvider::from_mithril_network_configuration( |
| 60 | + configuration.clone(), |
| 61 | + ); |
| 62 | + |
| 63 | + let retrieved_configuration = provider.get().await?; |
| 64 | + |
| 65 | + assert_eq!(configuration, retrieved_configuration); |
| 66 | + Ok(()) |
| 67 | + } |
| 68 | +} |
0 commit comments