From 0cb4bb484b7e9a9425e844edad1821c2b7c72a3e Mon Sep 17 00:00:00 2001 From: kylezs Date: Tue, 29 Oct 2024 16:34:13 +0100 Subject: [PATCH] test: fix one test --- .../src/electoral_systems/mocks.rs | 2 + .../tests/monotonic_change.rs | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/state-chain/pallets/cf-elections/src/electoral_systems/mocks.rs b/state-chain/pallets/cf-elections/src/electoral_systems/mocks.rs index 4f28f85440f..352a67ab4e2 100644 --- a/state-chain/pallets/cf-elections/src/electoral_systems/mocks.rs +++ b/state-chain/pallets/cf-elections/src/electoral_systems/mocks.rs @@ -88,6 +88,8 @@ where let (election_identifier_extra, election_properties, election_state) = self.initial_election_state.unwrap_or_default(); + println!("Creating new elction"); + let election = electoral_access .new_election(election_identifier_extra, election_properties, election_state) .unwrap(); diff --git a/state-chain/pallets/cf-elections/src/electoral_systems/tests/monotonic_change.rs b/state-chain/pallets/cf-elections/src/electoral_systems/tests/monotonic_change.rs index 2a830b472f0..279d10a7195 100644 --- a/state-chain/pallets/cf-elections/src/electoral_systems/tests/monotonic_change.rs +++ b/state-chain/pallets/cf-elections/src/electoral_systems/tests/monotonic_change.rs @@ -76,18 +76,16 @@ fn generate_votes( fn generate_votes_with_different_slots( correct_voters: AuthorityCount, - correct_value: MonotonicChangeVote, + correct_value: Value, incorrect_voters: AuthorityCount, incorrect_value: MonotonicChangeVote, ) -> ConsensusVotes { ConsensusVotes { - votes: (0..correct_voters) + // we start from 1 so don't get a Default::default() conflict on vote validity. + votes: (1..=correct_voters) .enumerate() .map(|(index, _)| ConsensusVote { - vote: Some(( - (), - MonotonicChangeVote { value: correct_value.value, block: index as u32 }, - )), + vote: Some(((), MonotonicChangeVote { value: correct_value, block: index as u32 })), validator_id: (), }) .chain((0..incorrect_voters).map(|_| ConsensusVote { @@ -135,7 +133,7 @@ fn consensus_when_all_votes_the_same_but_different_blocks() { with_default_state().expect_consensus( generate_votes_with_different_slots( SUCCESS_THRESHOLD, - MonotonicChangeVote { value: 1, block: 0 }, + 1, 3, MonotonicChangeVote { value: 0, block: 0 }, ), @@ -144,7 +142,7 @@ fn consensus_when_all_votes_the_same_but_different_blocks() { with_default_state().expect_consensus( generate_votes_with_different_slots( AUTHORITY_COUNT, - MonotonicChangeVote { value: 1, block: 0 }, + 1, 0, MonotonicChangeVote { value: 0, block: 0 }, ), @@ -154,18 +152,26 @@ fn consensus_when_all_votes_the_same_but_different_blocks() { #[test] fn no_consensus_when_votes_are_filtered_because_invalid() { - with_default_state() - .force_consensus_update(crate::electoral_system::ConsensusStatus::Gained { - most_recent: Some((10, 12)), - new: (11, 13), - }) + TestSetup::::default() + .with_initial_election_state((), ((), 1, 1), ()) + .build_with_initial_election() .expect_consensus( generate_votes_with_different_slots( 0, - MonotonicChangeVote { value: 0, block: 0 }, + 0, + AUTHORITY_COUNT, + // block is valid, but value is invalid + MonotonicChangeVote { value: 1, block: 2 }, + ), + None, + ) + .expect_consensus( + generate_votes_with_different_slots( + 0, + 0, AUTHORITY_COUNT, - // neither the value has changed nor the block, both of which fail validity checks - MonotonicChangeVote { value: 11, block: 13 }, + // value is valid but block is invalid + MonotonicChangeVote { value: 2, block: 0 }, ), None, );