Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
karbyshev committed Jul 10, 2023
1 parent c2cfd34 commit 363aa47
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions proof_of_stake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::{
update_validator_set, validator_consensus_key_handle,
validator_set_update_tendermint, validator_slashes_handle,
validator_state_handle, withdraw_tokens, write_validator_address_raw_hash,
BecomeValidator,
BecomeValidator, STORE_VALIDATOR_SETS_LEN,
};

proptest! {
Expand Down Expand Up @@ -1161,8 +1161,7 @@ fn test_validator_sets() {
.unwrap();
};

// Start with two genesis validators with 1 NAM stake
let epoch = Epoch::default();
// Create genesis validators
let ((val1, pk1), stake1) =
(gen_validator(), token::Amount::native_whole(1));
let ((val2, pk2), stake2) =
Expand All @@ -1185,6 +1184,9 @@ fn test_validator_sets() {
println!("val6: {val6}, {pk6}, {}", stake6.to_string_native());
println!("val7: {val7}, {pk7}, {}", stake7.to_string_native());

let start_epoch = Epoch::default();
let epoch = start_epoch;

init_genesis(
&mut s,
&params,
Expand Down Expand Up @@ -1751,6 +1753,28 @@ fn test_validator_sets() {
})
);
assert_eq!(tm_updates[1], ValidatorSetUpdate::Deactivated(pk4));

// Check that the validator sets were purged for the old epochs
let last_epoch = epoch;
for e in Epoch::iter_bounds_inclusive(
start_epoch,
last_epoch
.sub_or_default(Epoch(STORE_VALIDATOR_SETS_LEN))
.sub_or_default(Epoch(1)),
) {
assert!(
consensus_validator_set_handle()
.at(&e)
.is_empty(&s)
.unwrap()
);
assert!(
below_capacity_validator_set_handle()
.at(&e)
.is_empty(&s)
.unwrap()
);
}
}

/// When a consensus set validator with 0 voting power adds a bond in the same
Expand Down

0 comments on commit 363aa47

Please sign in to comment.