Skip to content

Commit

Permalink
all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Oct 23, 2024
1 parent 3035e1f commit 81ebe55
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
},
UniqueMonotonicIdentifier,
};
use cf_traits::mocks::time_source::Mock;
use frame_support::{CloneNoBound, DebugNoBound, EqNoBound, PartialEqNoBound};

pub mod access;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cf_primitives::AuthorityCount;

use super::{mocks::*, register_checks};
use crate::{
electoral_system::{ConsensusStatus, ElectoralReadAccess},
electoral_system::ConsensusStatus,
electoral_systems::{tests::utils::generate_votes, unsafe_median::*},
};

Expand All @@ -19,66 +19,65 @@ fn with_default_context() -> TestContext<SimpleUnsafeMedian> {
with_default_setup().build_with_initial_election()
}

// TODO: Remove second arg from macro
// register_checks! {
// SimpleUnsafeMedian {
// started_at_initial_state(_post, _a) {
// assert_eq!(
// MockAccess::<SimpleUnsafeMedian>::unsynchronised_state().unwrap(),
// INIT_UNSYNCHRONISED_STATE,
// "Expected initial state pre-finalization."
// );
// },
// ended_at_initial_state(_pre, _a) {
// assert_eq!(
// MockAccess::<SimpleUnsafeMedian>::unsynchronised_state().unwrap(),
// INIT_UNSYNCHRONISED_STATE,
// "Expected initial state post-finalization."
// );
// },
// ended_at_new_state(_pre, _a) {
// assert_eq!(
// MockAccess::<SimpleUnsafeMedian>::unsynchronised_state().unwrap(),
// NEW_UNSYNCHRONISED_STATE,
// "Expected new state post-finalization."
// );
// },
// }
// }
register_checks! {
SimpleUnsafeMedian {
started_at_initial_state(pre_finalize, _a) {
assert_eq!(
pre_finalize.unsynchronised_state,
INIT_UNSYNCHRONISED_STATE,
"Expected initial state pre-finalization."
);
},
ended_at_initial_state(_pre, post_finalize) {
assert_eq!(
post_finalize.unsynchronised_state,
INIT_UNSYNCHRONISED_STATE,
"Expected initial state post-finalization."
);
},
ended_at_new_state(_pre, post_finalize) {
assert_eq!(
post_finalize.unsynchronised_state,
NEW_UNSYNCHRONISED_STATE,
"Expected new state post-finalization."
);
},
}
}

// #[test]
// fn if_consensus_update_unsynchronised_state() {
// with_default_context()
// .force_consensus_update(ConsensusStatus::Gained {
// most_recent: None,
// new: NEW_UNSYNCHRONISED_STATE,
// })
// .test_on_finalize(
// &(),
// |_| {},
// vec![
// Check::started_at_initial_state(),
// Check::ended_at_new_state(),
// Check::last_election_deleted(),
// Check::election_id_incremented(),
// ],
// );
// }
#[test]
fn if_consensus_update_unsynchronised_state() {
with_default_context()
.force_consensus_update(ConsensusStatus::Gained {
most_recent: None,
new: NEW_UNSYNCHRONISED_STATE,
})
.test_on_finalize(
&(),
|_| {},
vec![
Check::started_at_initial_state(),
Check::ended_at_new_state(),
Check::last_election_deleted(),
Check::election_id_incremented(),
],
);
}

// #[test]
// fn if_no_consensus_do_not_update_unsynchronised_state() {
// with_default_context()
// .force_consensus_update(ConsensusStatus::None)
// .test_on_finalize(
// &(),
// |_| {},
// vec![
// Check::started_at_initial_state(),
// Check::ended_at_initial_state(),
// Check::assert_unchanged(),
// ],
// );
// }
#[test]
fn if_no_consensus_do_not_update_unsynchronised_state() {
with_default_context()
.force_consensus_update(ConsensusStatus::None)
.test_on_finalize(
&(),
|_| {},
vec![
Check::started_at_initial_state(),
Check::ended_at_initial_state(),
Check::assert_unchanged(),
],
);
}

#[test]
fn check_consensus_correctly_calculates_median_when_all_authorities_vote() {
Expand Down

0 comments on commit 81ebe55

Please sign in to comment.