From 322a5720c590d661ea2ef419afad8f3cbdab258f Mon Sep 17 00:00:00 2001 From: yoduyodu Date: Wed, 10 Apr 2024 09:57:49 -0700 Subject: [PATCH] String -> Enum --- xmtp_id/src/associations/association_log.rs | 18 +++++++++--------- xmtp_id/src/associations/mod.rs | 10 +++++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/xmtp_id/src/associations/association_log.rs b/xmtp_id/src/associations/association_log.rs index b3026a5b2..809e97606 100644 --- a/xmtp_id/src/associations/association_log.rs +++ b/xmtp_id/src/associations/association_log.rs @@ -16,7 +16,7 @@ pub enum AssociationError { #[error("Signature validation failed {0}")] Signature(#[from] SignatureError), #[error("Member of kind {0} not allowed to add {1}")] - MemberNotAllowed(String, String), + MemberNotAllowed(MemberKind, MemberKind), #[error("Missing existing member")] MissingExistingMember, #[error("Legacy key is only allowed to be associated using a legacy signature with nonce 0")] @@ -165,8 +165,8 @@ impl IdentityAction for AddAssociation { // Ensure that the new member signature is correct for the new member type allowed_association( - &existing_member_identifier.kind(), - &self.new_member_identifier.kind(), + existing_member_identifier.kind(), + self.new_member_identifier.kind(), )?; let new_member = Member::new(new_member_address, Some(existing_entity_id)); @@ -347,16 +347,16 @@ fn is_legacy_signature(signature: &Box) -> bool { } fn allowed_association( - existing_member_kind: &MemberKind, - new_member_kind: &MemberKind, + existing_member_kind: MemberKind, + new_member_kind: MemberKind, ) -> Result<(), AssociationError> { // The only disallowed association is an installation adding an installation - if existing_member_kind.eq(&MemberKind::Installation) - && new_member_kind.eq(&MemberKind::Installation) + if existing_member_kind == MemberKind::Installation + && new_member_kind == MemberKind::Installation { return Err(AssociationError::MemberNotAllowed( - existing_member_kind.to_string(), - new_member_kind.to_string(), + existing_member_kind, + new_member_kind, )); } diff --git a/xmtp_id/src/associations/mod.rs b/xmtp_id/src/associations/mod.rs index 521829bef..b6e4930f6 100644 --- a/xmtp_id/src/associations/mod.rs +++ b/xmtp_id/src/associations/mod.rs @@ -378,9 +378,13 @@ mod tests { }); let update_result = apply_update(existing_state, IdentityUpdate::new_test(vec![update])); - assert!( - matches!(update_result, Err(AssociationError::MemberNotAllowed(t1, t2)) if t1 == MemberKind::Installation.to_string() && t2 == MemberKind::Installation.to_string()) - ); + assert!(matches!( + update_result, + Err(AssociationError::MemberNotAllowed( + MemberKind::Installation, + MemberKind::Installation + )) + )); } #[test]