Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions xmtp_db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ xmtp_configuration.workspace = true
xmtp_proto.workspace = true
zeroize.workspace = true

futures = { workspace = true, optional = true }
mockall = { workspace = true, optional = true }
tokio = { workspace = true, optional = true, features = [
"macros",
Expand Down Expand Up @@ -94,6 +95,7 @@ wasm-bindgen-test.workspace = true
[features]
update-schema = ["dep:toml"]
test-utils = [
"dep:futures",
"xmtp_common/test-utils",
"dep:mockall",
"xmtp_configuration/test-utils",
Expand Down
3 changes: 1 addition & 2 deletions xmtp_db/src/encrypted_store/association_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub(crate) mod tests {
}

#[xmtp_common::test]
async fn test_batch_read() {
fn test_batch_read() {
with_connection(|conn| {
let mock = AssociationStateProto {
inbox_id: "test_id1".into(),
Expand Down Expand Up @@ -223,6 +223,5 @@ pub(crate) mod tests {
.collect::<Vec<MockState>>();
assert_eq!(no_results.len(), 0);
})
.await
}
}
6 changes: 2 additions & 4 deletions xmtp_db/src/encrypted_store/consent_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ mod tests {
}

#[xmtp_common::test(unwrap_try = true)]
async fn find_consent_by_dm_id() {
fn find_consent_by_dm_id() {
with_connection(|conn| {
let mut g = generate_group(None);
g.dm_id = Some("dm:alpha:beta".to_string());
Expand All @@ -446,11 +446,10 @@ mod tests {
assert_eq!(records.len(), 1);
assert_eq!(records.pop()?, cr);
})
.await;
}

#[xmtp_common::test]
async fn insert_and_read() {
fn insert_and_read() {
with_connection(|conn| {
let inbox_id = "inbox_1";
let consent_record = generate_consent_record(
Expand Down Expand Up @@ -511,6 +510,5 @@ mod tests {
// ensure the db matches the state of what was returned
assert_eq!(db_cr.state, existing.state);
})
.await
}
}
27 changes: 9 additions & 18 deletions xmtp_db/src/encrypted_store/conversation_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub(crate) mod tests {
use crate::test_utils::with_connection;

#[xmtp_common::test]
async fn test_single_group_multiple_messages() {
fn test_single_group_multiple_messages() {
with_connection(|conn| {
// Create a group
let group = generate_group(None);
Expand Down Expand Up @@ -294,11 +294,10 @@ pub(crate) mod tests {
"Last message should be the most recent one"
);
})
.await
}

#[xmtp_common::test]
async fn test_three_groups_specific_ordering() {
fn test_three_groups_specific_ordering() {
with_connection(|conn| {
// Create three groups
let group_a = generate_group_with_created_at(None, 5000); // Created after last message
Expand Down Expand Up @@ -338,11 +337,10 @@ pub(crate) mod tests {
"Group created before the last message with no messages should come last"
);
})
.await
}

#[xmtp_common::test]
async fn test_group_with_newer_message_update() {
fn test_group_with_newer_message_update() {
with_connection(|conn| {
// Create a group
let group = generate_group(None);
Expand Down Expand Up @@ -391,11 +389,10 @@ pub(crate) mod tests {
"Last message should now match the second (newest) message"
);
})
.await
}

#[xmtp_common::test]
async fn test_find_conversations_by_consent_state() {
fn test_find_conversations_by_consent_state() {
with_connection(|conn| {
let test_group_1 = generate_group(Some(GroupMembershipState::Allowed));
test_group_1.store(conn).unwrap();
Expand Down Expand Up @@ -484,11 +481,10 @@ pub(crate) mod tests {
.unwrap();
assert_eq!(empty_array_results.len(), 3);
})
.await
}

#[xmtp_common::test]
async fn test_find_conversations_default_excludes_denied() {
fn test_find_conversations_default_excludes_denied() {
with_connection(|conn| {
// Create three groups: one allowed, one denied, one unknown (no consent)
let allowed_group = generate_group(Some(GroupMembershipState::Allowed));
Expand Down Expand Up @@ -527,11 +523,10 @@ pub(crate) mod tests {
assert!(returned_ids.contains(&&unknown_group.id));
assert!(!returned_ids.contains(&&denied_group.id));
})
.await
}

#[xmtp_common::test(unwrap_try = true)]
async fn test_unknown_content_type_is_present() {
fn test_unknown_content_type_is_present() {
with_connection(|conn| {
let dm = generate_dm(None);
dm.store(conn)?;
Expand All @@ -553,11 +548,10 @@ pub(crate) mod tests {
// Message id should be present
assert!(conv[0].message_id.is_some());
})
.await;
}

#[xmtp_common::test]
async fn test_last_activity_after_ns_filter() {
fn test_last_activity_after_ns_filter() {
with_connection(|conn| {
// Create groups with specific creation times
let group1 = generate_group_with_created_at(None, 1000);
Expand Down Expand Up @@ -638,11 +632,10 @@ pub(crate) mod tests {
.unwrap();
assert_eq!(results.len(), 3, "Should return all groups");
})
.await
}

#[xmtp_common::test]
async fn test_last_activity_before_ns_filter() {
fn test_last_activity_before_ns_filter() {
with_connection(|conn| {
// Create groups with specific creation times
let group1 = generate_group_with_created_at(None, 1000);
Expand Down Expand Up @@ -723,11 +716,10 @@ pub(crate) mod tests {
.unwrap();
assert_eq!(results.len(), 3, "Should return all groups");
})
.await
}

#[xmtp_common::test]
async fn test_activity_filters_combined_with_limit() {
fn test_activity_filters_combined_with_limit() {
with_connection(|conn| {
// Create multiple groups with different activity times
let mut groups = Vec::new();
Expand Down Expand Up @@ -772,6 +764,5 @@ pub(crate) mod tests {
"Second should be second most recent"
);
})
.await
}
}
3 changes: 1 addition & 2 deletions xmtp_db/src/encrypted_store/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod tests {

#[xmtp_common::test(unwrap_try = true)]
// A client build event should clear old events.
async fn clear_old_events() {
fn clear_old_events() {
with_connection(|conn| {
let details: HashMap<String, String> = HashMap::default();
Events {
Expand Down Expand Up @@ -234,6 +234,5 @@ mod tests {
let all = Events::all_events(conn)?;
assert_eq!(all.len(), 0);
})
.await;
}
}
33 changes: 11 additions & 22 deletions xmtp_db/src/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ pub(crate) mod tests {
}

#[xmtp_common::test]
async fn test_it_stores_group() {
fn test_it_stores_group() {
with_connection(|conn| {
let test_group = generate_group(None);

Expand All @@ -1420,11 +1420,10 @@ pub(crate) mod tests {
test_group
);
})
.await
}

#[xmtp_common::test]
async fn test_it_fetches_group() {
fn test_it_fetches_group() {
with_connection(|conn| {
let test_group = generate_group(None);

Expand All @@ -1438,11 +1437,10 @@ pub(crate) mod tests {
let fetched_group: Option<StoredGroup> = conn.fetch(&test_group.id).unwrap();
assert_eq!(fetched_group, Some(test_group));
})
.await
}

#[xmtp_common::test]
async fn test_it_updates_group_membership_state() {
fn test_it_updates_group_membership_state() {
with_connection(|conn| {
let test_group = generate_group(Some(GroupMembershipState::Pending));

Expand All @@ -1459,7 +1457,6 @@ pub(crate) mod tests {
}
);
})
.await
}

#[xmtp_common::test]
Expand Down Expand Up @@ -1584,7 +1581,7 @@ pub(crate) mod tests {
}

#[xmtp_common::test]
async fn test_new_group_has_correct_purpose() {
fn test_new_group_has_correct_purpose() {
with_connection(|conn| {
let test_group = generate_group(None);

Expand All @@ -1600,11 +1597,10 @@ pub(crate) mod tests {
let conversation_type = fetched_group.unwrap().conversation_type;
assert_eq!(conversation_type, ConversationType::Group);
})
.await
}

#[xmtp_common::test]
async fn test_find_groups_by_consent_state() {
fn test_find_groups_by_consent_state() {
with_connection(|conn| {
let test_group_1 = generate_group(Some(GroupMembershipState::Allowed));
test_group_1.store(conn).unwrap();
Expand Down Expand Up @@ -1691,11 +1687,10 @@ pub(crate) mod tests {
.unwrap();
assert_eq!(empty_array_results.len(), 3);
})
.await
}

#[xmtp_common::test]
async fn test_get_sequence_ids() {
fn test_get_sequence_ids() {
with_connection(|conn| {
let mls_groups = [
generate_group_with_welcome(None, Some(30)),
Expand All @@ -1715,11 +1710,10 @@ pub(crate) mod tests {
.collect::<Vec<u64>>()
);
})
.await
}

#[xmtp_common::test]
async fn test_find_group_default_excludes_denied() {
fn test_find_group_default_excludes_denied() {
with_connection(|conn| {
// Create three groups: one allowed, one denied, one unknown (no consent)
let allowed_group = generate_group(Some(GroupMembershipState::Allowed));
Expand Down Expand Up @@ -1756,11 +1750,10 @@ pub(crate) mod tests {
assert!(returned_ids.contains(&&unknown_group.id));
assert!(!returned_ids.contains(&&denied_group.id));
})
.await
}

#[xmtp_common::test(unwrap_try = true)]
async fn test_get_conversation_ids_for_remote_log_publish() {
fn test_get_conversation_ids_for_remote_log_publish() {
with_connection(|conn| {
let mut group1 = generate_group(None);
let mut group2 = generate_group(None);
Expand Down Expand Up @@ -1801,11 +1794,10 @@ pub(crate) mod tests {
group3.commit_log_public_key
);
})
.await
}

#[xmtp_common::test]
async fn test_get_conversation_ids_for_remote_log_publish_with_consent() {
fn test_get_conversation_ids_for_remote_log_publish_with_consent() {
with_connection(|conn| {
// Create groups: one with Allowed consent, one with Denied consent, one with no consent
let mut allowed_group = generate_group(None);
Expand Down Expand Up @@ -1840,11 +1832,10 @@ pub(crate) mod tests {
assert_eq!(commit_log_keys.len(), 1);
assert_eq!(commit_log_keys[0].id, allowed_group.id);
})
.await
}

#[xmtp_common::test]
async fn test_get_conversation_ids_for_remote_log_download_with_consent() {
fn test_get_conversation_ids_for_remote_log_download_with_consent() {
with_connection(|conn| {
// Create groups: one with Allowed consent, one with Denied consent, one with no consent
let allowed_group = generate_group(None);
Expand Down Expand Up @@ -1887,11 +1878,10 @@ pub(crate) mod tests {
assert_eq!(conversation_ids.len(), 1);
assert_eq!(conversation_ids[0].id, allowed_group.id);
})
.await
}

#[xmtp_common::test]
async fn test_get_conversation_ids_for_responding_readds() {
fn test_get_conversation_ids_for_responding_readds() {
with_connection(|conn| {
// Create test groups
let group_id_1 = vec![1, 2, 3];
Expand Down Expand Up @@ -1995,6 +1985,5 @@ pub(crate) mod tests {
assert_eq!(group3_result.conversation_type, ConversationType::Group);
assert_eq!(group3_result.created_at_ns, 3000);
})
.await
}
}
6 changes: 2 additions & 4 deletions xmtp_db/src/encrypted_store/group/dms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub(super) mod tests {
}

#[xmtp_common::test]
async fn test_dm_stitching() {
fn test_dm_stitching() {
with_connection(|conn| {
StoredGroup::builder()
.id(rand_vec::<24>())
Expand All @@ -153,11 +153,10 @@ pub(super) mod tests {

assert_eq!(all_groups.len(), 1);
})
.await
}

#[xmtp_common::test]
async fn test_dm_deduplication() {
fn test_dm_deduplication() {
with_connection(|conn| {
let now = now_ns();
let base_time = now - 1_000_000_000; // 1 second ago
Expand Down Expand Up @@ -269,6 +268,5 @@ pub(super) mod tests {
// Should have all 5 groups
assert_eq!(all_groups.len(), 5);
})
.await
}
}
Loading
Loading