Skip to content

Commit

Permalink
feat(rust/cardano-blockchain-types): Add Network variants index (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem authored Jan 21, 2025
1 parent 581121b commit 288a5b6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions rust/cardano-blockchain-types/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ pub(crate) const ENVVAR_MITHRIL_EXE_NAME: &str = "MITHRIL_EXE_NAME";
strum::Display,
)]
#[strum(ascii_case_insensitive)]
#[strum(serialize_all = "snake_case")]
#[repr(usize)]
pub enum Network {
/// Cardano mainnet network.
Mainnet,
Mainnet = 0,
/// Cardano pre-production network.
Preprod,
Preprod = 1,
/// Cardano preview network.
Preview,
Preview = 2,
}

// Mainnet Defaults.
Expand Down Expand Up @@ -224,6 +226,7 @@ mod tests {

use anyhow::Ok;
use chrono::{TimeZone, Utc};
use strum::VariantNames;

use super::*;

Expand All @@ -248,6 +251,23 @@ mod tests {
Ok(())
}

#[test]
fn test_variant_to_usize() {
assert_eq!(Network::Mainnet as usize, 0);
assert_eq!(Network::Preprod as usize, 1);
assert_eq!(Network::Preview as usize, 2);
}

#[test]
fn test_variant_to_string() {
assert_eq!(Network::Mainnet.to_string(), "mainnet");
assert_eq!(Network::Preprod.to_string(), "preprod");
assert_eq!(Network::Preview.to_string(), "preview");

let expected_names = ["mainnet", "preprod", "preview"];
assert_eq!(Network::VARIANTS, expected_names);
}

#[test]
fn test_time_to_slot_before_blockchain() {
let network = Network::Mainnet;
Expand Down

0 comments on commit 288a5b6

Please sign in to comment.