Incorporate the new electing/electable naming into the code (#10956)

* Incorporate the new electing/electable naming into the code

* Update frame/election-provider-support/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Update frame/election-provider-support/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Some additional changes

* fmt

* update codec

* revert lock file to master

* fix doc test

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
This commit is contained in:
Kian Paimani
2022-03-19 12:24:41 +00:00
committed by GitHub
parent bbfdd38b69
commit 95192f0cda
9 changed files with 81 additions and 69 deletions
+26 -21
View File
@@ -4055,10 +4055,12 @@ mod election_data_provider {
#[test]
fn voters_include_self_vote() {
ExtBuilder::default().nominate(false).build_and_execute(|| {
assert!(<Validators<Test>>::iter().map(|(x, _)| x).all(|v| Staking::voters(None)
.unwrap()
.into_iter()
.any(|(w, _, t)| { v == w && t[0] == w })))
assert!(<Validators<Test>>::iter().map(|(x, _)| x).all(|v| Staking::electing_voters(
None
)
.unwrap()
.into_iter()
.any(|(w, _, t)| { v == w && t[0] == w })))
})
}
@@ -4067,7 +4069,7 @@ mod election_data_provider {
ExtBuilder::default().build_and_execute(|| {
assert_eq!(Staking::nominators(101).unwrap().targets, vec![11, 21]);
assert_eq!(
<Staking as ElectionDataProvider>::voters(None)
<Staking as ElectionDataProvider>::electing_voters(None)
.unwrap()
.iter()
.find(|x| x.0 == 101)
@@ -4082,7 +4084,7 @@ mod election_data_provider {
// 11 is gone.
start_active_era(2);
assert_eq!(
<Staking as ElectionDataProvider>::voters(None)
<Staking as ElectionDataProvider>::electing_voters(None)
.unwrap()
.iter()
.find(|x| x.0 == 101)
@@ -4094,7 +4096,7 @@ mod election_data_provider {
// resubmit and it is back
assert_ok!(Staking::nominate(Origin::signed(100), vec![11, 21]));
assert_eq!(
<Staking as ElectionDataProvider>::voters(None)
<Staking as ElectionDataProvider>::electing_voters(None)
.unwrap()
.iter()
.find(|x| x.0 == 101)
@@ -4118,20 +4120,23 @@ mod election_data_provider {
);
// if limits is less..
assert_eq!(Staking::voters(Some(1)).unwrap().len(), 1);
assert_eq!(Staking::electing_voters(Some(1)).unwrap().len(), 1);
// if limit is equal..
assert_eq!(Staking::voters(Some(5)).unwrap().len(), 5);
assert_eq!(Staking::electing_voters(Some(5)).unwrap().len(), 5);
// if limit is more.
assert_eq!(Staking::voters(Some(55)).unwrap().len(), 5);
assert_eq!(Staking::electing_voters(Some(55)).unwrap().len(), 5);
// if target limit is more..
assert_eq!(Staking::targets(Some(6)).unwrap().len(), 4);
assert_eq!(Staking::targets(Some(4)).unwrap().len(), 4);
assert_eq!(Staking::electable_targets(Some(6)).unwrap().len(), 4);
assert_eq!(Staking::electable_targets(Some(4)).unwrap().len(), 4);
// if target limit is less, then we return an error.
assert_eq!(Staking::targets(Some(1)).unwrap_err(), "Target snapshot too big");
assert_eq!(
Staking::electable_targets(Some(1)).unwrap_err(),
"Target snapshot too big"
);
});
}
@@ -4165,7 +4170,7 @@ mod election_data_provider {
// we take 4 voters: 2 validators and 2 nominators (so nominators quota = 2)
assert_eq!(
Staking::voters(Some(3))
Staking::electing_voters(Some(3))
.unwrap()
.iter()
.map(|(stash, _, _)| stash)
@@ -4204,7 +4209,7 @@ mod election_data_provider {
// we take 5 voters
assert_eq!(
Staking::voters(Some(5))
Staking::electing_voters(Some(5))
.unwrap()
.iter()
.map(|(stash, _, _)| stash)
@@ -4225,7 +4230,7 @@ mod election_data_provider {
// we take 4 voters
assert_eq!(
Staking::voters(Some(4))
Staking::electing_voters(Some(4))
.unwrap()
.iter()
.map(|(stash, _, _)| stash)
@@ -4666,7 +4671,7 @@ fn change_of_max_nominations() {
vec![(70, 3), (101, 2), (60, 1)]
);
// 3 validators and 3 nominators
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 3);
assert_eq!(Staking::electing_voters(None).unwrap().len(), 3 + 3);
// abrupt change from 16 to 4, everyone should be fine.
MaxNominations::set(4);
@@ -4677,7 +4682,7 @@ fn change_of_max_nominations() {
.collect::<Vec<_>>(),
vec![(70, 3), (101, 2), (60, 1)]
);
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 3);
assert_eq!(Staking::electing_voters(None).unwrap().len(), 3 + 3);
// abrupt change from 4 to 3, everyone should be fine.
MaxNominations::set(3);
@@ -4688,7 +4693,7 @@ fn change_of_max_nominations() {
.collect::<Vec<_>>(),
vec![(70, 3), (101, 2), (60, 1)]
);
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 3);
assert_eq!(Staking::electing_voters(None).unwrap().len(), 3 + 3);
// abrupt change from 3 to 2, this should cause some nominators to be non-decodable, and
// thus non-existent unless if they update.
@@ -4705,7 +4710,7 @@ fn change_of_max_nominations() {
// but its value cannot be decoded and default is returned.
assert!(Nominators::<Test>::get(70).is_none());
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 2);
assert_eq!(Staking::electing_voters(None).unwrap().len(), 3 + 2);
assert!(Nominators::<Test>::contains_key(101));
// abrupt change from 2 to 1, this should cause some nominators to be non-decodable, and
@@ -4722,7 +4727,7 @@ fn change_of_max_nominations() {
assert!(Nominators::<Test>::contains_key(60));
assert!(Nominators::<Test>::get(70).is_none());
assert!(Nominators::<Test>::get(60).is_some());
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 1);
assert_eq!(Staking::electing_voters(None).unwrap().len(), 3 + 1);
// now one of them can revive themselves by re-nominating to a proper value.
assert_ok!(Staking::nominate(Origin::signed(71), vec![1]));