mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Fix offchain election to respect the weight (#7215)
* Mockup * Fix offchain election to respect the weight * Fix builds a bit * Update frame/staking/src/offchain_election.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/staking/src/offchain_election.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Make it build, binary search * Fix a number of grumbles * one more fix. * remove unwrap. * better alg. * Better alg again. * Final fixes * Fix * Rollback to normal * Final touches. * Better tests. * Update frame/staking/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Proper maxExtWeight * Final fix * Final fix for the find_voter Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -1155,6 +1155,69 @@ mod solution_type {
|
||||
assert_eq!(compact.unique_targets(), vec![10, 11, 20, 40, 50, 51]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_voter_works() {
|
||||
let mut compact = TestSolutionCompact {
|
||||
votes1: vec![(0, 2), (1, 6)],
|
||||
votes2: vec![
|
||||
(2, (0, TestAccuracy::from_percent(80)), 1),
|
||||
(3, (7, TestAccuracy::from_percent(85)), 8),
|
||||
],
|
||||
votes3: vec![
|
||||
(
|
||||
4,
|
||||
[(3, TestAccuracy::from_percent(50)), (4, TestAccuracy::from_percent(25))],
|
||||
5,
|
||||
),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert!(!compact.remove_voter(11));
|
||||
assert!(compact.remove_voter(2));
|
||||
assert_eq!(
|
||||
compact,
|
||||
TestSolutionCompact {
|
||||
votes1: vec![(0, 2), (1, 6)],
|
||||
votes2: vec![
|
||||
(3, (7, TestAccuracy::from_percent(85)), 8),
|
||||
],
|
||||
votes3: vec![
|
||||
(
|
||||
4,
|
||||
[(3, TestAccuracy::from_percent(50)), (4, TestAccuracy::from_percent(25))],
|
||||
5,
|
||||
),
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
assert!(compact.remove_voter(4));
|
||||
assert_eq!(
|
||||
compact,
|
||||
TestSolutionCompact {
|
||||
votes1: vec![(0, 2), (1, 6)],
|
||||
votes2: vec![
|
||||
(3, (7, TestAccuracy::from_percent(85)), 8),
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
assert!(compact.remove_voter(1));
|
||||
assert_eq!(
|
||||
compact,
|
||||
TestSolutionCompact {
|
||||
votes1: vec![(0, 2)],
|
||||
votes2: vec![
|
||||
(3, (7, TestAccuracy::from_percent(85)), 8),
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_from_and_into_compact_works_assignments() {
|
||||
let voters = vec![
|
||||
|
||||
Reference in New Issue
Block a user