From 98076d6439102791b27968c9a152edaf698af179 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 24 Oct 2018 15:22:39 +0200 Subject: [PATCH] Add test for utils/active-validators --- .../utils/active-validators/src/lib.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) 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]); + } +}