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 713a92e commit d6b2cab
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 16 deletions.
4 changes: 2 additions & 2 deletions base_layer/core/tests/base_node_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<EpochTime> = vec![prev_block.header().timestamp];
for _ in 0..10 {
tokio::time::sleep(Duration::from_secs(2)).await;
let new_block = base_node
Expand Down
71 changes: 70 additions & 1 deletion base_layer/wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,75 @@ impl From<WalletStorageError> 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);
}
}
1 change: 0 additions & 1 deletion base_layer/wallet/tests/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ use tari_wallet::{
handle::TransactionEvent,
storage::sqlite_db::TransactionServiceSqliteDatabase,
},
utxo_scanner_service::utxo_scanning::UtxoScannerService,
Wallet,
WalletConfig,
WalletSqlite,
Expand Down
6 changes: 0 additions & 6 deletions common_sqlite/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 0 additions & 6 deletions comms/dht/src/storage/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit d6b2cab

Please sign in to comment.