From 766e698b6cbd04f87e8191a3c779cf500c5a18e1 Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Thu, 18 Jan 2024 14:41:32 +0100 Subject: [PATCH] more tests --- .../secure_storage/wallet_client_storage.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/profile/src/wallet/secure_storage/wallet_client_storage.rs b/profile/src/wallet/secure_storage/wallet_client_storage.rs index bc9f30fa..ee8807af 100644 --- a/profile/src/wallet/secure_storage/wallet_client_storage.rs +++ b/profile/src/wallet/secure_storage/wallet_client_storage.rs @@ -133,6 +133,28 @@ impl WalletClientStorage { let storage = EphemeralSecureStorage::new(); (WalletClientStorage::new(storage.clone()), storage) } + + pub(crate) fn always_fail() -> Self { + WalletClientStorage::new(Arc::new(AlwaysFailStorage {})) + } +} +#[cfg(test)] +#[derive(Debug)] +struct AlwaysFailStorage {} + +#[cfg(test)] +impl SecureStorage for AlwaysFailStorage { + fn load_data(&self, _key: SecureStorageKey) -> Result>> { + todo!() + } + + fn save_data(&self, _key: SecureStorageKey, _data: Vec) -> Result<()> { + Err(CommonError::Unknown) + } + + fn delete_data_for_key(&self, _key: SecureStorageKey) -> Result<()> { + todo!() + } } #[cfg(test)] @@ -239,4 +261,14 @@ mod tests { .unwrap() .contains("zoo")); } + + #[test] + fn save_mnemonic_with_passphrase_failure() { + let sut = WalletClientStorage::always_fail(); + let id = FactorSourceIDFromHash::placeholder(); + assert_eq!( + sut.save_mnemonic_with_passphrase(&MnemonicWithPassphrase::placeholder(), &id), + Err(CommonError::UnableToSaveMnemonicToSecureStorage(id.clone())) + ); + } }