mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 17:05:47 +00:00
[NPoS] Use EraInfo to manipulate exposure in fast-unstake tests (#2459)
The FastUnstake pallet tests were previously directly modifying storage items in the pallet-staking to alter exposure. However, due to the introduction of the [new paged exposure feature](https://github.com/paritytech/polkadot-sdk/pull/1189) these tests were not testing against correct storage items. This issue resulted in a bug that I didn't catch, which has been addressed in [this fix](https://github.com/paritytech/polkadot-sdk/pull/2369). This PR introduces a modification to how the pallet-fast-unstake handles exposure. It now utilizes `pallet-staking::EraInfo` to set or mutate Exposures.
This commit is contained in:
@@ -244,7 +244,7 @@ impl ExtBuilder {
|
||||
(v, Exposure { total: 0, own: 0, others })
|
||||
})
|
||||
.for_each(|(validator, exposure)| {
|
||||
pallet_staking::ErasStakers::<T>::insert(era, validator, exposure);
|
||||
pallet_staking::EraInfo::<T>::set_exposure(era, &validator, exposure);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -342,10 +342,11 @@ pub fn assert_unstaked(stash: &AccountId) {
|
||||
}
|
||||
|
||||
pub fn create_exposed_nominator(exposed: AccountId, era: u32) {
|
||||
// create an exposed nominator in era 1
|
||||
pallet_staking::ErasStakers::<T>::mutate(era, VALIDATORS_PER_ERA, |expo| {
|
||||
expo.others.push(IndividualExposure { who: exposed, value: 0 as Balance });
|
||||
});
|
||||
// create an exposed nominator in passed era
|
||||
let mut exposure = pallet_staking::EraInfo::<T>::get_full_exposure(era, &VALIDATORS_PER_ERA);
|
||||
exposure.others.push(IndividualExposure { who: exposed, value: 0 as Balance });
|
||||
pallet_staking::EraInfo::<T>::set_exposure(era, &VALIDATORS_PER_ERA, exposure);
|
||||
|
||||
Balances::make_free_balance_be(&exposed, 100);
|
||||
assert_ok!(Staking::bond(
|
||||
RuntimeOrigin::signed(exposed),
|
||||
|
||||
@@ -788,10 +788,12 @@ mod on_idle {
|
||||
assert_ok!(FastUnstake::register_fast_unstake(RuntimeOrigin::signed(VALIDATOR_PREFIX)));
|
||||
|
||||
// but they indeed are exposed!
|
||||
assert!(pallet_staking::ErasStakers::<T>::contains_key(
|
||||
assert!(pallet_staking::EraInfo::<T>::get_paged_exposure(
|
||||
BondingDuration::get() - 1,
|
||||
VALIDATOR_PREFIX
|
||||
));
|
||||
&VALIDATOR_PREFIX,
|
||||
0
|
||||
)
|
||||
.is_some());
|
||||
|
||||
// process a block, this validator is exposed and has been slashed.
|
||||
next_block(true);
|
||||
|
||||
Reference in New Issue
Block a user