Skip to content

Commit

Permalink
reproduce the member list issue in test
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Aug 5, 2024
1 parent 0a9aeab commit 410503d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 12 deletions.
8 changes: 4 additions & 4 deletions bindings_ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 75 additions & 2 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,10 @@ mod tests {
}

impl LocalWalletInboxOwner {
pub fn with_wallet(wallet: xmtp_cryptography::utils::LocalWallet) -> Self {
Self { wallet }
}

pub fn new() -> Self {
Self {
wallet: xmtp_cryptography::utils::LocalWallet::new(&mut rng()),
Expand Down Expand Up @@ -1607,8 +1611,11 @@ mod tests {
client.register_identity(signature_request).await.unwrap();
}

async fn new_test_client() -> Arc<FfiXmtpClient> {
let ffi_inbox_owner = LocalWalletInboxOwner::new();
/// Create a new test client with a given wallet.
async fn new_test_client_with_wallet(
wallet: xmtp_cryptography::utils::LocalWallet,
) -> Arc<FfiXmtpClient> {
let ffi_inbox_owner = LocalWalletInboxOwner::with_wallet(wallet);
let nonce = 1;
let inbox_id = generate_inbox_id(&ffi_inbox_owner.get_address(), &nonce);

Expand All @@ -1626,10 +1633,16 @@ mod tests {
)
.await
.unwrap();

register_client(&ffi_inbox_owner, &client).await;
client
}

async fn new_test_client() -> Arc<FfiXmtpClient> {
let wallet = xmtp_cryptography::utils::LocalWallet::new(&mut rng());
new_test_client_with_wallet(wallet).await
}

#[tokio::test]
async fn get_inbox_id() {
let client = new_test_client().await;
Expand Down Expand Up @@ -2228,6 +2241,66 @@ mod tests {
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_create_new_installation_without_breaking_group() {
let wallet1_key = &mut rng();
let wallet1 = xmtp_cryptography::utils::LocalWallet::new(wallet1_key);
let wallet2_key = &mut rng();
let wallet2 = xmtp_cryptography::utils::LocalWallet::new(wallet2_key);

// Create clients
let client1 = new_test_client_with_wallet(wallet1).await;
let client2 = new_test_client_with_wallet(wallet2.clone()).await;
// Create a new group with client1 including wallet2

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

// Sync groups
client1.conversations().sync().await.unwrap();
client2.conversations().sync().await.unwrap();

// Find groups for both clients
let client1_group = client1.group(group.id()).unwrap();
let client2_group = client2.group(group.id()).unwrap();

// Sync both groups
client1_group.sync().await.unwrap();
client2_group.sync().await.unwrap();

// Assert both clients see 2 members
let client1_members = client1_group.list_members().unwrap();
assert_eq!(client1_members.len(), 2);

let client2_members = client2_group.list_members().unwrap();
assert_eq!(client2_members.len(), 2);

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

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

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

// Assert client1 still sees 2 members
let client1_members = client1_group.list_members().unwrap();
assert_eq!(client1_members.len(), 2);

let client2_members = client2_group.list_members().unwrap();
assert_eq!(client2_members.len(), 2);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_can_add_members_when_out_of_sync() {
let alix = new_test_client().await;
Expand Down
13 changes: 7 additions & 6 deletions bindings_node/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 410503d

Please sign in to comment.