Add test for utils/active-validators

This commit is contained in:
Paul Hauner 2018-10-24 15:22:39 +02:00
parent b17a15a378
commit 98076d6439
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -24,3 +24,45 @@ pub fn active_validator_indices(validators: &[ValidatorRecord])
}) })
.collect() .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]);
}
}