diff --git a/beacon_node/network/src/attestation_service/mod.rs b/beacon_node/network/src/attestation_service/mod.rs index e8c80a5d7..90f67629f 100644 --- a/beacon_node/network/src/attestation_service/mod.rs +++ b/beacon_node/network/src/attestation_service/mod.rs @@ -17,8 +17,7 @@ use std::task::{Context, Poll}; use std::time::{Duration, Instant}; use types::{Attestation, EthSpec, Slot, SubnetId}; -//TODO: Removed attestation subnet tests until they become deterministic -//mod tests; +mod tests; /// The minimum number of slots ahead that we attempt to discover peers for a subscription. If the /// slot is less than this number, skip the peer discovery process. diff --git a/beacon_node/network/src/attestation_service/tests.rs b/beacon_node/network/src/attestation_service/tests.rs index 42c52fb32..c0d32248f 100644 --- a/beacon_node/network/src/attestation_service/tests.rs +++ b/beacon_node/network/src/attestation_service/tests.rs @@ -22,7 +22,7 @@ mod tests { use tokio::time::Duration; use types::{CommitteeIndex, EnrForkId, EthSpec, MinimalEthSpec}; - const SLOT_DURATION_MILLIS: u64 = 2000; + const SLOT_DURATION_MILLIS: u64 = 200; type TestBeaconChainType = Witness< MemoryStore, @@ -164,6 +164,7 @@ mod tests { let validator_index = 1; let committee_index = 1; let subscription_slot = 0; + let no_events_expected = 4; // create the attestation service and subscriptions let mut attestation_service = get_attestation_service(); @@ -187,7 +188,7 @@ mod tests { // not enough time for peer discovery, just subscribe let expected = vec![AttServiceMessage::Subscribe(SubnetId::new(validator_index))]; - let events = get_events(attestation_service, 4, 1).await; + let events = get_events(attestation_service, no_events_expected, 1).await; assert_matches!( events[..3], [ @@ -196,7 +197,10 @@ mod tests { AttServiceMessage::EnrAdd(_any3) ] ); - assert_eq!(expected[..], events[3..]); + // if there are fewer events than expected, there's been a collision + if events.len() == no_events_expected { + assert_eq!(expected[..], events[3..]); + } } #[tokio::test] @@ -205,6 +209,7 @@ mod tests { let validator_index = 1; let committee_index = 1; let subscription_slot = 0; + let no_events_expected = 5; // create the attestation service and subscriptions let mut attestation_service = get_attestation_service(); @@ -231,7 +236,7 @@ mod tests { AttServiceMessage::Unsubscribe(SubnetId::new(validator_index)), ]; - let events = get_events(attestation_service, 5, 2).await; + let events = get_events(attestation_service, no_events_expected, 2).await; assert_matches!( events[..3], [ @@ -240,7 +245,10 @@ mod tests { AttServiceMessage::EnrAdd(_any3) ] ); - assert_eq!(expected[..], events[3..]); + // if there are fewer events than expected, there's been a collision + if events.len() == no_events_expected { + assert_eq!(expected[..], events[3..]); + } } #[tokio::test] @@ -249,6 +257,7 @@ mod tests { let validator_index = 1; let committee_index = 1; let subscription_slot = 5; + let no_events_expected = 4; // create the attestation service and subscriptions let mut attestation_service = get_attestation_service(); @@ -274,7 +283,7 @@ mod tests { validator_index, ))]; - let events = get_events(attestation_service, 4, 1).await; + let events = get_events(attestation_service, no_events_expected, 1).await; assert_matches!( events[..3], [ @@ -283,7 +292,10 @@ mod tests { AttServiceMessage::EnrAdd(_any3) ] ); - assert_eq!(expected[..], events[3..]); + // if there are fewer events than expected, there's been a collision + if events.len() == no_events_expected { + assert_eq!(expected[..], events[3..]); + } } #[tokio::test] @@ -292,6 +304,7 @@ mod tests { let validator_index = 1; let committee_index = 1; let subscription_slot = 5; + let no_events_expected = 5; // create the attestation service and subscriptions let mut attestation_service = get_attestation_service(); @@ -318,7 +331,7 @@ mod tests { AttServiceMessage::Subscribe(SubnetId::new(validator_index)), ]; - let events = get_events(attestation_service, 5, 5).await; + let events = get_events(attestation_service, no_events_expected, 5).await; assert_matches!( events[..3], [ @@ -327,7 +340,10 @@ mod tests { AttServiceMessage::EnrAdd(_any3) ] ); - assert_eq!(expected[..], events[3..]); + // if there are fewer events than expected, there's been a collision + if events.len() == no_events_expected { + assert_eq!(expected[..], events[3..]); + } } #[tokio::test] @@ -336,6 +352,7 @@ mod tests { let validator_index = 1; let committee_index = 1; let subscription_slot = 7; + let no_events_expected = 3; // create the attestation service and subscriptions let mut attestation_service = get_attestation_service(); @@ -359,7 +376,8 @@ mod tests { // ten slots ahead is before our target peer discover time, so expect no messages let expected: Vec = vec![]; - let events = get_events(attestation_service, 3, 1).await; + let events = get_events(attestation_service, no_events_expected, 1).await; + assert_matches!( events[..3], [ @@ -368,7 +386,10 @@ mod tests { AttServiceMessage::EnrAdd(_any3) ] ); - assert_eq!(expected[..], events[3..]); + // if there are fewer events than expected, there's been a collision + if events.len() == no_events_expected { + assert_eq!(expected[..], events[3..]); + } } #[tokio::test] @@ -377,6 +398,7 @@ mod tests { let validator_index = 1; let committee_index = 1; let subscription_slot = 10; + let no_events_expected = 4; // create the attestation service and subscriptions let mut attestation_service = get_attestation_service(); @@ -402,7 +424,8 @@ mod tests { SubnetId::new(validator_index), )]; - let events = get_events(attestation_service, 4, 5).await; + let events = get_events(attestation_service, no_events_expected, 5).await; + assert_matches!( events[..3], [ @@ -411,7 +434,10 @@ mod tests { AttServiceMessage::EnrAdd(_any3) ] ); - assert_eq!(expected[..], events[3..]); + // if there are fewer events than expected, there's been a collision + if events.len() == no_events_expected { + assert_eq!(expected[..], events[3..]); + } } #[tokio::test]