Skip to content

Commit

Permalink
test: fix one test
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Oct 29, 2024
1 parent 685ca04 commit 0cb4bb4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ fn generate_votes(

fn generate_votes_with_different_slots(
correct_voters: AuthorityCount,
correct_value: MonotonicChangeVote<Value, Slot>,
correct_value: Value,
incorrect_voters: AuthorityCount,
incorrect_value: MonotonicChangeVote<Value, Slot>,
) -> ConsensusVotes<SimpleMonotonicChange> {
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 {
Expand Down Expand Up @@ -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 },
),
Expand All @@ -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 },
),
Expand All @@ -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::<SimpleMonotonicChange>::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,
);
Expand Down

0 comments on commit 0cb4bb4

Please sign in to comment.