Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Nov 24, 2021
1 parent d6b2cab commit a817669
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 92 deletions.
4 changes: 2 additions & 2 deletions base_layer/key_manager/src/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions base_layer/wallet/src/contacts_service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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,
Expand Down
75 changes: 0 additions & 75 deletions base_layer/wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,78 +170,3 @@ impl From<WalletStorageError> 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);
}
}
2 changes: 1 addition & 1 deletion base_layer/wallet/src/output_manager_service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 15 additions & 12 deletions base_layer/wallet/tests/contacts_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit a817669

Please sign in to comment.