fix attestation service tests (#1167)
This commit is contained in:
parent
d79e07902e
commit
ea56dcb179
@ -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.
|
||||
|
@ -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<MinimalEthSpec>,
|
||||
@ -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<AttServiceMessage> = 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]
|
||||
|
Loading…
Reference in New Issue
Block a user