Skip to content

Commit

Permalink
Initial Bindings Test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieobject committed Apr 10, 2024
1 parent 2826cac commit 175c420
Showing 1 changed file with 117 additions and 78 deletions.
195 changes: 117 additions & 78 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,84 +954,84 @@ mod tests {
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_conversation_streaming() {
let amal = new_test_client().await;
let bola = new_test_client().await;

let stream_callback = RustStreamCallback::new();

let stream = bola
.conversations()
.stream(Box::new(stream_callback.clone()))
.await
.unwrap();

tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

amal.conversations()
.create_group(vec![bola.account_address()], None)
.await
.unwrap();

tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

assert_eq!(stream_callback.message_count(), 1);
// Create another group and add bola
amal.conversations()
.create_group(vec![bola.account_address()], None)
.await
.unwrap();

tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
assert_eq!(stream_callback.message_count(), 2);

stream.end();
tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
assert!(stream.is_closed());
}

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

let alix_group = alix
.conversations()
.create_group(vec![caro.account_address()], None)
.await
.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

let stream_callback = RustStreamCallback::new();
let stream = caro
.conversations()
.stream_all_messages(Box::new(stream_callback.clone()))
.await
.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

alix_group.send("first".as_bytes().to_vec()).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
let bo_group = bo
.conversations()
.create_group(vec![caro.account_address()], None)
.await
.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
bo_group.send("second".as_bytes().to_vec()).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
alix_group.send("third".as_bytes().to_vec()).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
bo_group.send("fourth".as_bytes().to_vec()).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

assert_eq!(stream_callback.message_count(), 4);
stream.end();
tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
assert!(stream.is_closed());
}
// #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
// async fn test_conversation_streaming() {
// let amal = new_test_client().await;
// let bola = new_test_client().await;

// let stream_callback = RustStreamCallback::new();

// let stream = bola
// .conversations()
// .stream(Box::new(stream_callback.clone()))
// .await
// .unwrap();

// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

// amal.conversations()
// .create_group(vec![bola.account_address()], None)
// .await
// .unwrap();

// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

// assert_eq!(stream_callback.message_count(), 1);
// // Create another group and add bola
// amal.conversations()
// .create_group(vec![bola.account_address()], None)
// .await
// .unwrap();

// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
// assert_eq!(stream_callback.message_count(), 2);

// stream.end();
// tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
// assert!(stream.is_closed());
// }

// #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
// async fn test_stream_all_messages() {
// let alix = new_test_client().await;
// let bo = new_test_client().await;
// let caro = new_test_client().await;

// let alix_group = alix
// .conversations()
// .create_group(vec![caro.account_address()], None)
// .await
// .unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

// let stream_callback = RustStreamCallback::new();
// let stream = caro
// .conversations()
// .stream_all_messages(Box::new(stream_callback.clone()))
// .await
// .unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

// alix_group.send("first".as_bytes().to_vec()).await.unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
// let bo_group = bo
// .conversations()
// .create_group(vec![caro.account_address()], None)
// .await
// .unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
// bo_group.send("second".as_bytes().to_vec()).await.unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
// alix_group.send("third".as_bytes().to_vec()).await.unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
// bo_group.send("fourth".as_bytes().to_vec()).await.unwrap();
// tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;

// assert_eq!(stream_callback.message_count(), 4);
// stream.end();
// tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
// assert!(stream.is_closed());
// }

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_message_streaming() {
Expand Down Expand Up @@ -1125,4 +1125,43 @@ mod tests {
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
assert!(stream_closer.is_closed());
}

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_group_who_added_me() {
// Create Clients
let amal = new_test_client().await;
let bola = new_test_client().await;

// Amal creates a group and adds Bola to the group
amal.conversations()
.create_group(vec![bola.account_address()], None)
.await
.unwrap();

// 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_conversations = bola.conversations();
let _ = bola_conversations.sync().await;

// Bola gets the group id. This will be needed to fetch the group from
// the database.
let bola_groups = bola_conversations
.list(
crate::FfiListConversationsOptions {
created_after_ns: None,
created_before_ns: None,
limit: None
}
)
.await
.unwrap();

let bola_group = bola_groups.first().unwrap();

// Check Bola's group for the added_by_address of the inviter
let added_by_address = bola_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!");
}
}

0 comments on commit 175c420

Please sign in to comment.