Skip to content

Commit

Permalink
evil: reinclude test_purge_validator_information
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Dec 19, 2023
1 parent 1352ae9 commit 2492a0b
Showing 1 changed file with 120 additions and 3 deletions.
123 changes: 120 additions & 3 deletions proof_of_stake/src/tests/test_validator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp::min;

use namada_core::ledger::storage::testing::TestWlStorage;
use namada_core::ledger::storage::WlStorage;
use namada_core::ledger::storage_api::collections::lazy_map;
use namada_core::ledger::storage_api::token::credit_tokens;
use namada_core::types::address::testing::arb_established_address;
Expand All @@ -26,11 +27,12 @@ use crate::storage::{
read_below_capacity_validator_set_addresses_with_stake,
read_below_threshold_validator_set_addresses,
read_consensus_validator_set_addresses_with_stake, update_validator_deltas,
validator_consensus_key_handle, write_validator_address_raw_hash,
validator_addresses_handle, validator_consensus_key_handle,
validator_set_positions_handle, write_validator_address_raw_hash,
};
use crate::test_utils::test_init_genesis;
use crate::test_utils::{init_genesis_helper, test_init_genesis};
use crate::tests::helpers::{
advance_epoch, arb_params_and_genesis_validators,
advance_epoch, arb_genesis_validators, arb_params_and_genesis_validators,
get_tendermint_set_updates,
};
use crate::types::{
Expand Down Expand Up @@ -1189,3 +1191,118 @@ fn test_validator_sets_swap() {
})
);
}

proptest! {
// Generate arb valid input for `test_purge_validator_information_aux`
#![proptest_config(Config {
cases: 1,
.. Config::default()
})]
#[test]
fn test_purge_validator_information(

genesis_validators in arb_genesis_validators(4..5, None),

) {
test_purge_validator_information_aux( genesis_validators)
}
}

/// Test validator initialization.
fn test_purge_validator_information_aux(validators: Vec<GenesisValidator>) {
let owned = OwnedPosParams {
unbonding_len: 4,
..Default::default()
};

let mut s = TestWlStorage::default();
let mut current_epoch = s.storage.block.epoch;

// Genesis
let gov_params =
namada_core::ledger::governance::parameters::GovernanceParameters {
max_proposal_period: 5,
..Default::default()
};

gov_params.init_storage(&mut s).unwrap();
let params = crate::read_non_pos_owned_params(&s, owned).unwrap();
init_genesis_helper(&mut s, &params, validators.into_iter(), current_epoch)
.unwrap();

s.commit_block().unwrap();

let default_past_epochs = 2;
let consensus_val_set_len =
gov_params.max_proposal_period + default_past_epochs;

let consensus_val_set = consensus_validator_set_handle();
// let below_cap_val_set = below_capacity_validator_set_handle();
let validator_positions = validator_set_positions_handle();
let all_validator_addresses = validator_addresses_handle();

let check_is_data = |storage: &WlStorage<_, _>,
start: Epoch,
end: Epoch| {
for ep in Epoch::iter_bounds_inclusive(start, end) {
assert!(!consensus_val_set.at(&ep).is_empty(storage).unwrap());
// assert!(!below_cap_val_set.at(&ep).is_empty(storage).
// unwrap());
assert!(!validator_positions.at(&ep).is_empty(storage).unwrap());
assert!(
!all_validator_addresses.at(&ep).is_empty(storage).unwrap()
);
}
};

// Check that there is validator data for epochs 0 - pipeline_len
check_is_data(&s, current_epoch, Epoch(params.owned.pipeline_len));

// Advance to epoch 1
for _ in 0..default_past_epochs {
current_epoch = advance_epoch(&mut s, &params);
}
assert_eq!(s.storage.block.epoch.0, default_past_epochs);
assert_eq!(current_epoch.0, default_past_epochs);

check_is_data(
&s,
Epoch(0),
Epoch(params.owned.pipeline_len + default_past_epochs),
);

current_epoch = advance_epoch(&mut s, &params);
assert_eq!(current_epoch.0, default_past_epochs + 1);

check_is_data(
&s,
Epoch(1),
Epoch(params.pipeline_len + default_past_epochs + 1),
);
assert!(!consensus_val_set.at(&Epoch(0)).is_empty(&s).unwrap());
assert!(validator_positions.at(&Epoch(0)).is_empty(&s).unwrap());
assert!(all_validator_addresses.at(&Epoch(0)).is_empty(&s).unwrap());

// Advance to the epoch `consensus_val_set_len` + 1
loop {
assert!(!consensus_val_set.at(&Epoch(0)).is_empty(&s).unwrap());

current_epoch = advance_epoch(&mut s, &params);
if current_epoch.0 == consensus_val_set_len + 1 {
break;
}
}

assert!(consensus_val_set.at(&Epoch(0)).is_empty(&s).unwrap());

current_epoch = advance_epoch(&mut s, &params);
for ep in Epoch::default().iter_range(2) {
assert!(consensus_val_set.at(&ep).is_empty(&s).unwrap());
}
for ep in Epoch::iter_bounds_inclusive(
Epoch(2),
current_epoch + params.pipeline_len,
) {
assert!(!consensus_val_set.at(&ep).is_empty(&s).unwrap());
}
}

0 comments on commit 2492a0b

Please sign in to comment.