mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 01:11:08 +00:00
Abstracts elections-phragmen pallet to use NposSolver (#12588)
* Abstracts elections-phragmen pallet to use NposSolver * Update frame/elections-phragmen/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/elections-phragmen/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * changes the name of the pallet; adds changelog * update changelog * Adds weight testing * Adds log macro_rules * renames elections-phragment dir to elections * weights rename * fixes typo in cargo toml * pre/post solve weight scafolding * refactor do_post_election * refactors into pre and post election solve for independent benchmarking * deconstructs PreElectionResults struct * updates benchmarking pre and post election solve; mock weights * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * addresses PR comments * adds pre_solve and post_sove weights * Adds comments on election pallet id param name change * ".git/.scripts/bench-bot.sh" pallet dev pallet_elections * Finishes pre-post solve weights * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Addresses PR comments: no panic in on_init path; nits * Fixes node build * Implements approval voting to use as a `NposSolver` (#13367) * Implements the approval voting methods in sp_npos_elections * fmt * remove unecessary file * comment clarification * re-run weights * fix typo * updates MaxVoters in tests for integrity_tests to pass * Refactors election provider support benchmarks outside its own crate (#13431) * Refactors election provider support benchmarks outside its own crate --------- Co-authored-by: command-bot <> --------- Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: parity-processbot <> Co-authored-by: Ross Bulat <ross@parity.io>
This commit is contained in:
@@ -18,12 +18,57 @@
|
||||
//! Tests for npos-elections.
|
||||
|
||||
use crate::{
|
||||
balancing, helpers::*, mock::*, seq_phragmen, seq_phragmen_core, setup_inputs, to_support_map,
|
||||
Assignment, BalancingConfig, ElectionResult, ExtendedBalance, StakedAssignment, Support, Voter,
|
||||
approval_voting::*, balancing, helpers::*, mock::*, seq_phragmen, seq_phragmen_core,
|
||||
setup_inputs, to_support_map, Assignment, BalancingConfig, ElectionResult, ExtendedBalance,
|
||||
StakedAssignment, Support, Voter,
|
||||
};
|
||||
use sp_arithmetic::{PerU16, Perbill, Percent, Permill};
|
||||
use substrate_test_utils::assert_eq_uvec;
|
||||
|
||||
#[test]
|
||||
fn approval_voting_works() {
|
||||
let candidates = vec![1, 2, 3, 4];
|
||||
let voters = vec![(10, vec![1, 2]), (20, vec![1, 2]), (30, vec![1, 2, 3]), (40, vec![4])];
|
||||
let stake_of = create_stake_of(&[(10, 10), (20, 20), (30, 30), (40, 40)]);
|
||||
|
||||
let voters = voters
|
||||
.iter()
|
||||
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let ElectionResult::<_, Perbill> { winners, assignments } =
|
||||
approval_voting(3, candidates, voters).unwrap();
|
||||
|
||||
assert_eq_uvec!(winners, vec![(1, 60), (2, 60), (4, 40)]);
|
||||
assert_eq_uvec!(
|
||||
assignments,
|
||||
vec![
|
||||
Assignment {
|
||||
who: 10u64,
|
||||
distribution: vec![
|
||||
(1, Perbill::from_percent(100)),
|
||||
(2, Perbill::from_percent(100))
|
||||
]
|
||||
},
|
||||
Assignment {
|
||||
who: 20u64,
|
||||
distribution: vec![
|
||||
(1, Perbill::from_percent(100)),
|
||||
(2, Perbill::from_percent(100))
|
||||
]
|
||||
},
|
||||
Assignment {
|
||||
who: 30u64,
|
||||
distribution: vec![
|
||||
(1, Perbill::from_percent(100)),
|
||||
(2, Perbill::from_percent(100))
|
||||
]
|
||||
},
|
||||
Assignment { who: 40u64, distribution: vec![(4, Perbill::from_percent(100))] },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_phragmen_poc_works() {
|
||||
let candidates = vec![1, 2, 3];
|
||||
|
||||
Reference in New Issue
Block a user