mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
pallet-staking: Add extrinsic force_apply_min_commission (#10786)
* pallet-staking: Add extrinsic `force_apply_min_commission` * Add benchmarks * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Bound iteration by max_validator_count * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Only apply to 1 validator * Update doc comments * Uncomment tests * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Accept signed origins * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Remove contains_key check * Add test for try_mutate_exists * Impove try_mutate_exists docs * Delete redundant try_mutate_exists tests; * Delete residual from removed test * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Return an error when the stash does not exist * Update try_mutate_exist doc wording * Update frame/staking/src/pallet/mod.rs * Apply suggestions from code review Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -4711,3 +4711,38 @@ mod sorted_list_provider {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_apply_min_commission_works() {
|
||||
let prefs = |c| ValidatorPrefs { commission: Perbill::from_percent(c), blocked: false };
|
||||
let validators = || Validators::<Test>::iter().collect::<Vec<_>>();
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Staking::validate(Origin::signed(30), prefs(10)));
|
||||
assert_ok!(Staking::validate(Origin::signed(20), prefs(5)));
|
||||
|
||||
// Given
|
||||
assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]);
|
||||
MinCommission::<Test>::set(Perbill::from_percent(5));
|
||||
|
||||
// When applying to a commission greater than min
|
||||
assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 31));
|
||||
// Then the commission is not changed
|
||||
assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]);
|
||||
|
||||
// When applying to a commission that is equal to min
|
||||
assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 21));
|
||||
// Then the commission is not changed
|
||||
assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(0))]);
|
||||
|
||||
// When applying to a commission that is less than the min
|
||||
assert_ok!(Staking::force_apply_min_commission(Origin::signed(1), 11));
|
||||
// Then the commission is bumped to the min
|
||||
assert_eq!(validators(), vec![(31, prefs(10)), (21, prefs(5)), (11, prefs(5))]);
|
||||
|
||||
// When applying commission to a validator that doesn't exist then storage is not altered
|
||||
assert_noop!(
|
||||
Staking::force_apply_min_commission(Origin::signed(1), 420),
|
||||
Error::<Test>::NotStash
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user