From 48b2e7682713e88debad66ca3124d224788ed2c2 Mon Sep 17 00:00:00 2001 From: Daniel Cadenas Date: Sat, 24 Aug 2024 10:02:13 -0300 Subject: [PATCH] Add failing test case for list syncronization --- src/follows_differ.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/follows_differ.rs b/src/follows_differ.rs index 956c8f6..d9fe9da 100644 --- a/src/follows_differ.rs +++ b/src/follows_differ.rs @@ -525,6 +525,46 @@ mod tests { .await; } + #[tokio::test] + async fn test_final_state_with_older_list_ignored() { + let followee1_pubkey = Keys::generate().public_key(); + let followee2_pubkey = Keys::generate().public_key(); + let followee3_pubkey = Keys::generate().public_key(); + let follower_keys = Keys::generate(); + let follower_pubkey = follower_keys.public_key(); + + // Monday's list: follower follows followee1 + let monday_list = create_contact_event(&follower_keys, vec![followee1_pubkey], 1000000000); + + // Wednesday's update: follower follows followee1 and followee3 + let wednesday_update = create_contact_event( + &follower_keys, + vec![followee1_pubkey, followee3_pubkey], + 1000000020, + ); + + // Tuesday's list arrives late: follower follows followee1 and followee2 + let tuesday_list = create_contact_event( + &follower_keys, + vec![followee1_pubkey, followee2_pubkey], + 1000000010, + ); + + // Apply Monday's list, then Wednesday's update, and finally the late Tuesday list + assert_follow_changes( + vec![monday_list, wednesday_update, tuesday_list], + vec![ + // Monday: followee1 is followed + FollowChange::new_followed(1000000000.into(), follower_pubkey, followee1_pubkey), + // Wednesday: followee3 is followed (with followee1 still followed) + FollowChange::new_followed(1000000020.into(), follower_pubkey, followee3_pubkey), + // Tuesday's late update should now add followee2 without overwriting newer data + FollowChange::new_followed(1000000010.into(), follower_pubkey, followee2_pubkey), + ], + ) + .await; + } + async fn assert_follow_changes(contact_events: Vec, mut expected: Vec) { let follow_changes = get_follow_changes_from_contact_events(contact_events) .await