From ea076b3d769ebe9bc06931cac10a40924c221e28 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 14 Jul 2025 21:28:45 +0200 Subject: [PATCH] chore: Upgrade testing crates to Rust Edition 2024 --- .../matrix-sdk-integration-testing/Cargo.toml | 2 +- .../src/helpers.rs | 8 +-- .../src/tests/e2ee/mod.rs | 17 +++-- .../src/tests/e2ee/shared_history.rs | 4 +- .../src/tests/invitations.rs | 4 +- .../src/tests/nse.rs | 8 +-- .../src/tests/redaction.rs | 4 +- .../src/tests/repeated_join.rs | 2 +- .../src/tests/room.rs | 8 +-- .../src/tests/room_directory_search.rs | 4 +- .../src/tests/room_privacy.rs | 4 +- .../tests/sliding_sync/notification_client.rs | 8 +-- .../src/tests/sliding_sync/room.rs | 67 ++++++++++--------- .../src/tests/timeline.rs | 59 ++++++++-------- testing/matrix-sdk-test-macros/Cargo.toml | 2 +- testing/matrix-sdk-test-macros/src/lib.rs | 2 +- testing/matrix-sdk-test/Cargo.toml | 2 +- testing/matrix-sdk-test/src/event_factory.rs | 26 +++---- testing/matrix-sdk-test/src/lib.rs | 11 +-- testing/matrix-sdk-test/src/mocks.rs | 2 +- .../src/notification_settings/mod.rs | 2 +- .../matrix-sdk-test/src/sync_builder/bulk.rs | 2 +- .../src/sync_builder/invited_room.rs | 4 +- .../src/sync_builder/joined_room.rs | 10 +-- .../src/sync_builder/knocked_room.rs | 4 +- .../src/sync_builder/left_room.rs | 2 +- .../matrix-sdk-test/src/sync_builder/mod.rs | 8 +-- .../src/sync_builder/test_event.rs | 6 +- .../src/test_json/api_responses.rs | 2 +- .../src/test_json/keys_query.rs | 4 +- .../src/test_json/keys_query_sets.rs | 11 +-- .../matrix-sdk-test/src/test_json/members.rs | 2 +- testing/matrix-sdk-test/src/test_json/mod.rs | 2 +- .../src/test_json/search_users.rs | 2 +- testing/matrix-sdk-test/src/test_json/sync.rs | 4 +- .../src/test_json/sync_events.rs | 2 +- 36 files changed, 163 insertions(+), 148 deletions(-) diff --git a/testing/matrix-sdk-integration-testing/Cargo.toml b/testing/matrix-sdk-integration-testing/Cargo.toml index e6e68f6e1..c38956aa7 100644 --- a/testing/matrix-sdk-integration-testing/Cargo.toml +++ b/testing/matrix-sdk-integration-testing/Cargo.toml @@ -2,7 +2,7 @@ name = "matrix-sdk-integration-testing" description = "Internal integration testing for matrix-sdk crate" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false license = "Apache-2.0" diff --git a/testing/matrix-sdk-integration-testing/src/helpers.rs b/testing/matrix-sdk-integration-testing/src/helpers.rs index 183f10d06..39aeac1b2 100644 --- a/testing/matrix-sdk-integration-testing/src/helpers.rs +++ b/testing/matrix-sdk-integration-testing/src/helpers.rs @@ -10,21 +10,21 @@ use std::{ use anyhow::Result; use assign::assign; use matrix_sdk::{ + Client, ClientBuilder, Room, config::{RequestConfig, SyncSettings}, encryption::EncryptionSettings, ruma::{ + RoomId, api::client::{account::register::v3::Request as RegistrationRequest, uiaa}, time::Instant, - RoomId, }, sliding_sync::VersionBuilder, sync::SyncResponse, timeout::ElapsedError, - Client, ClientBuilder, Room, }; use once_cell::sync::Lazy; use rand::Rng as _; -use tempfile::{tempdir, TempDir}; +use tempfile::{TempDir, tempdir}; use tokio::{sync::Mutex, time::sleep}; /// This global maintains temp directories alive for the whole lifetime of the @@ -47,7 +47,7 @@ pub struct TestClientBuilder { impl TestClientBuilder { pub fn new(username: impl AsRef) -> Self { - let suffix: u128 = rand::thread_rng().gen(); + let suffix: u128 = rand::thread_rng().r#gen(); let randomized_username = format!("{}{}", username.as_ref(), suffix); Self::with_exact_username(randomized_username) } diff --git a/testing/matrix-sdk-integration-testing/src/tests/e2ee/mod.rs b/testing/matrix-sdk-integration-testing/src/tests/e2ee/mod.rs index 96787d206..587866f54 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/e2ee/mod.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/e2ee/mod.rs @@ -8,31 +8,30 @@ use assert_matches::assert_matches; use assert_matches2::assert_let; use assign::assign; use matrix_sdk::{ - assert_next_eq_with_timeout, - crypto::{format_emojis, SasState}, + Client, assert_next_eq_with_timeout, + crypto::{SasState, format_emojis}, encryption::{ + BackupDownloadStrategy, EncryptionSettings, LocalTrust, backups::BackupState, recovery::{Recovery, RecoveryState}, verification::{ QrVerificationData, QrVerificationState, Verification, VerificationRequestState, }, - BackupDownloadStrategy, EncryptionSettings, LocalTrust, }, ruma::{ + OwnedEventId, api::client::room::create_room::v3::Request as CreateRoomRequest, events::{ - key::verification::{request::ToDeviceKeyVerificationRequestEvent, VerificationMethod}, + GlobalAccountDataEventType, OriginalSyncMessageLikeEvent, + key::verification::{VerificationMethod, request::ToDeviceKeyVerificationRequestEvent}, room::message::{ MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent, SyncRoomMessageEvent, }, secret_storage::secret::SecretEventContent, - GlobalAccountDataEventType, OriginalSyncMessageLikeEvent, }, - OwnedEventId, }, timeout::timeout, - Client, }; use matrix_sdk_ui::{ notification_client::{NotificationClient, NotificationProcessSetup}, @@ -51,8 +50,8 @@ mod shared_history; // processed twice, meaning incorrect verification states will be found and the // process will fail, especially with user verification. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] -async fn test_mutual_sas_verification_with_notification_client_ignores_verification_events( -) -> Result<()> { +async fn test_mutual_sas_verification_with_notification_client_ignores_verification_events() +-> Result<()> { let encryption_settings = EncryptionSettings { auto_enable_cross_signing: true, ..Default::default() }; let alice = TestClientBuilder::new("alice") diff --git a/testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs b/testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs index 02087acaa..289f3ce99 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use anyhow::Result; use assert_matches2::assert_let; use assign::assign; -use futures::{pin_mut, FutureExt, StreamExt}; +use futures::{FutureExt, StreamExt, pin_mut}; use matrix_sdk::{ assert_decrypted_message_eq, encryption::EncryptionSettings, @@ -15,7 +15,7 @@ use matrix_sdk::{ use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent; use matrix_sdk_ui::sync_service::SyncService; use similar_asserts::assert_eq; -use tracing::{info, Instrument}; +use tracing::{Instrument, info}; use crate::helpers::{SyncTokenAwareClient, TestClientBuilder}; diff --git a/testing/matrix-sdk-integration-testing/src/tests/invitations.rs b/testing/matrix-sdk-integration-testing/src/tests/invitations.rs index 89d99351f..b6d6add75 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/invitations.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/invitations.rs @@ -1,7 +1,7 @@ -use anyhow::{ensure, Result}; +use anyhow::{Result, ensure}; use assign::assign; use matrix_sdk::{ - ruma::api::client::room::create_room::v3::Request as CreateRoomRequest, RoomState, + RoomState, ruma::api::client::room::create_room::v3::Request as CreateRoomRequest, }; use crate::helpers::TestClientBuilder; diff --git a/testing/matrix-sdk-integration-testing/src/tests/nse.rs b/testing/matrix-sdk-integration-testing/src/tests/nse.rs index 896518be8..8cf755cf3 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/nse.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/nse.rs @@ -8,22 +8,22 @@ use anyhow::Result; use assign::assign; use futures::Future; use matrix_sdk::{ + Client, Room, encryption::EncryptionSettings, ruma::{ + EventEncryptionAlgorithm, OwnedEventId, OwnedRoomId, RoomId, api::client::room::create_room::v3::Request as CreateRoomRequest, events::{ + AnyMessageLikeEventContent, AnySyncTimelineEvent, OriginalSyncMessageLikeEvent, room::{ encrypted::{OriginalSyncRoomEncryptedEvent, RoomEncryptedEventContent}, encryption::RoomEncryptionEventContent, message::{MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent}, }, room_key::ToDeviceRoomKeyEvent, - AnyMessageLikeEventContent, AnySyncTimelineEvent, OriginalSyncMessageLikeEvent, }, serde::Raw, - EventEncryptionAlgorithm, OwnedEventId, OwnedRoomId, RoomId, }, - Client, Room, }; use matrix_sdk_ui::{ notification_client::{ @@ -33,7 +33,7 @@ use matrix_sdk_ui::{ }; use serde_json::json; use tempfile::tempdir; -use tracing::{info, instrument, span, Level}; +use tracing::{Level, info, instrument, span}; use crate::helpers::{SyncTokenAwareClient, TestClientBuilder}; diff --git a/testing/matrix-sdk-integration-testing/src/tests/redaction.rs b/testing/matrix-sdk-integration-testing/src/tests/redaction.rs index 8f60afd08..f9756fd2e 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/redaction.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/redaction.rs @@ -2,15 +2,15 @@ use anyhow::Result; use assert_matches::assert_matches; use assign::assign; use matrix_sdk::{ + Client, config::SyncSettings, ruma::{ api::client::room::create_room::v3::Request as CreateRoomRequest, events::{ - room::name::{RoomNameEventContent, SyncRoomNameEvent}, AnySyncStateEvent, StateEventType, + room::name::{RoomNameEventContent, SyncRoomNameEvent}, }, }, - Client, }; use crate::helpers::TestClientBuilder; diff --git a/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs b/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs index 44c986c71..885c8ddce 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs @@ -3,12 +3,12 @@ use std::{sync::Arc, time::Duration}; use anyhow::Result; use assign::assign; use matrix_sdk::{ + Client, Room, RoomMemberships, RoomState, StateStoreExt, event_handler::Ctx, ruma::{ api::client::room::create_room::v3::Request as CreateRoomRequest, events::room::member::{MembershipState, StrippedRoomMemberEvent}, }, - Client, Room, RoomMemberships, RoomState, StateStoreExt, }; use matrix_sdk_common::executor::spawn; use tokio::sync::Notify; diff --git a/testing/matrix-sdk-integration-testing/src/tests/room.rs b/testing/matrix-sdk-integration-testing/src/tests/room.rs index d9f9575bd..ce1aa6a8a 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/room.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/room.rs @@ -3,24 +3,24 @@ use std::time::Duration; use anyhow::Result; use assert_matches2::{assert_let, assert_matches}; use matrix_sdk::{ + RoomState, room::MessagesOptions, ruma::{ api::client::room::create_room::v3::Request as CreateRoomRequest, assign, event_id, events, events::{ - room::message::RoomMessageEventContent, AnyRoomAccountDataEventContent, - AnySyncStateEvent, AnySyncTimelineEvent, EventContent, + AnyRoomAccountDataEventContent, AnySyncStateEvent, AnySyncTimelineEvent, EventContent, + room::message::RoomMessageEventContent, }, serde::Raw, uint, }, test_utils::assert_event_matches_msg, - RoomState, }; use tokio::{spawn, time::sleep}; use tracing::error; -use crate::helpers::{wait_for_room, TestClientBuilder}; +use crate::helpers::{TestClientBuilder, wait_for_room}; #[tokio::test] async fn test_event_with_context() -> Result<()> { diff --git a/testing/matrix-sdk-integration-testing/src/tests/room_directory_search.rs b/testing/matrix-sdk-integration-testing/src/tests/room_directory_search.rs index 79f240183..91ad47778 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/room_directory_search.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/room_directory_search.rs @@ -21,9 +21,9 @@ use eyeball_im::VectorDiff; use futures::StreamExt; use matrix_sdk::{ room_directory_search::RoomDirectorySearch, - ruma::api::client::room::{create_room::v3::Request as CreateRoomRequest, Visibility}, + ruma::api::client::room::{Visibility, create_room::v3::Request as CreateRoomRequest}, }; -use rand::{thread_rng, Rng}; +use rand::{Rng, thread_rng}; use stream_assert::assert_pending; use tokio::time::sleep; use tracing::warn; diff --git a/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs b/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs index 6b1a24799..c78fe7f83 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs @@ -19,9 +19,10 @@ use assign::assign; use matrix_sdk::{ config::SyncSettings, ruma::{ + RoomAliasId, api::client::{ directory::get_public_rooms_filtered, - room::{create_room::v3::Request as CreateRoomRequest, Visibility}, + room::{Visibility, create_room::v3::Request as CreateRoomRequest}, }, directory::Filter, events::room::{ @@ -32,7 +33,6 @@ use matrix_sdk::{ }, }, serde::Raw, - RoomAliasId, }, }; use matrix_sdk_base::ruma::events::room::canonical_alias::SyncRoomCanonicalAliasEvent; diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs index 14e5f25e7..42b8e5fcd 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs @@ -3,21 +3,21 @@ use std::sync::Arc; -use anyhow::{ensure, Result}; +use anyhow::{Result, ensure}; use assert_matches::assert_matches; use assert_matches2::assert_let; use matrix_sdk::{ + RoomState, config::SyncSettings, ruma::{ + OwnedEventId, api::client::room::create_room::v3::Request as CreateRoomRequest, assign, events::{ - room::{member::MembershipState, message::RoomMessageEventContent}, AnyStrippedStateEvent, SyncMessageLikeEvent, TimelineEventType, + room::{member::MembershipState, message::RoomMessageEventContent}, }, - OwnedEventId, }, - RoomState, }; use matrix_sdk_ui::{ notification_client::{ diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs index 8918fc9f7..02e15de07 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs @@ -11,12 +11,14 @@ use anyhow::Result; use assert_matches::assert_matches; use assert_matches2::assert_let; use eyeball_im::VectorDiff; -use futures_util::{pin_mut, StreamExt as _}; +use futures_util::{StreamExt as _, pin_mut}; use matrix_sdk::{ + Client, Room, RoomInfo, RoomMemberships, RoomState, SlidingSyncList, SlidingSyncMode, bytes::Bytes, config::SyncSettings, room_preview::RoomPreview, ruma::{ + RoomId, api::client::{ receipt::create_receipt::v3::ReceiptType, room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, @@ -24,29 +26,28 @@ use matrix_sdk::{ assign, directory::PublicRoomsChunkInit, events::{ + AnySyncMessageLikeEvent, InitialStateEvent, Mentions, StateEventType, receipt::ReceiptThread, room::{ history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, join_rules::{JoinRule, RoomJoinRulesEventContent}, message::RoomMessageEventContent, }, - AnySyncMessageLikeEvent, InitialStateEvent, Mentions, StateEventType, }, mxc_uri, owned_server_name, room_id, space::SpaceRoomJoinRule, - uint, RoomId, + uint, }, sliding_sync::VersionBuilder, test_utils::{logged_in_client_with_server, mocks::MatrixMockServer}, - Client, Room, RoomInfo, RoomMemberships, RoomState, SlidingSyncList, SlidingSyncMode, }; use matrix_sdk_base::ruma::{ api::client::sync::sync_events::v5 as http, owned_room_id, room_alias_id, }; use matrix_sdk_test::async_test; use matrix_sdk_ui::{ - room_list_service::filters::new_filter_all, sync_service::SyncService, timeline::RoomExt, - RoomListService, + RoomListService, room_list_service::filters::new_filter_all, sync_service::SyncService, + timeline::RoomExt, }; use once_cell::sync::Lazy; use rand::Rng as _; @@ -58,9 +59,9 @@ use tokio::{ time::{sleep, timeout}, }; use tracing::{debug, error, info, trace, warn}; -use wiremock::{matchers::AnyMatcher, Mock, MockServer}; +use wiremock::{Mock, MockServer, matchers::AnyMatcher}; -use crate::helpers::{wait_for_room, TestClientBuilder}; +use crate::helpers::{TestClientBuilder, wait_for_room}; #[tokio::test] async fn test_left_room() -> Result<()> { @@ -1060,7 +1061,7 @@ async fn test_room_preview() -> Result<()> { .await?; // Alice creates a room in which they're alone, to start with. - let suffix: u128 = rand::thread_rng().gen(); + let suffix: u128 = rand::thread_rng().r#gen(); let room_alias = format!("aliasy_mac_alias{suffix}"); let room = alice @@ -1142,13 +1143,15 @@ async fn test_room_preview_with_room_directory_search_and_room_alias_only() { .await; // Given a successful public room search - let chunks = vec![PublicRoomsChunkInit { - num_joined_members: uint!(0), - room_id: expected_room_id.to_owned(), - world_readable: true, - guest_can_join: true, - } - .into()]; + let chunks = vec![ + PublicRoomsChunkInit { + num_joined_members: uint!(0), + room_id: expected_room_id.to_owned(), + world_readable: true, + guest_can_join: true, + } + .into(), + ]; server.mock_public_rooms().ok(chunks, None, None, Some(1)).mock_once().mount().await; // The room preview is found @@ -1184,24 +1187,28 @@ async fn test_room_preview_with_room_directory_search_and_room_alias_only_in_sev ( via_1.to_owned(), // The actual room we want - vec![PublicRoomsChunkInit { - num_joined_members: uint!(0), - room_id: expected_room_id.to_owned(), - world_readable: true, - guest_can_join: true, - } - .into()], + vec![ + PublicRoomsChunkInit { + num_joined_members: uint!(0), + room_id: expected_room_id.to_owned(), + world_readable: true, + guest_can_join: true, + } + .into(), + ], ), ( via_2.to_owned(), // Some other room - vec![PublicRoomsChunkInit { - num_joined_members: uint!(1), - room_id: owned_room_id!("!some-other-room:matrix.org"), - world_readable: true, - guest_can_join: true, - } - .into()], + vec![ + PublicRoomsChunkInit { + num_joined_members: uint!(1), + room_id: owned_room_id!("!some-other-room:matrix.org"), + world_readable: true, + guest_can_join: true, + } + .into(), + ], ), ]); server diff --git a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs index 24e55e6eb..0bd1ac9a8 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs @@ -22,27 +22,26 @@ use eyeball_im::{Vector, VectorDiff}; use futures::pin_mut; use futures_util::{FutureExt, StreamExt}; use matrix_sdk::{ - assert_next_with_timeout, + Client, Room, RoomState, assert_next_with_timeout, config::SyncSettings, deserialized_responses::{VerificationLevel, VerificationState}, - encryption::{backups::BackupState, EncryptionSettings}, + encryption::{EncryptionSettings, backups::BackupState}, room::edit::EditedContent, ruma::{ + MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, api::client::room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, events::{ - room::{encryption::RoomEncryptionEventContent, message::RoomMessageEventContent}, InitialStateEvent, + room::{encryption::RoomEncryptionEventContent, message::RoomMessageEventContent}, }, - MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, }, - Client, Room, RoomState, }; use matrix_sdk_ui::{ + Timeline, notification_client::NotificationClient, room_list_service::RoomListLoadingState, sync_service::SyncService, timeline::{EventSendState, EventTimelineItem, ReactionStatus, RoomExt, TimelineItem}, - Timeline, }; use similar_asserts::assert_eq; use stream_assert::assert_pending; @@ -397,9 +396,10 @@ async fn test_enabling_backups_retries_decryption() { debug!("Creating room…"); - let initial_state = - vec![InitialStateEvent::new(RoomEncryptionEventContent::with_recommended_defaults()) - .to_raw_any()]; + let initial_state = vec![ + InitialStateEvent::new(RoomEncryptionEventContent::with_recommended_defaults()) + .to_raw_any(), + ]; let room = alice .create_room(assign!(CreateRoomRequest::new(), { @@ -410,11 +410,12 @@ async fn test_enabling_backups_retries_decryption() { .await .unwrap(); - assert!(room - .latest_encryption_state() - .await - .expect("We should be able to check that the room is encrypted") - .is_encrypted()); + assert!( + room.latest_encryption_state() + .await + .expect("We should be able to check that the room is encrypted") + .is_encrypted() + ); let event_id = room .send(RoomMessageEventContent::text_plain("It's a secret to everybody!")) @@ -533,9 +534,10 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() { debug!("Creating the room…"); // The room needs to be encrypted. - let initial_state = - vec![InitialStateEvent::new(RoomEncryptionEventContent::with_recommended_defaults()) - .to_raw_any()]; + let initial_state = vec![ + InitialStateEvent::new(RoomEncryptionEventContent::with_recommended_defaults()) + .to_raw_any(), + ]; let alice_room = alice .create_room(assign!(CreateRoomRequest::new(), { @@ -546,11 +548,13 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() { .await .unwrap(); - assert!(alice_room - .latest_encryption_state() - .await - .expect("We should be able to check that the room is encrypted") - .is_encrypted()); + assert!( + alice_room + .latest_encryption_state() + .await + .expect("We should be able to check that the room is encrypted") + .is_encrypted() + ); // Create stream listening for devices. let devices_stream = alice @@ -795,11 +799,12 @@ async fn test_new_users_first_messages_dont_warn_about_insecure_device_if_it_is_ .await .expect("should not fail to create room"); - assert!(room - .latest_encryption_state() - .await - .expect("should be able to check that the room is encrypted") - .is_encrypted()); + assert!( + room.latest_encryption_state() + .await + .expect("should be able to check that the room is encrypted") + .is_encrypted() + ); room } diff --git a/testing/matrix-sdk-test-macros/Cargo.toml b/testing/matrix-sdk-test-macros/Cargo.toml index c43f9aea7..50b8ef082 100644 --- a/testing/matrix-sdk-test-macros/Cargo.toml +++ b/testing/matrix-sdk-test-macros/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["stoically "] description = "Helper macros to write tests for the Matrix SDK" -edition = "2021" +edition = "2024" homepage = "https://github.com/matrix-org/matrix-rust-sdk" keywords = ["matrix", "chat", "messaging", "ruma"] license = "Apache-2.0" diff --git a/testing/matrix-sdk-test-macros/src/lib.rs b/testing/matrix-sdk-test-macros/src/lib.rs index a5e9aab18..d50ecd713 100644 --- a/testing/matrix-sdk-test-macros/src/lib.rs +++ b/testing/matrix-sdk-test-macros/src/lib.rs @@ -1,5 +1,5 @@ use proc_macro::TokenStream; -use quote::{format_ident, quote, ToTokens}; +use quote::{ToTokens, format_ident, quote}; use syn::parse_macro_input; /// Attribute to use `wasm_bindgen_test` for wasm32 targets and `tokio::test` diff --git a/testing/matrix-sdk-test/Cargo.toml b/testing/matrix-sdk-test/Cargo.toml index 5a180a9bd..275fbbb19 100644 --- a/testing/matrix-sdk-test/Cargo.toml +++ b/testing/matrix-sdk-test/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Damir Jelić "] description = "Helpers to write tests for the Matrix SDK" -edition = "2021" +edition = "2024" homepage = "https://github.com/matrix-org/matrix-rust-sdk" keywords = ["matrix", "chat", "messaging", "ruma"] license = "Apache-2.0" diff --git a/testing/matrix-sdk-test/src/event_factory.rs b/testing/matrix-sdk-test/src/event_factory.rs index 64afcbc34..c76f91d62 100644 --- a/testing/matrix-sdk-test/src/event_factory.rs +++ b/testing/matrix-sdk-test/src/event_factory.rs @@ -24,12 +24,18 @@ use matrix_sdk_common::deserialized_responses::{ TimelineEvent, UnableToDecryptInfo, UnableToDecryptReason, }; use ruma::{ + EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, + OwnedRoomId, OwnedTransactionId, OwnedUserId, OwnedVoipId, RoomId, RoomVersionId, + TransactionId, UInt, UserId, VoipVersionId, events::{ + AnyMessageLikeEvent, AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, + AnyTimelineEvent, BundledMessageLikeRelations, Mentions, RedactedMessageLikeEventContent, + RedactedStateEventContent, StateEventContent, StaticEventContent, beacon::BeaconEventContent, call::{ + SessionDescription, invite::CallInviteEventContent, notify::{ApplicationType, CallNotifyEventContent, NotifyType}, - SessionDescription, }, member_hints::MemberHintsEventContent, poll::{ @@ -44,6 +50,7 @@ use ruma::{ receipt::{Receipt, ReceiptEventContent, ReceiptThread, ReceiptType}, relation::{Annotation, BundledThread, InReplyTo, Replacement, Thread}, room::{ + ImageInfo, avatar::{self, RoomAvatarEventContent}, canonical_alias::RoomCanonicalAliasEventContent, create::{PreviousRoom, RoomCreateEventContent}, @@ -60,18 +67,12 @@ use ruma::{ server_acl::RoomServerAclEventContent, tombstone::RoomTombstoneEventContent, topic::RoomTopicEventContent, - ImageInfo, }, sticker::StickerEventContent, typing::TypingEventContent, - AnyMessageLikeEvent, AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, - AnyTimelineEvent, BundledMessageLikeRelations, Mentions, RedactedMessageLikeEventContent, - RedactedStateEventContent, StateEventContent, StaticEventContent, }, serde::Raw, - server_name, EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri, - OwnedRoomAliasId, OwnedRoomId, OwnedTransactionId, OwnedUserId, OwnedVoipId, RoomId, - RoomVersionId, TransactionId, UInt, UserId, VoipVersionId, + server_name, }; use serde::Serialize; use serde_json::json; @@ -554,8 +555,8 @@ impl EventFactory { /// use matrix_sdk_test::event_factory::EventFactory; /// use ruma::{ /// events::{ - /// room::member::{MembershipState, RoomMemberEventContent}, /// SyncStateEvent, + /// room::member::{MembershipState, RoomMemberEventContent}, /// }, /// room_id, /// serde::Raw, @@ -626,7 +627,7 @@ impl EventFactory { /// /// use matrix_sdk_test::event_factory::EventFactory; /// use ruma::{ - /// events::{member_hints::MemberHintsEventContent, SyncStateEvent}, + /// events::{SyncStateEvent, member_hints::MemberHintsEventContent}, /// owned_user_id, room_id, /// serde::Raw, /// user_id, @@ -892,10 +893,11 @@ impl EventFactory { /// ``` /// use matrix_sdk_test::event_factory::EventFactory; /// use ruma::{ - /// events::{beacon::BeaconEventContent, MessageLikeEvent}, + /// MilliSecondsSinceUnixEpoch, + /// events::{MessageLikeEvent, beacon::BeaconEventContent}, /// owned_event_id, room_id, /// serde::Raw, - /// user_id, MilliSecondsSinceUnixEpoch, + /// user_id, /// }; /// /// let factory = EventFactory::new().room(room_id!("!test:localhost")); diff --git a/testing/matrix-sdk-test/src/lib.rs b/testing/matrix-sdk-test/src/lib.rs index b70ea0fd7..78a861512 100644 --- a/testing/matrix-sdk-test/src/lib.rs +++ b/testing/matrix-sdk-test/src/lib.rs @@ -2,10 +2,11 @@ use http::Response; pub use matrix_sdk_test_macros::async_test; use once_cell::sync::Lazy; use ruma::{ + RoomId, UserId, api::{ - client::sync::sync_events::v3::Response as SyncResponse, IncomingResponse, OutgoingResponse, + IncomingResponse, OutgoingResponse, client::sync::sync_events::v3::Response as SyncResponse, }, - room_id, user_id, RoomId, UserId, + room_id, user_id, }; use serde_json::Value as JsonValue; @@ -120,9 +121,9 @@ mod sync_builder; pub mod test_json; pub use self::sync_builder::{ - bulk_room_members, GlobalAccountDataTestEvent, InvitedRoomBuilder, JoinedRoomBuilder, - KnockedRoomBuilder, LeftRoomBuilder, PresenceTestEvent, RoomAccountDataTestEvent, - StateTestEvent, StrippedStateTestEvent, SyncResponseBuilder, + GlobalAccountDataTestEvent, InvitedRoomBuilder, JoinedRoomBuilder, KnockedRoomBuilder, + LeftRoomBuilder, PresenceTestEvent, RoomAccountDataTestEvent, StateTestEvent, + StrippedStateTestEvent, SyncResponseBuilder, bulk_room_members, }; pub static ALICE: Lazy<&UserId> = Lazy::new(|| user_id!("@alice:server.name")); diff --git a/testing/matrix-sdk-test/src/mocks.rs b/testing/matrix-sdk-test/src/mocks.rs index 1fabb3636..9e15cee32 100644 --- a/testing/matrix-sdk-test/src/mocks.rs +++ b/testing/matrix-sdk-test/src/mocks.rs @@ -15,8 +15,8 @@ //! Mocks useful to reuse across different testing contexts. use wiremock::{ - matchers::{header, method, path_regex}, Mock, MockServer, ResponseTemplate, + matchers::{header, method, path_regex}, }; use crate::test_json; diff --git a/testing/matrix-sdk-test/src/notification_settings/mod.rs b/testing/matrix-sdk-test/src/notification_settings/mod.rs index be55d7c8a..e86b82bc1 100644 --- a/testing/matrix-sdk-test/src/notification_settings/mod.rs +++ b/testing/matrix-sdk-test/src/notification_settings/mod.rs @@ -1,9 +1,9 @@ use ruma::{ + RoomId, UserId, push::{ Action, NewConditionalPushRule, NewPushRule, NewSimplePushRule, PushCondition, RuleKind, Ruleset, Tweak, }, - RoomId, UserId, }; pub fn get_server_default_ruleset() -> Ruleset { diff --git a/testing/matrix-sdk-test/src/sync_builder/bulk.rs b/testing/matrix-sdk-test/src/sync_builder/bulk.rs index 5ddf10d56..bd5eb89ee 100644 --- a/testing/matrix-sdk-test/src/sync_builder/bulk.rs +++ b/testing/matrix-sdk-test/src/sync_builder/bulk.rs @@ -1,7 +1,7 @@ use std::ops::Range; use ruma::{ - events::{room::member::MembershipState, AnySyncStateEvent}, + events::{AnySyncStateEvent, room::member::MembershipState}, serde::Raw, }; use serde_json::{from_value as from_json_value, json}; diff --git a/testing/matrix-sdk-test/src/sync_builder/invited_room.rs b/testing/matrix-sdk-test/src/sync_builder/invited_room.rs index 16a821eba..67475bf32 100644 --- a/testing/matrix-sdk-test/src/sync_builder/invited_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/invited_room.rs @@ -1,6 +1,6 @@ use ruma::{ - api::client::sync::sync_events::v3::InvitedRoom, events::AnyStrippedStateEvent, serde::Raw, - OwnedRoomId, RoomId, + OwnedRoomId, RoomId, api::client::sync::sync_events::v3::InvitedRoom, + events::AnyStrippedStateEvent, serde::Raw, }; use super::StrippedStateTestEvent; diff --git a/testing/matrix-sdk-test/src/sync_builder/joined_room.rs b/testing/matrix-sdk-test/src/sync_builder/joined_room.rs index ca98fcff3..bc146d877 100644 --- a/testing/matrix-sdk-test/src/sync_builder/joined_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/joined_room.rs @@ -1,16 +1,16 @@ use ruma::{ + OwnedRoomId, RoomId, api::client::sync::sync_events::v3::JoinedRoom, events::{ - receipt::ReceiptEventContent, typing::TypingEventContent, AnyRoomAccountDataEvent, - AnySyncStateEvent, AnySyncTimelineEvent, + AnyRoomAccountDataEvent, AnySyncStateEvent, AnySyncTimelineEvent, + receipt::ReceiptEventContent, typing::TypingEventContent, }, serde::Raw, - OwnedRoomId, RoomId, }; -use serde_json::{from_value as from_json_value, Value as JsonValue}; +use serde_json::{Value as JsonValue, from_value as from_json_value}; use super::RoomAccountDataTestEvent; -use crate::{event_factory::EventBuilder, DEFAULT_TEST_ROOM_ID}; +use crate::{DEFAULT_TEST_ROOM_ID, event_factory::EventBuilder}; pub struct JoinedRoomBuilder { pub(super) room_id: OwnedRoomId, diff --git a/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs b/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs index 2d488eb13..065636ab4 100644 --- a/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs @@ -1,6 +1,6 @@ use ruma::{ - api::client::sync::sync_events::v3::KnockedRoom, events::AnyStrippedStateEvent, serde::Raw, - OwnedRoomId, RoomId, + OwnedRoomId, RoomId, api::client::sync::sync_events::v3::KnockedRoom, + events::AnyStrippedStateEvent, serde::Raw, }; use super::StrippedStateTestEvent; diff --git a/testing/matrix-sdk-test/src/sync_builder/left_room.rs b/testing/matrix-sdk-test/src/sync_builder/left_room.rs index b4d8f0e41..8ef530466 100644 --- a/testing/matrix-sdk-test/src/sync_builder/left_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/left_room.rs @@ -1,8 +1,8 @@ use ruma::{ + OwnedRoomId, RoomId, api::client::sync::sync_events::v3::LeftRoom, events::{AnyRoomAccountDataEvent, AnySyncStateEvent, AnySyncTimelineEvent}, serde::Raw, - OwnedRoomId, RoomId, }; use super::{RoomAccountDataTestEvent, StateTestEvent}; diff --git a/testing/matrix-sdk-test/src/sync_builder/mod.rs b/testing/matrix-sdk-test/src/sync_builder/mod.rs index c27b286b4..3ac56b89f 100644 --- a/testing/matrix-sdk-test/src/sync_builder/mod.rs +++ b/testing/matrix-sdk-test/src/sync_builder/mod.rs @@ -2,17 +2,17 @@ use std::collections::HashMap; use http::Response; use ruma::{ + OwnedRoomId, OwnedUserId, UserId, api::{ + IncomingResponse, client::sync::sync_events::v3::{ InvitedRoom, JoinedRoom, KnockedRoom, LeftRoom, Response as SyncResponse, }, - IncomingResponse, }, - events::{presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyToDeviceEvent}, + events::{AnyGlobalAccountDataEvent, AnyToDeviceEvent, presence::PresenceEvent}, serde::Raw, - OwnedRoomId, OwnedUserId, UserId, }; -use serde_json::{from_value as from_json_value, json, Value as JsonValue}; +use serde_json::{Value as JsonValue, from_value as from_json_value, json}; use super::test_json; diff --git a/testing/matrix-sdk-test/src/sync_builder/test_event.rs b/testing/matrix-sdk-test/src/sync_builder/test_event.rs index 6b8cd5ce4..3d864804a 100644 --- a/testing/matrix-sdk-test/src/sync_builder/test_event.rs +++ b/testing/matrix-sdk-test/src/sync_builder/test_event.rs @@ -1,11 +1,11 @@ use ruma::{ events::{ - presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, - AnyStrippedStateEvent, AnySyncStateEvent, + AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, + AnySyncStateEvent, presence::PresenceEvent, }, serde::Raw, }; -use serde_json::{from_value as from_json_value, Value as JsonValue}; +use serde_json::{Value as JsonValue, from_value as from_json_value}; use crate::test_json; diff --git a/testing/matrix-sdk-test/src/test_json/api_responses.rs b/testing/matrix-sdk-test/src/test_json/api_responses.rs index 7aa35b616..6e726aa60 100644 --- a/testing/matrix-sdk-test/src/test_json/api_responses.rs +++ b/testing/matrix-sdk-test/src/test_json/api_responses.rs @@ -1,7 +1,7 @@ //! Responses to client API calls. use once_cell::sync::Lazy; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; /// `GET /_matrix/client/v3/devices` pub static DEVICES: Lazy = Lazy::new(|| { diff --git a/testing/matrix-sdk-test/src/test_json/keys_query.rs b/testing/matrix-sdk-test/src/test_json/keys_query.rs index c09cf48e7..167713f0d 100644 --- a/testing/matrix-sdk-test/src/test_json/keys_query.rs +++ b/testing/matrix-sdk-test/src/test_json/keys_query.rs @@ -19,8 +19,8 @@ use std::{collections::HashMap, iter}; use ruma::{ - api::client::keys::get_keys::v3::Response as KeyQueryResponse, device_id, user_id, DeviceId, - UserId, + DeviceId, UserId, api::client::keys::get_keys::v3::Response as KeyQueryResponse, device_id, + user_id, }; use serde_json::json; diff --git a/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs b/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs index daeb08f2b..75ce3cf21 100644 --- a/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs +++ b/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs @@ -2,18 +2,19 @@ use std::{collections::BTreeMap, default::Default}; use insta::{assert_json_snapshot, with_settings}; use ruma::{ + CanonicalJsonValue, CrossSigningKeyId, CrossSigningOrDeviceSignatures, + CrossSigningOrDeviceSigningKeyId, DeviceId, OwnedBase64PublicKey, + OwnedBase64PublicKeyOrDeviceId, OwnedDeviceId, OwnedUserId, SigningKeyAlgorithm, UserId, api::client::keys::get_keys::v3::Response as KeyQueryResponse, device_id, encryption::{CrossSigningKey, DeviceKeys, KeyUsage}, serde::Raw, - user_id, CanonicalJsonValue, CrossSigningKeyId, CrossSigningOrDeviceSignatures, - CrossSigningOrDeviceSigningKeyId, DeviceId, OwnedBase64PublicKey, - OwnedBase64PublicKeyOrDeviceId, OwnedDeviceId, OwnedUserId, SigningKeyAlgorithm, UserId, + user_id, }; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use vodozemac::{Curve25519PublicKey, Ed25519PublicKey, Ed25519SecretKey, Ed25519Signature}; -use super::keys_query::{keys_query, master_keys, KeysQueryUser}; +use super::keys_query::{KeysQueryUser, keys_query, master_keys}; use crate::{ ruma_response_from_json, ruma_response_to_json, test_json::keys_query::{device_keys_payload, self_signing_keys}, diff --git a/testing/matrix-sdk-test/src/test_json/members.rs b/testing/matrix-sdk-test/src/test_json/members.rs index 06d757bc0..c4915e40f 100644 --- a/testing/matrix-sdk-test/src/test_json/members.rs +++ b/testing/matrix-sdk-test/src/test_json/members.rs @@ -1,7 +1,7 @@ //! Example responses to `GET /_matrix/client/v3/rooms/{roomId}/members` use once_cell::sync::Lazy; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; use super::DEFAULT_TEST_ROOM_ID; diff --git a/testing/matrix-sdk-test/src/test_json/mod.rs b/testing/matrix-sdk-test/src/test_json/mod.rs index 4ccb8ec8d..79ecd74a8 100644 --- a/testing/matrix-sdk-test/src/test_json/mod.rs +++ b/testing/matrix-sdk-test/src/test_json/mod.rs @@ -5,7 +5,7 @@ //! the test data needs to be contained within this crate. use once_cell::sync::Lazy; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; use crate::DEFAULT_TEST_ROOM_ID; diff --git a/testing/matrix-sdk-test/src/test_json/search_users.rs b/testing/matrix-sdk-test/src/test_json/search_users.rs index e43937b31..3ab9c96a2 100644 --- a/testing/matrix-sdk-test/src/test_json/search_users.rs +++ b/testing/matrix-sdk-test/src/test_json/search_users.rs @@ -1,5 +1,5 @@ use once_cell::sync::Lazy; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; pub static SEARCH_USERS_REQUEST: Lazy = Lazy::new(|| { json!({ diff --git a/testing/matrix-sdk-test/src/test_json/sync.rs b/testing/matrix-sdk-test/src/test_json/sync.rs index 0cb611ee1..e9d9648fa 100644 --- a/testing/matrix-sdk-test/src/test_json/sync.rs +++ b/testing/matrix-sdk-test/src/test_json/sync.rs @@ -1,8 +1,8 @@ //! Complete sync responses. use once_cell::sync::Lazy; -use ruma::{room_id, RoomId}; -use serde_json::{json, Value as JsonValue}; +use ruma::{RoomId, room_id}; +use serde_json::{Value as JsonValue, json}; use crate::DEFAULT_TEST_ROOM_ID; diff --git a/testing/matrix-sdk-test/src/test_json/sync_events.rs b/testing/matrix-sdk-test/src/test_json/sync_events.rs index 7ca590a72..f655c58cb 100644 --- a/testing/matrix-sdk-test/src/test_json/sync_events.rs +++ b/testing/matrix-sdk-test/src/test_json/sync_events.rs @@ -1,7 +1,7 @@ //! Discrete events found in a sync response. use once_cell::sync::Lazy; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; use crate::DEFAULT_TEST_ROOM_ID;