diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index 9338e82217..8df3f90734 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -350,7 +350,7 @@ mod test { "abandon".to_string(), "tipico".to_string(), ]; - assert_eq!(MnemonicLanguage::detect_language(&words2).is_err(), true); + assert!(MnemonicLanguage::detect_language(&words2).is_err()); // bounds check (last word is invalid) let words3 = vec![ @@ -360,7 +360,7 @@ mod test { "abandon".to_string(), "topazio".to_string(), ]; - assert_eq!(MnemonicLanguage::detect_language(&words3).is_err(), true); + assert!(MnemonicLanguage::detect_language(&words3).is_err()); // building up a word list: English/French + French -> French let mut words = Vec::with_capacity(3); diff --git a/base_layer/wallet/src/contacts_service/error.rs b/base_layer/wallet/src/contacts_service/error.rs index b06a02f9c0..3d9dd19987 100644 --- a/base_layer/wallet/src/contacts_service/error.rs +++ b/base_layer/wallet/src/contacts_service/error.rs @@ -25,7 +25,7 @@ use diesel::result::Error as DieselError; use tari_service_framework::reply_channel::TransportChannelError; use thiserror::Error; -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] #[allow(clippy::large_enum_variant)] pub enum ContactsServiceError { #[error("Contact is not found")] @@ -38,7 +38,7 @@ pub enum ContactsServiceError { TransportChannelError(#[from] TransportChannelError), } -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] pub enum ContactsServiceStorageError { #[error("This write operation is not supported for provided DbKey")] OperationNotSupported, diff --git a/base_layer/wallet/src/error.rs b/base_layer/wallet/src/error.rs index 774e367f74..7aba0ca426 100644 --- a/base_layer/wallet/src/error.rs +++ b/base_layer/wallet/src/error.rs @@ -170,78 +170,3 @@ impl From for ExitCodes { } } } - -impl PartialEq for WalletStorageError { - fn eq(&self, other: &Self) -> bool { - match other { - WalletStorageError::DuplicateContact => matches!(self, WalletStorageError::DuplicateContact), - WalletStorageError::OperationNotSupported => matches!(self, WalletStorageError::OperationNotSupported), - WalletStorageError::ConversionError(_) => matches!(self, WalletStorageError::ConversionError(_)), - WalletStorageError::ValuesNotFound => matches!(self, WalletStorageError::ValuesNotFound), - WalletStorageError::DbPathDoesNotExist => matches!(self, WalletStorageError::DbPathDoesNotExist), - WalletStorageError::SerdeJsonError(_) => matches!(self, WalletStorageError::SerdeJsonError(_)), - WalletStorageError::DieselR2d2Error(_) => matches!(self, WalletStorageError::DieselR2d2Error(_)), - WalletStorageError::DieselError(_) => matches!(self, WalletStorageError::DieselError(_)), - WalletStorageError::DieselConnectionError(_) => { - matches!(self, WalletStorageError::DieselConnectionError(_)) - }, - WalletStorageError::DatabaseMigrationError(_) => { - matches!(self, WalletStorageError::DatabaseMigrationError(_)) - }, - WalletStorageError::ValueNotFound(_) => matches!(self, WalletStorageError::ValueNotFound(_)), - WalletStorageError::UnexpectedResult(_) => matches!(self, WalletStorageError::UnexpectedResult(_)), - WalletStorageError::BlockingTaskSpawnError(_) => { - matches!(self, WalletStorageError::BlockingTaskSpawnError(_)) - }, - WalletStorageError::FileError(_) => matches!(self, WalletStorageError::FileError(_)), - WalletStorageError::InvalidUnicodePath => matches!(self, WalletStorageError::InvalidUnicodePath), - WalletStorageError::HexError(_) => matches!(self, WalletStorageError::HexError(_)), - WalletStorageError::InvalidEncryptionCipher => matches!(self, WalletStorageError::InvalidEncryptionCipher), - WalletStorageError::InvalidPassphrase => matches!(self, WalletStorageError::InvalidPassphrase), - WalletStorageError::MissingNonce => matches!(self, WalletStorageError::MissingNonce), - WalletStorageError::AeadError(_) => matches!(self, WalletStorageError::AeadError(_)), - WalletStorageError::AlreadyEncrypted => matches!(self, WalletStorageError::AlreadyEncrypted), - WalletStorageError::ByteArrayError(_) => matches!(self, WalletStorageError::ByteArrayError(_)), - WalletStorageError::CannotAcquireFileLock => matches!(self, WalletStorageError::CannotAcquireFileLock), - WalletStorageError::DatabasePathIsRootPath => matches!(self, WalletStorageError::DatabasePathIsRootPath), - WalletStorageError::IoError(_) => matches!(self, WalletStorageError::IoError(_)), - WalletStorageError::NoPasswordError => matches!(self, WalletStorageError::NoPasswordError), - WalletStorageError::DeprecatedOperation => matches!(self, WalletStorageError::DeprecatedOperation), - WalletStorageError::KeyManagerError(_) => matches!(self, WalletStorageError::KeyManagerError(_)), - } - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn not_stack_overflow() { - #[allow(clippy::eq_op)] - let compare_true = WalletStorageError::InvalidUnicodePath == WalletStorageError::InvalidUnicodePath; - assert!(compare_true); - - #[allow(clippy::eq_op)] - let compare_true = WalletStorageError::ValuesNotFound == WalletStorageError::ValuesNotFound; - assert!(compare_true); - - let compare_false = - WalletStorageError::DieselR2d2Error(SqliteStorageError::DieselR2d2Error(String::from("test1"))) == - WalletStorageError::InvalidUnicodePath; - assert!(!compare_false); - - let compare_true = - WalletStorageError::DieselR2d2Error(SqliteStorageError::DieselR2d2Error(String::from("test1"))) == - WalletStorageError::DieselR2d2Error(SqliteStorageError::DieselR2d2Error(String::from("test2"))); - assert!(compare_true); - - let compare_true = - WalletStorageError::DieselR2d2Error(SqliteStorageError::DieselR2d2Error(String::from("test1"))) == - WalletStorageError::DieselR2d2Error(SqliteStorageError::DieselR2d2Error(String::from("test1"))); - assert!(compare_true); - - let compare_false = WalletStorageError::MissingNonce == WalletStorageError::CannotAcquireFileLock; - assert!(!compare_false); - } -} diff --git a/base_layer/wallet/src/output_manager_service/error.rs b/base_layer/wallet/src/output_manager_service/error.rs index 1e7eeb84e8..afef1156c3 100644 --- a/base_layer/wallet/src/output_manager_service/error.rs +++ b/base_layer/wallet/src/output_manager_service/error.rs @@ -120,7 +120,7 @@ pub enum OutputManagerError { InvalidMessageError(String), } -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] pub enum OutputManagerStorageError { #[error("Tried to insert an output that already exists in the database")] DuplicateOutput, diff --git a/base_layer/wallet/tests/contacts_service/mod.rs b/base_layer/wallet/tests/contacts_service/mod.rs index ed5ad5033c..b96aa8e8a7 100644 --- a/base_layer/wallet/tests/contacts_service/mod.rs +++ b/base_layer/wallet/tests/contacts_service/mod.rs @@ -87,18 +87,21 @@ pub fn test_contacts_service() { let (_secret_key, public_key) = PublicKey::random_keypair(&mut OsRng); let contact = runtime.block_on(contacts_service.get_contact(public_key.clone())); - assert_eq!( - contact, - Err(ContactsServiceError::ContactsServiceStorageError( - ContactsServiceStorageError::ValueNotFound(DbKey::Contact(public_key.clone())) - )) - ); - assert_eq!( - runtime.block_on(contacts_service.remove_contact(public_key.clone())), - Err(ContactsServiceError::ContactsServiceStorageError( - ContactsServiceStorageError::ValueNotFound(DbKey::Contact(public_key)) - )) - ); + match contact { + Ok(_) => panic!("There should be an error here"), + Err(ContactsServiceError::ContactsServiceStorageError(ContactsServiceStorageError::ValueNotFound(val))) => { + assert_eq!(val, DbKey::Contact(public_key.clone())) + }, + _ => panic!("There should be a specific error here"), + } + let result = runtime.block_on(contacts_service.remove_contact(public_key.clone())); + match result { + Ok(_) => panic!("There should be an error here"), + Err(ContactsServiceError::ContactsServiceStorageError(ContactsServiceStorageError::ValueNotFound(val))) => { + assert_eq!(val, DbKey::Contact(public_key)) + }, + _ => panic!("There should be a specific error here"), + } let _ = runtime .block_on(contacts_service.remove_contact(contacts[0].public_key.clone()))