@@ -46,6 +46,17 @@ impl core::fmt::Display for ChainId {
46
46
}
47
47
}
48
48
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
+
49
60
// Felt
50
61
51
62
impl From < ChainId > for Felt {
@@ -205,11 +216,11 @@ mod tests {
205
216
fn str_and_chain_id_round_trip ( ) {
206
217
let s = SN_MAIN_STR ;
207
218
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) ;
209
220
210
221
let s = SN_SEPOLIA_STR ;
211
222
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) ;
213
224
214
225
#[ cfg( not( feature = "devnet" ) ) ]
215
226
{
@@ -220,7 +231,7 @@ mod tests {
220
231
{
221
232
let s = "SN_DEVNET" ;
222
233
let chain_id = ChainId :: from_str ( s) . unwrap ( ) ;
223
- assert_eq ! ( s, chain_id. to_string ( ) ) ;
234
+ assert_eq ! ( s, chain_id. as_ref ( ) ) ;
224
235
let s = "SN_DEVNET_LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG" ;
225
236
assert ! ( ChainId :: from_str( s) . is_err( ) ) ;
226
237
let s = "SN_DEVNET_🌟" ;
0 commit comments