From b7543d9bc7e4ecb3c8b3666e87772b813fc32812 Mon Sep 17 00:00:00 2001 From: Richard Hua Date: Wed, 24 Jul 2024 15:23:56 -0700 Subject: [PATCH] Add test to make sure commits work when out of sync --- bindings_ffi/src/mls.rs | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index c641b4f9e..70ec8c8ea 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -2156,6 +2156,66 @@ mod tests { assert!(stream_messages.is_closed()); } + #[tokio::test(flavor = "multi_thread", worker_threads = 5)] + async fn test_can_add_members_when_out_of_sync() { + let alix = new_test_client().await; + let bo = new_test_client().await; + let caro = new_test_client().await; + let davon = new_test_client().await; + let eri = new_test_client().await; + let frankie = new_test_client().await; + + let alix_group = alix + .conversations() + .create_group( + vec![bo.account_address.clone()], + FfiCreateGroupOptions::default(), + ) + .await + .unwrap(); + + bo.conversations().sync().await.unwrap(); + let bo_group = bo.group(alix_group.id()).unwrap(); + + 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 3 epochs (as Alix's max_past_epochs is + // configured to 3) without Bo syncing + alix_group + .add_members(vec![ + caro.account_address.clone(), + davon.account_address.clone(), + ]) + .await + .unwrap(); + alix_group + .remove_members(vec![ + caro.account_address.clone(), + davon.account_address.clone(), + ]) + .await + .unwrap(); + alix_group + .add_members(vec![eri.account_address.clone()]) + .await + .unwrap(); + + // Bo adds a member while 3 epochs behind + bo_group + .add_members(vec![frankie.account_address.clone()]) + .await + .unwrap(); + + bo_group.sync().await.unwrap(); + let bo_members = bo_group.list_members().unwrap(); + assert_eq!(bo_members.len(), 4); + + alix_group.sync().await.unwrap(); + let alix_members = alix_group.list_members().unwrap(); + assert_eq!(alix_members.len(), 4); + } + #[tokio::test(flavor = "multi_thread", worker_threads = 5)] async fn test_can_send_message_when_out_of_sync() { let alix = new_test_client().await;