From 4ec20ab9dc81805c54f10a4acdbbbb27357397c3 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 12 Mar 2025 20:43:17 +0000 Subject: [PATCH] test: return chat ID from TestContext.exec_securejoin_qr() --- src/test_utils.rs | 20 ++++++++++++++++---- src/tests/verified_chats.rs | 8 ++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index de41beb0b..33ebda85c 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -167,7 +167,10 @@ impl TestContextManager { ); } - pub async fn execute_securejoin(&self, scanner: &TestContext, scanned: &TestContext) { + /// Executes SecureJoin protocol between `scanner` and `scanned`. + /// + /// Returns chat ID of the 1:1 chat for `scanner`. + pub async fn execute_securejoin(&self, scanner: &TestContext, scanned: &TestContext) -> ChatId { self.section(&format!( "{} scans {}'s QR code", scanner.name(), @@ -175,12 +178,20 @@ impl TestContextManager { )); let qr = get_securejoin_qr(&scanned.ctx, None).await.unwrap(); - self.exec_securejoin_qr(scanner, scanned, &qr).await; + self.exec_securejoin_qr(scanner, scanned, &qr).await } /// Executes SecureJoin initiated by `scanner` scanning `qr` generated by `scanned`. - pub async fn exec_securejoin_qr(&self, scanner: &TestContext, scanned: &TestContext, qr: &str) { - join_securejoin(&scanner.ctx, qr).await.unwrap(); + /// + /// The [`ChatId`] of the created chat is returned, for a SetupContact QR this is the 1:1 + /// chat with `scanned`, for a SecureJoin QR this is the group chat. + pub async fn exec_securejoin_qr( + &self, + scanner: &TestContext, + scanned: &TestContext, + qr: &str, + ) -> ChatId { + let chat_id = join_securejoin(&scanner.ctx, qr).await.unwrap(); loop { if let Some(sent) = scanner.pop_sent_msg_opt(Duration::ZERO).await { @@ -191,6 +202,7 @@ impl TestContextManager { break; } } + chat_id } } diff --git a/src/tests/verified_chats.rs b/src/tests/verified_chats.rs index aa46671d7..4b8e9f072 100644 --- a/src/tests/verified_chats.rs +++ b/src/tests/verified_chats.rs @@ -186,14 +186,14 @@ async fn test_missing_peerstate_reexecute_securejoin() -> Result<()> { let alice_addr = alice.get_config(Config::Addr).await?.unwrap(); let bob = &tcm.bob().await; enable_verified_oneonone_chats(&[alice, bob]).await; - tcm.execute_securejoin(bob, alice).await; - let chat = bob.get_chat(alice).await; + let chat_id = tcm.execute_securejoin(bob, alice).await; + let chat = Chat::load_from_db(bob, chat_id).await?; assert!(chat.is_protected()); bob.sql .execute("DELETE FROM acpeerstates WHERE addr=?", (&alice_addr,)) .await?; - tcm.execute_securejoin(bob, alice).await; - let chat = bob.get_chat(alice).await; + let chat_id = tcm.execute_securejoin(bob, alice).await; + let chat = Chat::load_from_db(bob, chat_id).await?; assert!(chat.is_protected()); assert!(!chat.is_protection_broken()); Ok(())