wallet: removing an account in a login twice should fail

This commit is contained in:
Jon Häggblad
2022-05-06 09:01:48 +02:00
parent 0812378fdd
commit 571fd5cb93
2 changed files with 11 additions and 9 deletions
@@ -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(())
}
}
@@ -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]