Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use to_string in mainnet chain variant #2275

Merged
merged 2 commits into from Mar 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion ethers-core/src/types/chain.rs
Expand Up @@ -53,7 +53,8 @@ pub type ParseChainError = TryFromPrimitiveError<Chain>;
#[strum(serialize_all = "kebab-case")]
#[repr(u64)]
pub enum Chain {
#[strum(serialize = "ethlive", serialize = "mainnet")]
#[strum(to_string = "mainnet", serialize = "ethlive")]
#[serde(alias = "ethlive")]
Mainnet = 1,
Morden = 2,
Ropsten = 3,
Expand Down Expand Up @@ -598,6 +599,7 @@ mod tests {

// kebab-case
const ALIASES: &[(Chain, &[&str])] = &[
(Mainnet, &["ethlive"]),
(BinanceSmartChain, &["bsc", "binance-smart-chain"]),
(BinanceSmartChainTestnet, &["bsc-testnet", "binance-smart-chain-testnet"]),
(XDai, &["xdai", "gnosis", "gnosis-chain"]),
Expand All @@ -614,4 +616,13 @@ mod tests {
}
}
}

#[test]
fn serde_to_string_match() {
for chain in Chain::iter() {
let chain_serde = serde_json::to_string(&chain).unwrap();
let chain_string = format!("\"{}\"", chain.to_string());
assert_eq!(chain_serde, chain_string);
}
}
}