mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
add is_post_merge implementation for Hardfork (#6204)
This commit is contained in:
@ -87,14 +87,18 @@ impl Hardfork {
|
|||||||
Hardfork::Canyon => None,
|
Hardfork::Canyon => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if the hardfork is post the Ethereum merge.
|
||||||
|
pub fn is_post_merge(&self) -> bool {
|
||||||
|
self >= &Hardfork::Paris
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Hardfork {
|
impl FromStr for Hardfork {
|
||||||
type Err = String;
|
type Err = String;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let s = s.to_lowercase();
|
Ok(match s.to_lowercase().as_str() {
|
||||||
let hardfork = match s.as_str() {
|
|
||||||
"frontier" => Hardfork::Frontier,
|
"frontier" => Hardfork::Frontier,
|
||||||
"homestead" => Hardfork::Homestead,
|
"homestead" => Hardfork::Homestead,
|
||||||
"dao" => Hardfork::Dao,
|
"dao" => Hardfork::Dao,
|
||||||
@ -119,8 +123,7 @@ impl FromStr for Hardfork {
|
|||||||
#[cfg(feature = "optimism")]
|
#[cfg(feature = "optimism")]
|
||||||
"canyon" => Hardfork::Canyon,
|
"canyon" => Hardfork::Canyon,
|
||||||
_ => return Err(format!("Unknown hardfork: {s}")),
|
_ => return Err(format!("Unknown hardfork: {s}")),
|
||||||
};
|
})
|
||||||
Ok(hardfork)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,4 +200,33 @@ mod tests {
|
|||||||
fn check_nonexistent_hardfork_from_str() {
|
fn check_nonexistent_hardfork_from_str() {
|
||||||
assert!(Hardfork::from_str("not a hardfork").is_err());
|
assert!(Hardfork::from_str("not a hardfork").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_post_merge() {
|
||||||
|
assert!(!Hardfork::Frontier.is_post_merge());
|
||||||
|
assert!(!Hardfork::Homestead.is_post_merge());
|
||||||
|
assert!(!Hardfork::Dao.is_post_merge());
|
||||||
|
assert!(!Hardfork::Tangerine.is_post_merge());
|
||||||
|
assert!(!Hardfork::SpuriousDragon.is_post_merge());
|
||||||
|
assert!(!Hardfork::Byzantium.is_post_merge());
|
||||||
|
assert!(!Hardfork::Constantinople.is_post_merge());
|
||||||
|
assert!(!Hardfork::Petersburg.is_post_merge());
|
||||||
|
assert!(!Hardfork::Istanbul.is_post_merge());
|
||||||
|
assert!(!Hardfork::MuirGlacier.is_post_merge());
|
||||||
|
assert!(!Hardfork::Berlin.is_post_merge());
|
||||||
|
assert!(!Hardfork::London.is_post_merge());
|
||||||
|
assert!(!Hardfork::ArrowGlacier.is_post_merge());
|
||||||
|
assert!(!Hardfork::GrayGlacier.is_post_merge());
|
||||||
|
assert!(Hardfork::Paris.is_post_merge());
|
||||||
|
assert!(Hardfork::Shanghai.is_post_merge());
|
||||||
|
assert!(Hardfork::Cancun.is_post_merge());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "optimism")]
|
||||||
|
fn check_op_post_merge() {
|
||||||
|
assert!(Hardfork::Bedrock.is_post_merge());
|
||||||
|
assert!(Hardfork::Regolith.is_post_merge());
|
||||||
|
assert!(Hardfork::Canyon.is_post_merge());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user