fix: use to_string in mainnet chain variant (#2275)
* fix: use to_string in mainnet chain variant * Add test for chain serde and to_string matching
This commit is contained in:
parent
18d40425ec
commit
1dc5d403f4
|
@ -53,7 +53,8 @@ pub type ParseChainError = TryFromPrimitiveError<Chain>;
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
#[repr(u64)]
|
#[repr(u64)]
|
||||||
pub enum Chain {
|
pub enum Chain {
|
||||||
#[strum(serialize = "ethlive", serialize = "mainnet")]
|
#[strum(to_string = "mainnet", serialize = "ethlive")]
|
||||||
|
#[serde(alias = "ethlive")]
|
||||||
Mainnet = 1,
|
Mainnet = 1,
|
||||||
Morden = 2,
|
Morden = 2,
|
||||||
Ropsten = 3,
|
Ropsten = 3,
|
||||||
|
@ -598,6 +599,7 @@ mod tests {
|
||||||
|
|
||||||
// kebab-case
|
// kebab-case
|
||||||
const ALIASES: &[(Chain, &[&str])] = &[
|
const ALIASES: &[(Chain, &[&str])] = &[
|
||||||
|
(Mainnet, &["ethlive"]),
|
||||||
(BinanceSmartChain, &["bsc", "binance-smart-chain"]),
|
(BinanceSmartChain, &["bsc", "binance-smart-chain"]),
|
||||||
(BinanceSmartChainTestnet, &["bsc-testnet", "binance-smart-chain-testnet"]),
|
(BinanceSmartChainTestnet, &["bsc-testnet", "binance-smart-chain-testnet"]),
|
||||||
(XDai, &["xdai", "gnosis", "gnosis-chain"]),
|
(XDai, &["xdai", "gnosis", "gnosis-chain"]),
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue