Skip to content

Commit 1dc5d40

Browse files
authored
fix: use to_string in mainnet chain variant (gakonst#2275)
* fix: use to_string in mainnet chain variant * Add test for chain serde and to_string matching
1 parent 18d4042 commit 1dc5d40

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ethers-core/src/types/chain.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ pub type ParseChainError = TryFromPrimitiveError<Chain>;
5353
#[strum(serialize_all = "kebab-case")]
5454
#[repr(u64)]
5555
pub enum Chain {
56-
#[strum(serialize = "ethlive", serialize = "mainnet")]
56+
#[strum(to_string = "mainnet", serialize = "ethlive")]
57+
#[serde(alias = "ethlive")]
5758
Mainnet = 1,
5859
Morden = 2,
5960
Ropsten = 3,
@@ -598,6 +599,7 @@ mod tests {
598599

599600
// kebab-case
600601
const ALIASES: &[(Chain, &[&str])] = &[
602+
(Mainnet, &["ethlive"]),
601603
(BinanceSmartChain, &["bsc", "binance-smart-chain"]),
602604
(BinanceSmartChainTestnet, &["bsc-testnet", "binance-smart-chain-testnet"]),
603605
(XDai, &["xdai", "gnosis", "gnosis-chain"]),
@@ -614,4 +616,13 @@ mod tests {
614616
}
615617
}
616618
}
619+
620+
#[test]
621+
fn serde_to_string_match() {
622+
for chain in Chain::iter() {
623+
let chain_serde = serde_json::to_string(&chain).unwrap();
624+
let chain_string = format!("\"{}\"", chain.to_string());
625+
assert_eq!(chain_serde, chain_string);
626+
}
627+
}
617628
}

0 commit comments

Comments
 (0)