Skip to content

Commit

Permalink
Remove PartialEq from Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
37ng committed Apr 10, 2024
1 parent 1a3105b commit edb01c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
2 changes: 1 addition & 1 deletion xmtp_id/src/associations/association_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 3 additions & 5 deletions xmtp_id/src/associations/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl IdentityUpdateBuilder {
}
}

#[derive(Debug, Error, PartialEq)]
#[derive(Debug, Error)]
pub enum SignatureRequestError {
#[error("Unknown signer")]
UnknownSigner,
Expand Down Expand Up @@ -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()));
}
}
49 changes: 17 additions & 32 deletions xmtp_id/src/associations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ mod tests {
..Default::default()
});
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!(update_result.is_err_and(|e| e.to_string() == AssociationError::Replay.to_string()));
}

#[test]
Expand Down Expand Up @@ -285,11 +284,9 @@ mod tests {
let state_result = get_state(vec![IdentityUpdate::new_test(vec![Action::CreateInbox(
action,
)])]);
assert!(state_result.is_err());
assert_eq!(
state_result.err().unwrap(),
AssociationError::Signature(SignatureError::Invalid)
);
assert!(state_result
.is_err_and(|e| e.to_string()
== AssociationError::Signature(SignatureError::Invalid).to_string()));
}

#[test]
Expand All @@ -307,11 +304,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(),
Expand All @@ -328,11 +323,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]
Expand All @@ -351,11 +344,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]
Expand Down Expand Up @@ -383,14 +373,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]
Expand Down Expand Up @@ -569,10 +557,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()));
}
}
2 changes: 1 addition & 1 deletion xmtp_id/src/associations/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit edb01c1

Please sign in to comment.