mithril_common/entities/
supported_era.rs

1use serde::{Deserialize, Serialize};
2use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
3
4/// The era that the software is running or will run
5#[derive(
6    Display, EnumString, EnumIter, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize,
7)]
8#[serde(rename_all = "lowercase")]
9#[strum(serialize_all = "lowercase")]
10pub enum SupportedEra {
11    /// Pythagoras era
12    Pythagoras,
13}
14
15impl SupportedEra {
16    /// Retrieve the list of supported eras
17    pub fn eras() -> Vec<Self> {
18        Self::iter().collect()
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use std::str::FromStr;
25
26    use crate::test::double::Dummy;
27
28    use super::*;
29
30    #[test]
31    fn correct_number_of_eras() {
32        let total_eras = SupportedEra::eras().len();
33
34        assert!(total_eras > 0);
35        assert!(total_eras <= 2);
36    }
37
38    #[test]
39    fn from_str() {
40        let supported_era = SupportedEra::from_str(&SupportedEra::dummy().to_string())
41            .expect("This era name should be supported.");
42
43        assert_eq!(SupportedEra::dummy(), supported_era);
44    }
45}