From c86232a4baed897d5959142eb42745a2508234e8 Mon Sep 17 00:00:00 2001 From: yoduyodu Date: Tue, 9 Apr 2024 20:11:56 -0700 Subject: [PATCH] Remove PartialEq from Errors --- xmtp_id/src/associations/association_log.rs | 2 +- xmtp_id/src/associations/builder.rs | 8 ++-- xmtp_id/src/associations/mod.rs | 47 +++++++++------------ xmtp_id/src/associations/signature.rs | 2 +- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/xmtp_id/src/associations/association_log.rs b/xmtp_id/src/associations/association_log.rs index d0c8dde72..b3026a5b2 100644 --- a/xmtp_id/src/associations/association_log.rs +++ b/xmtp_id/src/associations/association_log.rs @@ -5,7 +5,7 @@ use super::state::AssociationState; use thiserror::Error; -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] pub enum AssociationError { #[error("Error creating association {0}")] Generic(String), diff --git a/xmtp_id/src/associations/builder.rs b/xmtp_id/src/associations/builder.rs index 90d63a9b3..a62932e19 100644 --- a/xmtp_id/src/associations/builder.rs +++ b/xmtp_id/src/associations/builder.rs @@ -141,7 +141,7 @@ impl IdentityUpdateBuilder { } } -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] pub enum SignatureRequestError { #[error("Unknown signer")] UnknownSigner, @@ -434,9 +434,7 @@ mod tests { MockSignature::new_boxed(true, rand_string().into(), SignatureKind::Erc191, None), ); - assert_eq!( - attempt_to_add_random_member, - Err(SignatureRequestError::UnknownSigner) - ); + assert!(attempt_to_add_random_member + .is_err_and(|x| x.to_string() == SignatureRequestError::UnknownSigner.to_string())); } } diff --git a/xmtp_id/src/associations/mod.rs b/xmtp_id/src/associations/mod.rs index 2f2680761..022e8726f 100644 --- a/xmtp_id/src/associations/mod.rs +++ b/xmtp_id/src/associations/mod.rs @@ -234,7 +234,10 @@ mod tests { }); let update_result = apply_update(state, IdentityUpdate::new_test(vec![update])); assert!(update_result.is_err()); - assert_eq!(update_result.err().unwrap(), AssociationError::Replay); + assert_eq!( + update_result.err().unwrap().to_string(), + AssociationError::Replay.to_string() + ); } #[test] @@ -287,8 +290,8 @@ mod tests { )])]); assert!(state_result.is_err()); assert_eq!( - state_result.err().unwrap(), - AssociationError::Signature(SignatureError::Invalid) + state_result.err().unwrap().to_string(), + AssociationError::Signature(SignatureError::Invalid).to_string() ); } @@ -307,11 +310,9 @@ mod tests { initial_state.clone(), IdentityUpdate::new_test(vec![update_with_bad_existing_member]), ); - assert!(update_result.is_err()); - assert_eq!( - update_result.err().unwrap(), - AssociationError::Signature(SignatureError::Invalid) - ); + assert!(update_result + .is_err_and(|e| e.to_string() + == AssociationError::Signature(SignatureError::Invalid).to_string())); let update_with_bad_new_member = Action::AddAssociation(AddAssociation { new_member_signature: bad_signature.clone(), @@ -328,11 +329,9 @@ mod tests { initial_state, IdentityUpdate::new_test(vec![update_with_bad_new_member]), ); - assert!(update_result_2.is_err()); - assert_eq!( - update_result_2.err().unwrap(), - AssociationError::Signature(SignatureError::Invalid) - ); + assert!(update_result_2 + .is_err_and(|e| e.to_string() + == AssociationError::Signature(SignatureError::Invalid).to_string())); } #[test] @@ -351,11 +350,8 @@ mod tests { }); let state_result = get_state(vec![IdentityUpdate::new_test(vec![create_request, update])]); - assert!(state_result.is_err()); - assert_eq!( - state_result.err().unwrap(), - AssociationError::MissingExistingMember - ); + assert!(state_result + .is_err_and(|e| e.to_string() == AssociationError::MissingExistingMember.to_string())); } #[test] @@ -383,14 +379,12 @@ mod tests { }); let update_result = apply_update(existing_state, IdentityUpdate::new_test(vec![update])); - assert!(update_result.is_err()); - assert_eq!( - update_result.err().unwrap(), - AssociationError::MemberNotAllowed( + assert!(update_result.is_err_and(|e| e.to_string() + == AssociationError::MemberNotAllowed( MemberKind::Installation.to_string(), MemberKind::Installation.to_string() ) - ); + .to_string())); } #[test] @@ -569,10 +563,7 @@ mod tests { let revoke_result = apply_update(new_state, IdentityUpdate::new_test(vec![attempted_revoke])); - assert!(revoke_result.is_err()); - assert_eq!( - revoke_result.err().unwrap(), - AssociationError::MissingExistingMember - ); + assert!(revoke_result + .is_err_and(|e| e.to_string() == AssociationError::MissingExistingMember.to_string())); } } diff --git a/xmtp_id/src/associations/signature.rs b/xmtp_id/src/associations/signature.rs index d71bec608..ae71b83f5 100644 --- a/xmtp_id/src/associations/signature.rs +++ b/xmtp_id/src/associations/signature.rs @@ -2,7 +2,7 @@ use thiserror::Error; use super::MemberIdentifier; -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] pub enum SignatureError { #[error("Signature validation failed")] Invalid,