mithril_common/era/
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    /// Retrieve a dummy era (for test only)
22    pub fn dummy() -> Self {
23        Self::eras().first().unwrap().to_owned()
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use std::str::FromStr;
31
32    #[test]
33    fn correct_number_of_eras() {
34        let total_eras = SupportedEra::eras().len();
35
36        assert!(total_eras > 0);
37        assert!(total_eras <= 2);
38    }
39
40    #[test]
41    fn from_str() {
42        let supported_era = SupportedEra::from_str(&SupportedEra::dummy().to_string())
43            .expect("This era name should be supported.");
44
45        assert_eq!(SupportedEra::dummy(), supported_era);
46    }
47}