Skip to content

Commit

Permalink
E2E Who Added Me Test Including CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieobject committed Apr 8, 2024
1 parent b03c047 commit d0c98df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
20 changes: 16 additions & 4 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ where
self,
GroupMembershipState::Allowed,
permissions,
Some(self.account_address(),
))
Some(self.account_address()),
)
.map_err(|e| ClientError::Generic(format!("group create error {}", e)))?;

Ok(group)
Expand All @@ -223,7 +223,12 @@ where
let conn = &mut self.store.conn()?;
let stored_group: Option<StoredGroup> = conn.fetch(&group_id)?;
match stored_group {
Some(group) => Ok(MlsGroup::new(self, group.id, group.created_at_ns, group.added_by_address)),
Some(group) => Ok(MlsGroup::new(
self,
group.id,
group.created_at_ns,
group.added_by_address,
)),
None => Err(ClientError::Generic("group not found".to_string())),
}
}
Expand All @@ -247,7 +252,14 @@ where
.conn()?
.find_groups(allowed_states, created_after_ns, created_before_ns, limit)?
.into_iter()
.map(|stored_group| MlsGroup::new(self, stored_group.id, stored_group.created_at_ns, stored_group.added_by_address))
.map(|stored_group| {
MlsGroup::new(
self,
stored_group.id,
stored_group.created_at_ns,
stored_group.added_by_address,
)
})
.collect())
}

Expand Down
16 changes: 13 additions & 3 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,22 +1001,32 @@ mod tests {
let amal = ClientBuilder::new_test_client(&generate_local_wallet()).await;
let bola = ClientBuilder::new_test_client(&generate_local_wallet()).await;

// Amal creates a group
let amal_group = amal.create_group(None).unwrap();
// Add bola

// Amal adds Bola to the group
amal_group
.add_members_by_installation_id(vec![bola.installation_public_key()])
.await
.unwrap();

// Get bola's version of the same group
// Bola syncs groups - this will decrypt the Welcome, identify who added Bola
// and then store that value on the group and insert into the database
let bola_groups = bola
.sync_welcomes()
.await
.unwrap();

// Bola gets the group id. This will be needed to fetch the group from
// the database.
let bola_group = bola_groups.first().unwrap();
let bola_group_id = bola_group.group_id.clone();

// Bola fetches group from the database
let bola_fetched_group = bola.group(bola_group_id).unwrap();

// Check Bola's group for the added_by_address of the inviter
let added_by_address = bola_group.added_by_address.clone().unwrap();
let added_by_address = bola_fetched_group.added_by_address.clone().unwrap();

// // Verify the welcome host_credential is equal to Amal's
assert_eq!(amal.account_address(), added_by_address, "The Inviter and added_by_address do not match!");
Expand Down
7 changes: 6 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ impl_store!(StoredGroup, groups);

impl StoredGroup {
/// Create a new [`Purpose::Conversation`] group. This is the default type of group.
pub fn new(id: ID, created_at_ns: i64, membership_state: GroupMembershipState, added_by_address: Option<String>) -> Self {
pub fn new(
id: ID,
created_at_ns: i64,
membership_state: GroupMembershipState,
added_by_address: Option<String>,
) -> Self {
Self {
id,
created_at_ns,
Expand Down

0 comments on commit d0c98df

Please sign in to comment.