Skip to content

Commit

Permalink
Write a simpler test
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Oct 4, 2024
1 parent 26cb097 commit e0921f0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
22 changes: 11 additions & 11 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ mod tests {
bo_group.send("bo1".as_bytes().to_vec()).await.unwrap();
alix_group.send("alix1".as_bytes().to_vec()).await.unwrap();

// Move the group forward by 2 epochs (as Alix's max_past_epochs is
// Move the group forward by 3 epochs (as Alix's max_past_epochs is
// configured to 3) without Bo syncing
alix_group
.add_members(vec![
Expand All @@ -2530,15 +2530,15 @@ mod tests {
])
.await
.unwrap();
// alix_group
// .add_members(vec![
// eri.account_address.clone(),
// frankie.account_address.clone(),
// ])
// .await
// .unwrap();
alix_group
.add_members(vec![
eri.account_address.clone(),
frankie.account_address.clone(),
])
.await
.unwrap();

// Bo sends messages to Alix while 2 epochs behind
// Bo sends messages to Alix while 3 epochs behind
bo_group.send("bo3".as_bytes().to_vec()).await.unwrap();
alix_group.send("alix3".as_bytes().to_vec()).await.unwrap();
bo_group.send("bo4".as_bytes().to_vec()).await.unwrap();
Expand All @@ -2553,8 +2553,8 @@ mod tests {
let bo_messages = bo_group
.find_messages(FfiListMessagesOptions::default())
.unwrap();
assert_eq!(bo_messages.len(), 8);
assert_eq!(alix_messages.len(), 9);
assert_eq!(bo_messages.len(), 9);
assert_eq!(alix_messages.len(), 10);

assert_eq!(
bo_messages[bo_messages.len() - 1].id,
Expand Down
57 changes: 57 additions & 0 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3364,4 +3364,61 @@ mod tests {
// group consent state should be allowed if user publishes a message to the group
assert_eq!(caro_group.consent_state().unwrap(), ConsentState::Allowed);
}

// TODO(rich): Generalize the test once fixed - test messages that are 0, 1, 2, 3, 4, 5 epochs behind
#[tokio::test]
async fn test_max_past_epochs() {
// Create group with two members
let bo_wallet = generate_local_wallet();
let alix = ClientBuilder::new_test_client(&generate_local_wallet()).await;
let bo = ClientBuilder::new_test_client(&bo_wallet).await;
let alix_group = alix
.create_group_with_members(
vec![bo_wallet.get_address()],
None,
GroupMetadataOptions::default(),
)
.await
.unwrap();
bo.sync_welcomes().await.unwrap();
let bo_groups = bo.find_groups(None, None, None, None).unwrap();
let bo_group = bo_groups.first().unwrap();

// Both members see the same amount of messages to start
alix_group
.send_message("alix 1".as_bytes(), &alix)
.await
.unwrap();
bo_group.send_message("bo 1".as_bytes(), &bo).await.unwrap();
alix_group.sync(&alix).await.unwrap();
bo_group.sync(&bo).await.unwrap();
let alix_messages = alix_group
.find_messages(Some(GroupMessageKind::Application), None, None, None, None)
.unwrap();
let bo_messages = bo_group
.find_messages(Some(GroupMessageKind::Application), None, None, None, None)
.unwrap();
assert_eq!(alix_messages.len(), 2);
assert_eq!(bo_messages.len(), 2);

// Alix moves the group forward by 1 epoch
alix_group
.update_group_name(&alix, "new name".to_string())
.await
.unwrap();
// Bo sends a message while 1 epoch behind
bo_group.send_message("bo 2".as_bytes(), &bo).await.unwrap();

// If max_past_epochs is working, Alix should be able to decrypt Bo's message
alix_group.sync(&alix).await.unwrap();
bo_group.sync(&bo).await.unwrap();
let alix_messages = alix_group
.find_messages(Some(GroupMessageKind::Application), None, None, None, None)
.unwrap();
let bo_messages = bo_group
.find_messages(Some(GroupMessageKind::Application), None, None, None, None)
.unwrap();
assert_eq!(bo_messages.len(), 3);
assert_eq!(alix_messages.len(), 3); // Fails here, 2 != 3
}
}

0 comments on commit e0921f0

Please sign in to comment.