Skip to content

Commit f687ffe

Browse files
committed
don't use string for str test
1 parent ef2ad22 commit f687ffe

File tree

1 file changed

+14
-3
lines changed
  • crates/starknet-types-core/src/chain_id

1 file changed

+14
-3
lines changed

crates/starknet-types-core/src/chain_id/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ impl core::fmt::Display for ChainId {
4646
}
4747
}
4848

49+
impl AsRef<str> for ChainId {
50+
fn as_ref(&self) -> &str {
51+
match self {
52+
ChainId::Mainnet => SN_MAIN_STR,
53+
ChainId::Sepolia => SN_SEPOLIA_STR,
54+
#[cfg(feature = "devnet")]
55+
Devnet(ss) => ss.as_ref(),
56+
}
57+
}
58+
}
59+
4960
// Felt
5061

5162
impl From<ChainId> for Felt {
@@ -205,11 +216,11 @@ mod tests {
205216
fn str_and_chain_id_round_trip() {
206217
let s = SN_MAIN_STR;
207218
let chain_id = ChainId::from_str(s).unwrap();
208-
assert_eq!(chain_id.to_string(), s.to_string());
219+
assert_eq!(chain_id.as_ref(), s);
209220

210221
let s = SN_SEPOLIA_STR;
211222
let chain_id = ChainId::from_str(s).unwrap();
212-
assert_eq!(chain_id.to_string(), s.to_string());
223+
assert_eq!(chain_id.as_ref(), s);
213224

214225
#[cfg(not(feature = "devnet"))]
215226
{
@@ -220,7 +231,7 @@ mod tests {
220231
{
221232
let s = "SN_DEVNET";
222233
let chain_id = ChainId::from_str(s).unwrap();
223-
assert_eq!(s, chain_id.to_string());
234+
assert_eq!(s, chain_id.as_ref());
224235
let s = "SN_DEVNET_LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG";
225236
assert!(ChainId::from_str(s).is_err());
226237
let s = "SN_DEVNET_🌟";

0 commit comments

Comments
 (0)