Skip to content

Commit

Permalink
String -> Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
37ng committed Apr 10, 2024
1 parent 7e11c33 commit 322a572
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 9 additions & 9 deletions xmtp_id/src/associations/association_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -347,16 +347,16 @@ fn is_legacy_signature(signature: &Box<dyn Signature>) -> 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,
));
}

Expand Down
10 changes: 7 additions & 3 deletions xmtp_id/src/associations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 322a572

Please sign in to comment.