From 46cd67d51946dfcb530c22368d300d3975a995bf Mon Sep 17 00:00:00 2001 From: Mason Stallmo Date: Sat, 11 Sep 2021 06:07:20 +0000 Subject: [PATCH] Case insensitive match for ForkName (#2587) ## Issue Addressed #2583 ## Proposed Changes Case insensitive match on `fork_name` when calling `ForkName::from_str` ## Additional Info N/A --- consensus/types/src/fork_name.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/consensus/types/src/fork_name.rs b/consensus/types/src/fork_name.rs index a464a0ed9..15d5eab6a 100644 --- a/consensus/types/src/fork_name.rs +++ b/consensus/types/src/fork_name.rs @@ -58,7 +58,7 @@ impl FromStr for ForkName { type Err = (); fn from_str(fork_name: &str) -> Result { - Ok(match fork_name { + Ok(match fork_name.to_lowercase().as_ref() { "phase0" | "base" => ForkName::Base, "altair" => ForkName::Altair, _ => return Err(()), @@ -110,4 +110,22 @@ mod test { assert_eq!(fork.previous_fork(), Some(prev_fork)); } } + + #[test] + fn fork_name_case_insensitive_match() { + assert_eq!(ForkName::from_str("BASE"), Ok(ForkName::Base)); + assert_eq!(ForkName::from_str("BaSe"), Ok(ForkName::Base)); + assert_eq!(ForkName::from_str("base"), Ok(ForkName::Base)); + + assert_eq!(ForkName::from_str("PHASE0"), Ok(ForkName::Base)); + assert_eq!(ForkName::from_str("PhAsE0"), Ok(ForkName::Base)); + assert_eq!(ForkName::from_str("phase0"), Ok(ForkName::Base)); + + assert_eq!(ForkName::from_str("ALTAIR"), Ok(ForkName::Altair)); + assert_eq!(ForkName::from_str("AlTaIr"), Ok(ForkName::Altair)); + assert_eq!(ForkName::from_str("altair"), Ok(ForkName::Altair)); + + assert_eq!(ForkName::from_str("NO_NAME"), Err(())); + assert_eq!(ForkName::from_str("no_name"), Err(())); + } }