Skip to content

Commit

Permalink
write a test to reproduce the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Aug 15, 2024
1 parent 44924a2 commit 8410b7a
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,98 @@ mod tests {
assert_eq!(client2_members.len(), 2);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_create_new_installations_does_not_fork_group() {
let bo_wallet_key = &mut rng();
let bo_wallet = xmtp_cryptography::utils::LocalWallet::new(bo_wallet_key);

// Create clients
let alix = new_test_client().await;
let bo = new_test_client_with_wallet(bo_wallet.clone()).await;
let caro = new_test_client().await;

let message_callbacks = RustStreamCallback::default();
let stream_messages = alix
.conversations()
.stream_all_messages(Box::new(message_callbacks.clone()))
.await;
stream_messages.wait_for_ready().await;

let group = alix
.conversations()
.create_group(
vec![bo.account_address.clone(), caro.account_address.clone()],
FfiCreateGroupOptions::default(),
)
.await
.unwrap();

// Sync groups
alix.conversations().sync().await.unwrap();
bo.conversations().sync().await.unwrap();
caro.conversations().sync().await.unwrap();

// Find groups for both clients
let alix_group = alix.group(group.id()).unwrap();
let caro_group = bo.group(group.id()).unwrap();

// Send messages
alix_group
.send("First message".as_bytes().to_vec())
.await
.unwrap();

caro_group
.send("Second message".as_bytes().to_vec())
.await
.unwrap();

// Drop and delete local database for client2
bo.release_db_connection().unwrap();

// Recreate client2 (new installation)
let bo2 = new_test_client_with_wallet(bo_wallet).await;

// let bo_message_callbacks = RustStreamCallback::default();
// let bo_stream_messages = bo2
// .conversations()
// .stream_all_messages(Box::new(bo_message_callbacks.clone()))
// .await;
// bo_stream_messages.wait_for_ready().await;

// Send a message that will break the group
alix_group
.send("Third message".as_bytes().to_vec())
.await
.unwrap();

let bo_group = bo2.group(group.id()).unwrap();

bo_group
.send("Fourth message".as_bytes().to_vec())
.await
.unwrap();

caro_group
.send("Fifth message".as_bytes().to_vec())
.await
.unwrap();

let caro_messages = caro_group
.find_messages(FfiListMessagesOptions::default())
.unwrap();
let alix_messages = alix_group
.find_messages(FfiListMessagesOptions::default())
.unwrap();
let bo_messages = bo_group
.find_messages(FfiListMessagesOptions::default())
.unwrap();

assert_eq!(caro_messages.len(), 5);
assert_eq!(alix_messages.len(), 6);
assert_eq!(bo_messages.len(), 5);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_can_send_messages_when_epochs_behind() {
let alix = new_test_client().await;
Expand Down

0 comments on commit 8410b7a

Please sign in to comment.