Skip to content

Commit

Permalink
Merge pull request #2221 from anoma/tomas/pos-sm-v2
Browse files Browse the repository at this point in the history
PoS SM fixes
  • Loading branch information
brentstone authored Jan 3, 2024
2 parents d649d04 + b97a88b commit 50caebb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 9 additions & 0 deletions proof_of_stake/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ impl OwnedPosParams {
max_proposal_period: gov.max_proposal_period,
}
}

/// A test helper to add the default gov params to PoS params.
#[cfg(any(test, feature = "testing"))]
pub fn with_gov_params(self, gov: &GovernanceParameters) -> PosParams {
PosParams {
owned: self,
max_proposal_period: gov.max_proposal_period,
}
}
}

impl std::ops::Deref for PosParams {
Expand Down
8 changes: 7 additions & 1 deletion proof_of_stake/src/tests/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::ops::Deref;

use assert_matches::assert_matches;
use itertools::Itertools;
use namada_core::ledger::governance::parameters::GovernanceParameters;
use namada_core::ledger::storage::testing::TestWlStorage;
use namada_core::ledger::storage_api::collections::lazy_map::{
Collectable, NestedSubKey, SubKey,
Expand Down Expand Up @@ -110,6 +111,8 @@ struct AbstractPosState {
epoch: Epoch,
/// Parameters
params: PosParams,
/// Governance parameters used to construct `params`
gov_params: GovernanceParameters,
/// Genesis validators
genesis_validators: Vec<GenesisValidator>,
/// Bonds delta values. The outer key for Epoch is pipeline offset from
Expand Down Expand Up @@ -223,6 +226,7 @@ impl StateMachineTest for ConcretePosState {
.collect::<Vec<_>>()
);
let mut s = TestWlStorage::default();
initial_state.gov_params.init_storage(&mut s).unwrap();
crate::test_utils::test_init_genesis(
&mut s,
initial_state.params.owned.clone(),
Expand Down Expand Up @@ -1982,11 +1986,13 @@ impl ReferenceStateMachine for AbstractPosState {
tracing::debug!("\nInitializing abstract state machine");
arb_params_and_genesis_validators(Some(8), 8..10)
.prop_map(|(params, genesis_validators)| {
let params = params.with_default_gov_params();
let gov_params = GovernanceParameters::default();
let params = params.with_gov_params(&gov_params);
let epoch = Epoch::default();
let mut state = Self {
epoch,
params,
gov_params,
genesis_validators: genesis_validators
.into_iter()
// Sorted by stake to fill in the consensus set first
Expand Down
12 changes: 8 additions & 4 deletions proof_of_stake/src/tests/state_machine_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{cmp, mem};
use assert_matches::assert_matches;
use derivative::Derivative;
use itertools::Itertools;
use namada_core::ledger::governance::parameters::GovernanceParameters;
use namada_core::ledger::storage::testing::TestWlStorage;
use namada_core::ledger::storage_api::collections::lazy_map::{
NestedSubKey, SubKey,
Expand Down Expand Up @@ -74,6 +75,8 @@ struct AbstractPosState {
epoch: Epoch,
/// Parameters
params: PosParams,
/// Governance parameters used to construct `params`
gov_params: GovernanceParameters,
/// Genesis validators
#[derivative(Debug = "ignore")]
genesis_validators: Vec<GenesisValidator>,
Expand Down Expand Up @@ -1937,6 +1940,7 @@ impl StateMachineTest for ConcretePosState {
.collect::<Vec<_>>()
);
let mut s = TestWlStorage::default();
initial_state.gov_params.init_storage(&mut s).unwrap();
crate::test_utils::init_genesis_helper(
&mut s,
&initial_state.params,
Expand Down Expand Up @@ -3571,12 +3575,12 @@ impl ReferenceStateMachine for AbstractPosState {
arb_params_and_genesis_validators(Some(8), 8..10)
.prop_map(|(params, genesis_validators)| {
let epoch = Epoch::default();
let gov_params = GovernanceParameters::default();
let params = params.with_gov_params(&gov_params);
let mut state = Self {
epoch,
params: PosParams {
owned: params,
..Default::default()
},
params,
gov_params,
genesis_validators: genesis_validators
.into_iter()
// Sorted by stake to fill in the consensus set first
Expand Down

0 comments on commit 50caebb

Please sign in to comment.