wallet: tweak error enum names

This commit is contained in:
Jon Häggblad
2022-03-21 10:36:41 +01:00
parent 7aeac58fd9
commit 423cdb1e1b
3 changed files with 8 additions and 10 deletions
+2 -4
View File
@@ -77,16 +77,14 @@ pub enum BackendError {
NetworkNotSupported(config::defaults::all::Network),
#[error("Could not access the local data storage directory")]
UnknownStorageDirectory,
#[error("No nymd validator configured")]
NoNymdValidatorConfigured,
#[error("No validator API URL configured")]
NoValidatorApiUrlConfigured,
#[error("The wallet file already exists")]
WalletFileAlreadyExists,
#[error("The wallet file is not found")]
WalletNotFound,
WalletFileNotFound,
#[error("Account ID not found in wallet")]
NoSuchWalletId,
NoSuchIdInWallet,
#[error("Adding a different password to the wallet not currently supported")]
WalletDifferentPasswordDetected,
}
@@ -37,7 +37,7 @@ impl StoredWallet {
.iter()
.find(|account| &account.id == id)
.map(|account| &account.account)
.ok_or(BackendError::NoSuchWalletId)
.ok_or(BackendError::NoSuchIdInWallet)
}
pub fn decrypt_account(
@@ -38,7 +38,7 @@ pub(crate) fn load_existing_wallet(password: &UserPassword) -> Result<StoredWall
fn load_existing_wallet_at_file(filepath: PathBuf) -> Result<StoredWallet, BackendError> {
if !filepath.exists() {
return Err(BackendError::WalletNotFound);
return Err(BackendError::WalletFileNotFound);
}
let file = OpenOptions::new().read(true).open(filepath)?;
let wallet: StoredWallet = serde_json::from_reader(file)?;
@@ -84,7 +84,7 @@ fn store_wallet_login_information_at_file(
password: &UserPassword,
) -> Result<(), BackendError> {
let mut stored_wallet = match load_existing_wallet_at_file(filepath.clone()) {
Err(BackendError::WalletNotFound) => StoredWallet::default(),
Err(BackendError::WalletFileNotFound) => StoredWallet::default(),
result => result?,
};
@@ -144,11 +144,11 @@ mod tests {
// Nothing was stored on the disk
assert!(matches!(
load_existing_wallet_at_file(wallet_file.clone()),
Err(BackendError::WalletNotFound),
Err(BackendError::WalletFileNotFound),
));
assert!(matches!(
load_existing_wallet_login_information_at_file(wallet_file.clone(), &id1, &password),
Err(BackendError::WalletNotFound),
Err(BackendError::WalletFileNotFound),
));
// Store the first account
@@ -184,7 +184,7 @@ mod tests {
// and with the wrong id also fails
assert!(matches!(
load_existing_wallet_login_information_at_file(wallet_file.clone(), &id2, &password),
Err(BackendError::NoSuchWalletId),
Err(BackendError::NoSuchIdInWallet),
));
let loaded_account =