From 571fd5cb9312c1bf3d01a0220a2343f07d60f87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Fri, 6 May 2022 09:01:48 +0200 Subject: [PATCH] wallet: removing an account in a login twice should fail --- .../src-tauri/src/wallet_storage/account_data.rs | 6 +++++- nym-wallet/src-tauri/src/wallet_storage/mod.rs | 14 ++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/nym-wallet/src-tauri/src/wallet_storage/account_data.rs b/nym-wallet/src-tauri/src/wallet_storage/account_data.rs index b6b334e814..2eb875913d 100644 --- a/nym-wallet/src-tauri/src/wallet_storage/account_data.rs +++ b/nym-wallet/src-tauri/src/wallet_storage/account_data.rs @@ -267,8 +267,12 @@ impl MultipleAccounts { } } - pub(crate) fn remove(&mut self, id: &AccountId) { + pub(crate) fn remove(&mut self, id: &AccountId) -> Result<(), BackendError> { + if self.get_account(id).is_none() { + return Err(BackendError::NoSuchIdInWalletLoginEntry); + } self.accounts.retain(|accounts| &accounts.id != id); + Ok(()) } } diff --git a/nym-wallet/src-tauri/src/wallet_storage/mod.rs b/nym-wallet/src-tauri/src/wallet_storage/mod.rs index f4e2243bc9..27c6972c76 100644 --- a/nym-wallet/src-tauri/src/wallet_storage/mod.rs +++ b/nym-wallet/src-tauri/src/wallet_storage/mod.rs @@ -249,7 +249,7 @@ fn remove_account_from_wallet_login_at_file( return Err(BackendError::WalletUnexpectedMnemonicAccount); } StoredLogin::Multiple(ref mut accounts) => { - accounts.remove(inner_id); + accounts.remove(inner_id)?; accounts.is_empty() } }; @@ -259,7 +259,7 @@ fn remove_account_from_wallet_login_at_file( .remove_encrypted_login(id) .ok_or(BackendError::NoSuchIdInWallet)?; } else { - // Replace the encrypted login with the prune one. + // Replace the encrypted login with the pruned one. let encrypted_accounts = EncryptedLogin { id: id.clone(), account: encrypt_struct(&decrypted_login, password)?, @@ -873,12 +873,10 @@ mod tests { remove_account_from_wallet_login_at_file(wallet_file.clone(), &id1, &id2, &password).unwrap(); - // Delete the same again fails - // WIP(JON) - //assert!(matches!( - remove_account_from_wallet_login_at_file(wallet_file, &id1, &id2, &password).unwrap(); - //Err(BackendError::NoSuchIdInWallet), - //)); + assert!(matches!( + remove_account_from_wallet_login_at_file(wallet_file, &id1, &id2, &password), + Err(BackendError::NoSuchIdInWalletLoginEntry), + )); } #[test]