feat(core): add `strum::EnumIter` and `strum::EnumCount` to `Chain` (#2043)

* add strum EnumIter and EnumCount to Chain

* clippy
This commit is contained in:
joshieDo 2023-01-12 11:17:46 +08:00 committed by GitHub
parent a1d6b5e3f7
commit 3c65997eae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -5,7 +5,7 @@ use std::{
fmt,
time::Duration,
};
use strum::{AsRefStr, EnumString, EnumVariantNames};
use strum::{AsRefStr, EnumCount, EnumIter, EnumString, EnumVariantNames};
// compatibility re-export
#[doc(hidden)]
@ -33,6 +33,8 @@ pub type ParseChainError = TryFromPrimitiveError<Chain>;
AsRefStr, // also for fmt::Display and serde::Serialize
EnumVariantNames, // Self::VARIANTS
EnumString, // FromStr, TryFrom<&str>
EnumIter,
EnumCount,
TryFromPrimitive, // TryFrom<u64>
Deserialize,
)]
@ -372,9 +374,15 @@ impl Chain {
#[cfg(test)]
mod tests {
use super::*;
use strum::IntoEnumIterator;
#[test]
fn test_default_chain() {
assert_eq!(serde_json::to_string(&Chain::default()).unwrap(), "\"mainnet\"");
}
#[test]
fn test_enum_iter() {
assert_eq!(Chain::COUNT, Chain::iter().size_hint().0);
}
}

View File

@ -512,7 +512,7 @@ mod tests {
let source_maps = include_str!("../test-data/out-source-maps.txt");
for (line, s) in source_maps.lines().enumerate() {
parse(s).unwrap_or_else(|_| panic!("Failed to parse line {}", line));
parse(s).unwrap_or_else(|_| panic!("Failed to parse line {line}"));
}
}

View File

@ -506,7 +506,7 @@ mod tests {
let existing = path.join("Test.sol");
let non_existing = path.join("test.sol");
std::fs::write(
&existing,
existing,
r#"
pragma solidity ^0.8.10;
contract A {}

View File

@ -19,7 +19,7 @@ async fn main() -> eyre::Result<()> {
.rate_limit_retries(10)
.timeout_retries(3)
.initial_backoff(Duration::from_millis(500))
.build(provider, Box::new(HttpRateLimitRetryPolicy::default()));
.build(provider, Box::<ethers::providers::HttpRateLimitRetryPolicy>::default());
// Send a JSON-RPC request for the latest block
let block_num = "latest".to_string();