Add test for utils/active-validators
This commit is contained in:
parent
b17a15a378
commit
98076d6439
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user