From c3784ce99ed34e06ed9a4715b232201890d3a9d9 Mon Sep 17 00:00:00 2001 From: BradleyOlson64 Date: Mon, 5 Dec 2022 13:31:56 -0800 Subject: [PATCH 1/4] Refactoring to condense disputes tests --- node/core/dispute-coordinator/src/tests.rs | 636 ++++++++------------- 1 file changed, 238 insertions(+), 398 deletions(-) diff --git a/node/core/dispute-coordinator/src/tests.rs b/node/core/dispute-coordinator/src/tests.rs index 4d32620946e0..af6f03f12dee 100644 --- a/node/core/dispute-coordinator/src/tests.rs +++ b/node/core/dispute-coordinator/src/tests.rs @@ -104,6 +104,37 @@ async fn overseer_recv(virtual_overseer: &mut VirtualOverseer) -> AllMessages { .expect("overseer `recv` timed out") } +/// Helper to condense repeated code that creates vote pairs, one valid and one +/// invalid. Optionally the valid vote of the pair can be made a backing vote. +/// +/// Parameters valid_voter_idx, invalid_voter_idx, candidate_hash, session, +/// test_state, valid_is_backing +/// Returns tuple containing valid then invalid vote +async fn generate_vote_pair( + test_state: &TestState, + valid_voter_idx: ValidatorIndex, + invalid_voter_idx: ValidatorIndex, + candidate_hash: CandidateHash, + session: SessionIndex, + valid_is_backing: bool, +) -> (SignedDisputeStatement, SignedDisputeStatement) { + let valid_vote; + if valid_is_backing { + valid_vote = test_state + .issue_backing_statement_with_index(valid_voter_idx, candidate_hash, session) + .await; + } else { + valid_vote = test_state + .issue_explicit_statement_with_index(valid_voter_idx, candidate_hash, session, true) + .await; + } + let invalid_vote = test_state + .issue_explicit_statement_with_index(invalid_voter_idx, candidate_hash, session, false) + .await; + + (valid_vote, invalid_vote) +} + #[derive(Clone)] struct MockClock { time: Arc, @@ -633,31 +664,25 @@ fn too_many_unconfirmed_statements_are_considered_spam() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let valid_vote1 = test_state - .issue_backing_statement_with_index(ValidatorIndex(3), candidate_hash1, session) - .await; - - let invalid_vote1 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash1, - session, - false, - ) - .await; - - let valid_vote2 = test_state - .issue_backing_statement_with_index(ValidatorIndex(3), candidate_hash2, session) - .await; + let (valid_vote1, invalid_vote1) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash1, + session, + true, + ) + .await; - let invalid_vote2 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash2, - session, - false, - ) - .await; + let (valid_vote2, invalid_vote2) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash2, + session, + true, + ) + .await; gum::trace!("Before sending `ImportStatements`"); virtual_overseer @@ -770,18 +795,15 @@ fn approval_vote_import_works() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let valid_vote1 = test_state - .issue_backing_statement_with_index(ValidatorIndex(3), candidate_hash1, session) - .await; - - let invalid_vote1 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash1, - session, - false, - ) - .await; + let (valid_vote1, invalid_vote1) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash1, + session, + true, + ) + .await; let approval_vote = test_state.issue_approval_vote_with_index( ValidatorIndex(4), @@ -879,41 +901,25 @@ fn dispute_gets_confirmed_via_participation() { ) .await; - let valid_vote1 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(3), - candidate_hash1, - session, - true, - ) - .await; - - let invalid_vote1 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash1, - session, - false, - ) - .await; - - let valid_vote2 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(3), - candidate_hash2, - session, - true, - ) - .await; + let (valid_vote1, invalid_vote1) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash1, + session, + false, + ) + .await; - let invalid_vote2 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash2, - session, - false, - ) - .await; + let (valid_vote2, invalid_vote2) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash2, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -1033,59 +1039,35 @@ fn dispute_gets_confirmed_at_byzantine_threshold() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let valid_vote1 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(3), - candidate_hash1, - session, - true, - ) - .await; - - let invalid_vote1 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash1, - session, - false, - ) - .await; - - let valid_vote1a = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(4), - candidate_hash1, - session, - true, - ) - .await; - - let invalid_vote1a = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(5), - candidate_hash1, - session, - false, - ) - .await; + let (valid_vote1, invalid_vote1) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash1, + session, + false, + ) + .await; - let valid_vote2 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(3), - candidate_hash2, - session, - true, - ) - .await; + let (valid_vote1a, invalid_vote1a) = generate_vote_pair( + &test_state, + ValidatorIndex(4), + ValidatorIndex(5), + candidate_hash1, + session, + false, + ) + .await; - let invalid_vote2 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash2, - session, - false, - ) - .await; + let (valid_vote2, invalid_vote2) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash2, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -1320,23 +1302,15 @@ fn conflicting_votes_lead_to_dispute_participation() { ) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(3), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(3), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; let invalid_vote_2 = test_state .issue_explicit_statement_with_index( @@ -1570,23 +1544,15 @@ fn wrong_validator_index_is_ignored() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(2), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -1655,23 +1621,15 @@ fn finality_votes_ignore_disputed_candidates() { ) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(2), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -1775,23 +1733,15 @@ fn supermajority_valid_dispute_may_be_finalized() { let supermajority_threshold = polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(2), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -1922,23 +1872,15 @@ fn concluded_supermajority_for_non_active_after_time() { let supermajority_threshold = polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(2), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -2047,23 +1989,15 @@ fn concluded_supermajority_against_non_active_after_time() { let supermajority_threshold = polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(2), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; let (pending_confirmation, confirmation_rx) = oneshot::channel(); virtual_overseer @@ -2170,23 +2104,15 @@ fn resume_dispute_without_local_statement() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(1), + ValidatorIndex(2), + candidate_hash, + session, + false, + ) + .await; let (pending_confirmation, confirmation_rx) = oneshot::channel(); virtual_overseer @@ -2245,68 +2171,29 @@ fn resume_dispute_without_local_statement() { ) .await; - let valid_vote0 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(0), - candidate_hash, - session, - true, - ) - .await; - let valid_vote3 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(3), - candidate_hash, - session, - true, - ) - .await; - let valid_vote4 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(4), - candidate_hash, - session, - true, - ) - .await; - let valid_vote5 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(5), - candidate_hash, - session, - true, - ) - .await; - let valid_vote6 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(6), - candidate_hash, - session, - true, - ) - .await; - let valid_vote7 = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(7), - candidate_hash, - session, - true, - ) - .await; + let supermajority_threshold = + polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); + let mut statements = Vec::new(); + // Getting votes for supermajority. Should already have two valid votes. + for i in (0_u32..supermajority_threshold as u32 - 2).map(|i| i + 3) { + let vote = test_state + .issue_explicit_statement_with_index( + ValidatorIndex(i), + candidate_hash, + session, + true, + ) + .await; + + statements.push((vote, ValidatorIndex(i as _))); + } virtual_overseer .send(FromOrchestra::Communication { msg: DisputeCoordinatorMessage::ImportStatements { candidate_receipt: candidate_receipt.clone(), session, - statements: vec![ - (valid_vote0, ValidatorIndex(0)), - (valid_vote3, ValidatorIndex(3)), - (valid_vote4, ValidatorIndex(4)), - (valid_vote5, ValidatorIndex(5)), - (valid_vote6, ValidatorIndex(6)), - (valid_vote7, ValidatorIndex(7)), - ], + statements, pending_confirmation: None, }, }) @@ -2367,23 +2254,15 @@ fn resume_dispute_with_local_statement() { ) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(1), + ValidatorIndex(2), + candidate_hash, + session, + false, + ) + .await; let (pending_confirmation, confirmation_rx) = oneshot::channel(); virtual_overseer @@ -2459,23 +2338,15 @@ fn resume_dispute_without_local_statement_or_local_key() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(1), + ValidatorIndex(2), + candidate_hash, + session, + false, + ) + .await; let (pending_confirmation, confirmation_rx) = oneshot::channel(); virtual_overseer @@ -2563,23 +2434,15 @@ fn resume_dispute_with_local_statement_without_local_key() { ) .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(1), + ValidatorIndex(2), + candidate_hash, + session, + false, + ) + .await; let (pending_confirmation, confirmation_rx) = oneshot::channel(); virtual_overseer @@ -2759,22 +2622,15 @@ fn own_approval_vote_gets_distributed_on_dispute() { .await; // Trigger dispute: - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - false, - ) - .await; - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - true, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(2), + ValidatorIndex(1), + candidate_hash, + session, + false, + ) + .await; let (pending_confirmation, confirmation_rx) = oneshot::channel(); virtual_overseer @@ -3019,23 +2875,15 @@ fn refrain_from_participation() { .await; // generate two votes - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(1), + ValidatorIndex(2), + candidate_hash, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -3119,23 +2967,15 @@ fn participation_for_included_candidates() { .await; // generate two votes - let valid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(1), - candidate_hash, - session, - true, - ) - .await; - - let invalid_vote = test_state - .issue_explicit_statement_with_index( - ValidatorIndex(2), - candidate_hash, - session, - false, - ) - .await; + let (valid_vote, invalid_vote) = generate_vote_pair( + &test_state, + ValidatorIndex(1), + ValidatorIndex(2), + candidate_hash, + session, + false, + ) + .await; virtual_overseer .send(FromOrchestra::Communication { @@ -3192,4 +3032,4 @@ fn participation_for_included_candidates() { test_state }) }); -} +} \ No newline at end of file From fcc09f9f1b2c721e9aaa58e5034bf9cbc5f4479b Mon Sep 17 00:00:00 2001 From: BradleyOlson64 Date: Mon, 5 Dec 2022 13:40:52 -0800 Subject: [PATCH 2/4] Removing unhelpful comment lines --- node/core/dispute-coordinator/src/tests.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/node/core/dispute-coordinator/src/tests.rs b/node/core/dispute-coordinator/src/tests.rs index af6f03f12dee..fd27483cbcdf 100644 --- a/node/core/dispute-coordinator/src/tests.rs +++ b/node/core/dispute-coordinator/src/tests.rs @@ -106,10 +106,6 @@ async fn overseer_recv(virtual_overseer: &mut VirtualOverseer) -> AllMessages { /// Helper to condense repeated code that creates vote pairs, one valid and one /// invalid. Optionally the valid vote of the pair can be made a backing vote. -/// -/// Parameters valid_voter_idx, invalid_voter_idx, candidate_hash, session, -/// test_state, valid_is_backing -/// Returns tuple containing valid then invalid vote async fn generate_vote_pair( test_state: &TestState, valid_voter_idx: ValidatorIndex, From 4128694d061fcad841c6c017f4bc774df2ecfe7d Mon Sep 17 00:00:00 2001 From: BradleyOlson64 Date: Tue, 6 Dec 2022 11:39:01 -0800 Subject: [PATCH 3/4] Addressing Tsveto's suggestions --- node/core/dispute-coordinator/src/tests.rs | 115 +++++++++++---------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/node/core/dispute-coordinator/src/tests.rs b/node/core/dispute-coordinator/src/tests.rs index fd27483cbcdf..0e079455fdd5 100644 --- a/node/core/dispute-coordinator/src/tests.rs +++ b/node/core/dispute-coordinator/src/tests.rs @@ -104,26 +104,29 @@ async fn overseer_recv(virtual_overseer: &mut VirtualOverseer) -> AllMessages { .expect("overseer `recv` timed out") } +enum VoteType { + Backing, + Explicit, +} + /// Helper to condense repeated code that creates vote pairs, one valid and one /// invalid. Optionally the valid vote of the pair can be made a backing vote. -async fn generate_vote_pair( +async fn generate_opposing_votes_pair( test_state: &TestState, valid_voter_idx: ValidatorIndex, invalid_voter_idx: ValidatorIndex, candidate_hash: CandidateHash, session: SessionIndex, - valid_is_backing: bool, + valid_vote_type: VoteType, ) -> (SignedDisputeStatement, SignedDisputeStatement) { - let valid_vote; - if valid_is_backing { - valid_vote = test_state - .issue_backing_statement_with_index(valid_voter_idx, candidate_hash, session) - .await; - } else { - valid_vote = test_state - .issue_explicit_statement_with_index(valid_voter_idx, candidate_hash, session, true) - .await; - } + let valid_vote = match valid_vote_type { + VoteType::Backing => test_state + .issue_backing_statement_with_index(valid_voter_idx, candidate_hash, session) + .await, + VoteType::Explicit => test_state + .issue_explicit_statement_with_index(valid_voter_idx, candidate_hash, session, true) + .await, + }; let invalid_vote = test_state .issue_explicit_statement_with_index(invalid_voter_idx, candidate_hash, session, false) .await; @@ -660,23 +663,23 @@ fn too_many_unconfirmed_statements_are_considered_spam() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let (valid_vote1, invalid_vote1) = generate_vote_pair( + let (valid_vote1, invalid_vote1) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash1, session, - true, + VoteType::Backing, ) .await; - let (valid_vote2, invalid_vote2) = generate_vote_pair( + let (valid_vote2, invalid_vote2) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash2, session, - true, + VoteType::Backing, ) .await; @@ -791,13 +794,13 @@ fn approval_vote_import_works() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let (valid_vote1, invalid_vote1) = generate_vote_pair( + let (valid_vote1, invalid_vote1) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash1, session, - true, + VoteType::Backing, ) .await; @@ -897,23 +900,23 @@ fn dispute_gets_confirmed_via_participation() { ) .await; - let (valid_vote1, invalid_vote1) = generate_vote_pair( + let (valid_vote1, invalid_vote1) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash1, session, - false, + VoteType::Explicit, ) .await; - let (valid_vote2, invalid_vote2) = generate_vote_pair( + let (valid_vote2, invalid_vote2) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash2, session, - false, + VoteType::Explicit, ) .await; @@ -1035,33 +1038,33 @@ fn dispute_gets_confirmed_at_byzantine_threshold() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let (valid_vote1, invalid_vote1) = generate_vote_pair( + let (valid_vote1, invalid_vote1) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash1, session, - false, + VoteType::Explicit, ) .await; - let (valid_vote1a, invalid_vote1a) = generate_vote_pair( + let (valid_vote1a, invalid_vote1a) = generate_opposing_votes_pair( &test_state, ValidatorIndex(4), ValidatorIndex(5), candidate_hash1, session, - false, + VoteType::Explicit, ) .await; - let (valid_vote2, invalid_vote2) = generate_vote_pair( + let (valid_vote2, invalid_vote2) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash2, session, - false, + VoteType::Explicit, ) .await; @@ -1298,13 +1301,13 @@ fn conflicting_votes_lead_to_dispute_participation() { ) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(3), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -1540,13 +1543,13 @@ fn wrong_validator_index_is_ignored() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(2), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -1617,13 +1620,13 @@ fn finality_votes_ignore_disputed_candidates() { ) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(2), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -1729,13 +1732,13 @@ fn supermajority_valid_dispute_may_be_finalized() { let supermajority_threshold = polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(2), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -1868,13 +1871,13 @@ fn concluded_supermajority_for_non_active_after_time() { let supermajority_threshold = polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(2), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -1985,13 +1988,13 @@ fn concluded_supermajority_against_non_active_after_time() { let supermajority_threshold = polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(2), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2100,13 +2103,13 @@ fn resume_dispute_without_local_statement() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(1), ValidatorIndex(2), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2167,11 +2170,9 @@ fn resume_dispute_without_local_statement() { ) .await; - let supermajority_threshold = - polkadot_primitives::v2::supermajority_threshold(test_state.validators.len()); let mut statements = Vec::new(); // Getting votes for supermajority. Should already have two valid votes. - for i in (0_u32..supermajority_threshold as u32 - 2).map(|i| i + 3) { + for i in vec![3, 4, 5, 6, 7] { let vote = test_state .issue_explicit_statement_with_index( ValidatorIndex(i), @@ -2250,13 +2251,13 @@ fn resume_dispute_with_local_statement() { ) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(1), ValidatorIndex(2), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2334,13 +2335,13 @@ fn resume_dispute_without_local_statement_or_local_key() { .activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new()) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(1), ValidatorIndex(2), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2430,13 +2431,13 @@ fn resume_dispute_with_local_statement_without_local_key() { ) .await; - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(1), ValidatorIndex(2), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2618,13 +2619,13 @@ fn own_approval_vote_gets_distributed_on_dispute() { .await; // Trigger dispute: - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(2), ValidatorIndex(1), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2871,13 +2872,13 @@ fn refrain_from_participation() { .await; // generate two votes - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(1), ValidatorIndex(2), candidate_hash, session, - false, + VoteType::Explicit, ) .await; @@ -2963,13 +2964,13 @@ fn participation_for_included_candidates() { .await; // generate two votes - let (valid_vote, invalid_vote) = generate_vote_pair( + let (valid_vote, invalid_vote) = generate_opposing_votes_pair( &test_state, ValidatorIndex(1), ValidatorIndex(2), candidate_hash, session, - false, + VoteType::Explicit, ) .await; From 2ce99246851b1e566703b50ce0ffecb9b60d1d96 Mon Sep 17 00:00:00 2001 From: BradleyOlson64 Date: Wed, 7 Dec 2022 08:29:38 -0800 Subject: [PATCH 4/4] Fixing formatting nit --- node/core/dispute-coordinator/src/tests.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/node/core/dispute-coordinator/src/tests.rs b/node/core/dispute-coordinator/src/tests.rs index 0e079455fdd5..8f1d3482a1e0 100644 --- a/node/core/dispute-coordinator/src/tests.rs +++ b/node/core/dispute-coordinator/src/tests.rs @@ -120,12 +120,14 @@ async fn generate_opposing_votes_pair( valid_vote_type: VoteType, ) -> (SignedDisputeStatement, SignedDisputeStatement) { let valid_vote = match valid_vote_type { - VoteType::Backing => test_state - .issue_backing_statement_with_index(valid_voter_idx, candidate_hash, session) - .await, - VoteType::Explicit => test_state - .issue_explicit_statement_with_index(valid_voter_idx, candidate_hash, session, true) - .await, + VoteType::Backing => + test_state + .issue_backing_statement_with_index(valid_voter_idx, candidate_hash, session) + .await, + VoteType::Explicit => + test_state + .issue_explicit_statement_with_index(valid_voter_idx, candidate_hash, session, true) + .await, }; let invalid_vote = test_state .issue_explicit_statement_with_index(invalid_voter_idx, candidate_hash, session, false) @@ -3029,4 +3031,4 @@ fn participation_for_included_candidates() { test_state }) }); -} \ No newline at end of file +}