mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 01:57:56 +00:00
Use proper bounded vector type for nominations (#10601)
* Use proper bounded vector type for nominations * add docs and tweak chill_other for cleanup purposes * Fix the build * remove TODO * add a bit more doc * even more docs gushc * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <z.mostov@gmail.com> * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <z.mostov@gmail.com> * Fix the nasty bug * also bound the Snapshot type * fix doc test * document bounded_vec * self-review * remove unused * Fix build * frame-support: repetition overload for bounded_vec Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fix * remove the need to allocate into unbounded voters etc etc * Don't expect * unbreal the build again * handle macro a bit better Co-authored-by: Zeke Mostov <z.mostov@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -4248,7 +4248,11 @@ fn count_check_works() {
|
||||
Validators::<Test>::insert(987654321, ValidatorPrefs::default());
|
||||
Nominators::<Test>::insert(
|
||||
987654321,
|
||||
Nominations { targets: vec![], submitted_in: Default::default(), suppressed: false },
|
||||
Nominations {
|
||||
targets: Default::default(),
|
||||
submitted_in: Default::default(),
|
||||
suppressed: false,
|
||||
},
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -4589,6 +4593,100 @@ fn min_commission_works() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn change_of_max_nominations() {
|
||||
use frame_election_provider_support::ElectionDataProvider;
|
||||
ExtBuilder::default()
|
||||
.add_staker(60, 61, 10, StakerStatus::Nominator(vec![1]))
|
||||
.add_staker(70, 71, 10, StakerStatus::Nominator(vec![1, 2, 3]))
|
||||
.balance_factor(10)
|
||||
.build_and_execute(|| {
|
||||
// pre-condition
|
||||
assert_eq!(MaxNominations::get(), 16);
|
||||
|
||||
assert_eq!(
|
||||
Nominators::<Test>::iter()
|
||||
.map(|(k, n)| (k, n.targets.len()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(70, 3), (101, 2), (60, 1)]
|
||||
);
|
||||
// 3 validators and 3 nominators
|
||||
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 3);
|
||||
|
||||
// abrupt change from 16 to 4, everyone should be fine.
|
||||
MaxNominations::set(4);
|
||||
|
||||
assert_eq!(
|
||||
Nominators::<Test>::iter()
|
||||
.map(|(k, n)| (k, n.targets.len()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(70, 3), (101, 2), (60, 1)]
|
||||
);
|
||||
assert_eq!(Staking::voters(None).unwrap().len(), 3 + 3);
|
||||
|
||||
// abrupt change from 4 to 3, everyone should be fine.
|
||||
MaxNominations::set(3);
|
||||
|
||||
assert_eq!(
|
||||
Nominators::<Test>::iter()
|
||||
.map(|(k, n)| (k, n.targets.len()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(70, 3), (101, 2), (60, 1)]
|
||||
);
|
||||
assert_eq!(Staking::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.
|
||||
MaxNominations::set(2);
|
||||
|
||||
assert_eq!(
|
||||
Nominators::<Test>::iter()
|
||||
.map(|(k, n)| (k, n.targets.len()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(101, 2), (60, 1)]
|
||||
);
|
||||
// 70 is still in storage..
|
||||
assert!(Nominators::<Test>::contains_key(70));
|
||||
// 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!(Nominators::<Test>::contains_key(101));
|
||||
|
||||
// abrupt change from 2 to 1, this should cause some nominators to be non-decodable, and
|
||||
// thus non-existent unless if they update.
|
||||
MaxNominations::set(1);
|
||||
|
||||
assert_eq!(
|
||||
Nominators::<Test>::iter()
|
||||
.map(|(k, n)| (k, n.targets.len()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(60, 1)]
|
||||
);
|
||||
assert!(Nominators::<Test>::contains_key(70));
|
||||
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);
|
||||
|
||||
// now one of them can revive themselves by re-nominating to a proper value.
|
||||
assert_ok!(Staking::nominate(Origin::signed(71), vec![1]));
|
||||
assert_eq!(
|
||||
Nominators::<Test>::iter()
|
||||
.map(|(k, n)| (k, n.targets.len()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(70, 1), (60, 1)]
|
||||
);
|
||||
|
||||
// or they can be chilled by any account.
|
||||
assert!(Nominators::<Test>::contains_key(101));
|
||||
assert!(Nominators::<Test>::get(101).is_none());
|
||||
assert_ok!(Staking::chill_other(Origin::signed(70), 100));
|
||||
assert!(!Nominators::<Test>::contains_key(101));
|
||||
assert!(Nominators::<Test>::get(101).is_none());
|
||||
})
|
||||
}
|
||||
|
||||
mod sorted_list_provider {
|
||||
use super::*;
|
||||
use frame_election_provider_support::SortedListProvider;
|
||||
|
||||
Reference in New Issue
Block a user