From d6b2cab84132c1c957b05900d58eded4e4732627 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Tue, 23 Nov 2021 12:10:54 +0200 Subject: [PATCH] review comments --- base_layer/core/tests/base_node_rpc.rs | 4 +- base_layer/wallet/src/error.rs | 71 +++++++++++++++++++++++++- base_layer/wallet/tests/wallet/mod.rs | 1 - common_sqlite/src/error.rs | 6 --- comms/dht/src/storage/error.rs | 6 --- 5 files changed, 72 insertions(+), 16 deletions(-) diff --git a/base_layer/core/tests/base_node_rpc.rs b/base_layer/core/tests/base_node_rpc.rs index 7643b5ca28..1b928bf911 100644 --- a/base_layer/core/tests/base_node_rpc.rs +++ b/base_layer/core/tests/base_node_rpc.rs @@ -45,6 +45,7 @@ use std::{convert::TryFrom, sync::Arc, time::Duration}; use randomx_rs::RandomXFlag; +use tari_crypto::tari_utilities::epoch_time::EpochTime; use tempfile::{tempdir, TempDir}; use tari_common::configuration::Network; @@ -303,8 +304,7 @@ async fn test_get_height_at_time() { let (_, service, base_node, request_mock, consensus_manager, block0, _utxo0, _temp_dir) = setup().await; let mut prev_block = block0.clone(); - let mut times = Vec::new(); - times.push(prev_block.header().timestamp); + let mut times: Vec = vec![prev_block.header().timestamp]; for _ in 0..10 { tokio::time::sleep(Duration::from_secs(2)).await; let new_block = base_node diff --git a/base_layer/wallet/src/error.rs b/base_layer/wallet/src/error.rs index 61c879570f..774e367f74 100644 --- a/base_layer/wallet/src/error.rs +++ b/base_layer/wallet/src/error.rs @@ -173,6 +173,75 @@ impl From for ExitCodes { impl PartialEq for WalletStorageError { fn eq(&self, other: &Self) -> bool { - self == other + 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/tests/wallet/mod.rs b/base_layer/wallet/tests/wallet/mod.rs index d54c307c01..c33481f3c2 100644 --- a/base_layer/wallet/tests/wallet/mod.rs +++ b/base_layer/wallet/tests/wallet/mod.rs @@ -69,7 +69,6 @@ use tari_wallet::{ handle::TransactionEvent, storage::sqlite_db::TransactionServiceSqliteDatabase, }, - utxo_scanner_service::utxo_scanning::UtxoScannerService, Wallet, WalletConfig, WalletSqlite, diff --git a/common_sqlite/src/error.rs b/common_sqlite/src/error.rs index c47859ce16..cd2b8e967a 100644 --- a/common_sqlite/src/error.rs +++ b/common_sqlite/src/error.rs @@ -27,9 +27,3 @@ pub enum SqliteStorageError { #[error("Diesel R2d2 error")] DieselR2d2Error(String), } - -impl PartialEq for SqliteStorageError { - fn eq(&self, other: &Self) -> bool { - self == other - } -} diff --git a/comms/dht/src/storage/error.rs b/comms/dht/src/storage/error.rs index ca35523f65..5e89ab494d 100644 --- a/comms/dht/src/storage/error.rs +++ b/comms/dht/src/storage/error.rs @@ -46,9 +46,3 @@ pub enum StorageError { #[error("Diesel R2d2 error: `{0}`")] DieselR2d2Error(#[from] SqliteStorageError), } - -impl PartialEq for StorageError { - fn eq(&self, other: &Self) -> bool { - self == other - } -}