mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Revise how staking configurations are set (#10955)
* Revise how staking configurations are set fixes #10938 * Fix and add additional tests * Format * Formatting * Add doc Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/staking/src/tests.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Format * Fix build * Update weights.rs * 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 Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
committed by
GitHub
parent
0b3b3e4bfd
commit
b199ccf386
@@ -17,10 +17,10 @@
|
||||
|
||||
//! Tests for the module.
|
||||
|
||||
use super::{Event, MaxUnlockingChunks, *};
|
||||
use super::{ConfigOp, Event, MaxUnlockingChunks, *};
|
||||
use frame_election_provider_support::{ElectionProvider, SortedListProvider, Support};
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, bounded_vec,
|
||||
assert_noop, assert_ok, assert_storage_noop, bounded_vec,
|
||||
dispatch::WithPostDispatchInfo,
|
||||
pallet_prelude::*,
|
||||
traits::{Currency, Get, ReservableCurrency},
|
||||
@@ -40,6 +40,56 @@ use sp_staking::{
|
||||
use sp_std::prelude::*;
|
||||
use substrate_test_utils::assert_eq_uvec;
|
||||
|
||||
#[test]
|
||||
fn set_staking_configs_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// setting works
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
ConfigOp::Set(1_500),
|
||||
ConfigOp::Set(2_000),
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Set(20),
|
||||
ConfigOp::Set(Percent::from_percent(75)),
|
||||
ConfigOp::Set(Zero::zero())
|
||||
));
|
||||
assert_eq!(MinNominatorBond::<Test>::get(), 1_500);
|
||||
assert_eq!(MinValidatorBond::<Test>::get(), 2_000);
|
||||
assert_eq!(MaxNominatorsCount::<Test>::get(), Some(10));
|
||||
assert_eq!(MaxValidatorsCount::<Test>::get(), Some(20));
|
||||
assert_eq!(ChillThreshold::<Test>::get(), Some(Percent::from_percent(75)));
|
||||
assert_eq!(MinCommission::<Test>::get(), Perbill::from_percent(0));
|
||||
|
||||
// noop does nothing
|
||||
assert_storage_noop!(assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop
|
||||
)));
|
||||
|
||||
// removing works
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove
|
||||
));
|
||||
assert_eq!(MinNominatorBond::<Test>::get(), 0);
|
||||
assert_eq!(MinValidatorBond::<Test>::get(), 0);
|
||||
assert_eq!(MaxNominatorsCount::<Test>::get(), None);
|
||||
assert_eq!(MaxValidatorsCount::<Test>::get(), None);
|
||||
assert_eq!(ChillThreshold::<Test>::get(), None);
|
||||
assert_eq!(MinCommission::<Test>::get(), Perbill::from_percent(0));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_unstake_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
@@ -4368,12 +4418,12 @@ fn chill_other_works() {
|
||||
// Change the minimum bond... but no limits.
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
1_500,
|
||||
2_000,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Zero::zero()
|
||||
ConfigOp::Set(1_500),
|
||||
ConfigOp::Set(2_000),
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove
|
||||
));
|
||||
|
||||
// Still can't chill these users
|
||||
@@ -4389,12 +4439,12 @@ fn chill_other_works() {
|
||||
// Add limits, but no threshold
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
1_500,
|
||||
2_000,
|
||||
Some(10),
|
||||
Some(10),
|
||||
None,
|
||||
Zero::zero()
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop
|
||||
));
|
||||
|
||||
// Still can't chill these users
|
||||
@@ -4410,12 +4460,12 @@ fn chill_other_works() {
|
||||
// Add threshold, but no limits
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
1_500,
|
||||
2_000,
|
||||
None,
|
||||
None,
|
||||
Some(Percent::from_percent(0)),
|
||||
Zero::zero()
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop
|
||||
));
|
||||
|
||||
// Still can't chill these users
|
||||
@@ -4431,12 +4481,12 @@ fn chill_other_works() {
|
||||
// Add threshold and limits
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
1_500,
|
||||
2_000,
|
||||
Some(10),
|
||||
Some(10),
|
||||
Some(Percent::from_percent(75)),
|
||||
Zero::zero()
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Set(Percent::from_percent(75)),
|
||||
ConfigOp::Noop
|
||||
));
|
||||
|
||||
// 16 people total because tests start with 2 active one
|
||||
@@ -4476,12 +4526,12 @@ fn capped_stakers_works() {
|
||||
let max = 10;
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
10,
|
||||
10,
|
||||
Some(max),
|
||||
Some(max),
|
||||
Some(Percent::from_percent(0)),
|
||||
Zero::zero(),
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Set(10),
|
||||
ConfigOp::Set(max),
|
||||
ConfigOp::Set(max),
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
));
|
||||
|
||||
// can create `max - validator_count` validators
|
||||
@@ -4546,12 +4596,12 @@ fn capped_stakers_works() {
|
||||
// No problem when we set to `None` again
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
10,
|
||||
10,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Zero::zero(),
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Noop,
|
||||
ConfigOp::Noop,
|
||||
));
|
||||
assert_ok!(Staking::nominate(Origin::signed(last_nominator), vec![1]));
|
||||
assert_ok!(Staking::validate(Origin::signed(last_validator), ValidatorPrefs::default()));
|
||||
@@ -4568,12 +4618,12 @@ fn min_commission_works() {
|
||||
|
||||
assert_ok!(Staking::set_staking_configs(
|
||||
Origin::root(),
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Perbill::from_percent(10),
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Remove,
|
||||
ConfigOp::Set(Perbill::from_percent(10)),
|
||||
));
|
||||
|
||||
// can't make it less than 10 now
|
||||
|
||||
Reference in New Issue
Block a user