@@ -3,7 +3,6 @@ use std::collections::BTreeMap;
33use std:: fmt:: { Display , Formatter } ;
44use std:: str:: FromStr ;
55
6- use anyhow:: anyhow;
76use clap:: ValueEnum ;
87use serde:: { Deserialize , Serialize } ;
98use starknet_types_core:: felt:: Felt ;
@@ -16,20 +15,23 @@ use crate::signers::SignerSpec;
1615pub enum AccountType {
1716 #[ serde( rename = "open_zeppelin" ) ]
1817 OpenZeppelin ,
18+ // Backwards compatibility with pre-rebranding account files.
1919 #[ serde( alias = "argent" ) ]
2020 Ready ,
2121 Braavos ,
2222}
2323
2424impl FromStr for AccountType {
25- type Err = anyhow :: Error ;
25+ type Err = AccountsError ;
2626
2727 fn from_str ( value : & str ) -> Result < Self , Self :: Err > {
2828 match value {
2929 "open_zeppelin" | "open-zeppelin" | "oz" => Ok ( Self :: OpenZeppelin ) ,
3030 "ready" => Ok ( Self :: Ready ) ,
3131 "braavos" => Ok ( Self :: Braavos ) ,
32- account_type => Err ( anyhow ! ( "Invalid account type = {account_type}" ) ) ,
32+ account_type => Err ( AccountsError :: InvalidAccountType {
33+ account_type : account_type. to_owned ( ) ,
34+ } ) ,
3335 }
3436 }
3537}
@@ -48,7 +50,7 @@ macro_rules! identifier {
4850 impl $name {
4951 pub fn new( value: impl Into <String >) -> Result <Self , AccountsError > {
5052 let value = value. into( ) ;
51- if value. is_empty( ) {
53+ if value. trim ( ) . is_empty( ) {
5254 return Err ( AccountsError :: EmptyIdentifier { kind: $kind } ) ;
5355 }
5456 Ok ( Self ( value) )
@@ -208,7 +210,7 @@ impl<'a> DeployableAccountRecord<'a> {
208210 }
209211}
210212
211- fn required < T : Copy > (
213+ fn required < T > (
212214 value : Option < T > ,
213215 field : & ' static str ,
214216 operation : & ' static str ,
@@ -240,6 +242,8 @@ mod tests {
240242 fn identifiers_reject_empty_values ( ) {
241243 assert ! ( AccountName :: new( "" ) . is_err( ) ) ;
242244 assert ! ( NetworkName :: new( "" ) . is_err( ) ) ;
245+ assert ! ( AccountName :: new( " \t " ) . is_err( ) ) ;
246+ assert ! ( NetworkName :: new( "\n " ) . is_err( ) ) ;
243247 }
244248
245249 #[ test]
@@ -252,6 +256,7 @@ mod tests {
252256
253257 let registry = AccountRegistry :: new ( networks) ;
254258 assert ! ( registry. account( "alpha-sepolia" , "alice" ) . is_some( ) ) ;
259+ assert ! ( registry. account( "alpha-sepolia" , "bob" ) . is_none( ) ) ;
255260 }
256261
257262 #[ test]
0 commit comments