Skip to content

Commit

Permalink
Case insensitive match for ForkName (sigp#2587)
Browse files Browse the repository at this point in the history
## Issue Addressed

sigp#2583

## Proposed Changes

Case insensitive match on `fork_name` when calling `ForkName::from_str`

## Additional Info

N/A
  • Loading branch information
mstallmo committed Sep 11, 2021
1 parent 8d2650f commit 46cd67d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion consensus/types/src/fork_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl FromStr for ForkName {
type Err = ();

fn from_str(fork_name: &str) -> Result<Self, ()> {
Ok(match fork_name {
Ok(match fork_name.to_lowercase().as_ref() {
"phase0" | "base" => ForkName::Base,
"altair" => ForkName::Altair,
_ => return Err(()),
Expand Down Expand Up @@ -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(()));
}
}

0 comments on commit 46cd67d

Please sign in to comment.