diff --git a/zebra-network/src/peer_set/candidate_set/tests/vectors.rs b/zebra-network/src/peer_set/candidate_set/tests/vectors.rs index 04e47ce4..bf13da31 100644 --- a/zebra-network/src/peer_set/candidate_set/tests/vectors.rs +++ b/zebra-network/src/peer_set/candidate_set/tests/vectors.rs @@ -53,6 +53,33 @@ fn doesnt_offset_last_seen_times_in_the_past() { assert_eq!(validated_peers, expected_peers); } +/// Test that offset is applied to all the addresses if at least one has a `last_seen` time in the +/// future. +/// +/// Times that are in the past should be changed as well. +#[test] +fn offsets_all_last_seen_times_if_one_is_in_the_future() { + let last_seen_limit = DateTime32::now(); + let last_seen_limit_chrono = last_seen_limit.to_chrono(); + + let input_peers = mock_gossiped_peers(vec![ + last_seen_limit_chrono + Duration::minutes(55), + last_seen_limit_chrono - Duration::days(3), + last_seen_limit_chrono - Duration::hours(2), + ]); + + let validated_peers: Vec<_> = validate_addrs(input_peers, last_seen_limit).collect(); + + let expected_offset = Duration::minutes(55); + let expected_peers = mock_gossiped_peers(vec![ + last_seen_limit_chrono + Duration::minutes(55) - expected_offset, + last_seen_limit_chrono - Duration::days(3) - expected_offset, + last_seen_limit_chrono - Duration::hours(2) - expected_offset, + ]); + + assert_eq!(validated_peers, expected_peers); +} + /// Create a mock list of gossiped [`MetaAddr`]s with the specified `last_seen_times`. /// /// The IP address and port of the generated ports should not matter for the test.