diff --git a/beacon_chain/utils/active-validators/src/lib.rs b/beacon_chain/utils/active-validators/src/lib.rs index ea7812193..0d79ba0e9 100644 --- a/beacon_chain/utils/active-validators/src/lib.rs +++ b/beacon_chain/utils/active-validators/src/lib.rs @@ -24,3 +24,45 @@ pub fn active_validator_indices(validators: &[ValidatorRecord]) }) .collect() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_active_validator() { + let mut validators = vec![]; + + let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); + v.status = ValidatorStatus::Active as u8; + assert!(validator_is_active(&v)); + validators.push(v); + + let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); + v.status = ValidatorStatus::PendingActivation as u8; + assert!(!validator_is_active(&v)); + validators.push(v); + + let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); + v.status = ValidatorStatus::PendingExit as u8; + assert!(!validator_is_active(&v)); + validators.push(v); + + let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); + v.status = ValidatorStatus::PendingWithdraw as u8; + assert!(!validator_is_active(&v)); + validators.push(v); + + let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); + v.status = ValidatorStatus::Withdrawn as u8; + assert!(!validator_is_active(&v)); + validators.push(v); + + let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); + v.status = ValidatorStatus::Penalized as u8; + assert!(!validator_is_active(&v)); + validators.push(v); + + assert_eq!(active_validator_indices(&validators), vec![0]); + } +}