mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 02:51:01 +00:00
Nomination Pools: Rename state-toggler to bouncer (#13421)
* rename state-toggler to bouncer * add migration * fmt * bump storage version * rm migration * revert version * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: command-bot <>
This commit is contained in:
@@ -518,7 +518,7 @@ frame_benchmarking::benchmarks! {
|
|||||||
depositor: depositor.clone(),
|
depositor: depositor.clone(),
|
||||||
root: Some(depositor.clone()),
|
root: Some(depositor.clone()),
|
||||||
nominator: Some(depositor.clone()),
|
nominator: Some(depositor.clone()),
|
||||||
state_toggler: Some(depositor.clone()),
|
bouncer: Some(depositor.clone()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -557,7 +557,7 @@ frame_benchmarking::benchmarks! {
|
|||||||
depositor: depositor.clone(),
|
depositor: depositor.clone(),
|
||||||
root: Some(depositor.clone()),
|
root: Some(depositor.clone()),
|
||||||
nominator: Some(depositor.clone()),
|
nominator: Some(depositor.clone()),
|
||||||
state_toggler: Some(depositor.clone()),
|
bouncer: Some(depositor.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -630,7 +630,7 @@ frame_benchmarking::benchmarks! {
|
|||||||
pallet_nomination_pools::PoolRoles {
|
pallet_nomination_pools::PoolRoles {
|
||||||
depositor: root,
|
depositor: root,
|
||||||
nominator: Some(random.clone()),
|
nominator: Some(random.clone()),
|
||||||
state_toggler: Some(random.clone()),
|
bouncer: Some(random.clone()),
|
||||||
root: Some(random),
|
root: Some(random),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -143,9 +143,9 @@ fn random_call<R: Rng>(mut rng: &mut R) -> (pools::Call<T>, RuntimeOrigin) {
|
|||||||
let amount = random_ed_multiple(&mut rng);
|
let amount = random_ed_multiple(&mut rng);
|
||||||
fund_account(&mut rng, &who);
|
fund_account(&mut rng, &who);
|
||||||
let root = who;
|
let root = who;
|
||||||
let state_toggler = who;
|
let bouncer = who;
|
||||||
let nominator = who;
|
let nominator = who;
|
||||||
(PoolsCall::<T>::create { amount, root, state_toggler, nominator }, origin)
|
(PoolsCall::<T>::create { amount, root, bouncer, nominator }, origin)
|
||||||
},
|
},
|
||||||
7 => {
|
7 => {
|
||||||
// nominate
|
// nominate
|
||||||
|
|||||||
@@ -120,9 +120,9 @@
|
|||||||
//! * Depositor: creates the pool and is the initial member. They can only leave the pool once all
|
//! * Depositor: creates the pool and is the initial member. They can only leave the pool once all
|
||||||
//! other members have left. Once they fully withdraw their funds, the pool is destroyed.
|
//! other members have left. Once they fully withdraw their funds, the pool is destroyed.
|
||||||
//! * Nominator: can select which validators the pool nominates.
|
//! * Nominator: can select which validators the pool nominates.
|
||||||
//! * State-Toggler: can change the pools state and kick members if the pool is blocked.
|
//! * Bouncer: can change the pools state and kick members if the pool is blocked.
|
||||||
//! * Root: can change the nominator, state-toggler, or itself and can perform any of the actions
|
//! * Root: can change the nominator, bouncer, or itself and can perform any of the actions the
|
||||||
//! the nominator or state-toggler can.
|
//! nominator or bouncer can.
|
||||||
//!
|
//!
|
||||||
//! ### Dismantling
|
//! ### Dismantling
|
||||||
//!
|
//!
|
||||||
@@ -573,13 +573,13 @@ pub struct PoolRoles<AccountId> {
|
|||||||
/// Creates the pool and is the initial member. They can only leave the pool once all other
|
/// Creates the pool and is the initial member. They can only leave the pool once all other
|
||||||
/// members have left. Once they fully leave, the pool is destroyed.
|
/// members have left. Once they fully leave, the pool is destroyed.
|
||||||
pub depositor: AccountId,
|
pub depositor: AccountId,
|
||||||
/// Can change the nominator, state-toggler, or itself and can perform any of the actions the
|
/// Can change the nominator, bouncer, or itself and can perform any of the actions the
|
||||||
/// nominator or state-toggler can.
|
/// nominator or bouncer can.
|
||||||
pub root: Option<AccountId>,
|
pub root: Option<AccountId>,
|
||||||
/// Can select which validators the pool nominates.
|
/// Can select which validators the pool nominates.
|
||||||
pub nominator: Option<AccountId>,
|
pub nominator: Option<AccountId>,
|
||||||
/// Can change the pools state and kick members if the pool is blocked.
|
/// Can change the pools state and kick members if the pool is blocked.
|
||||||
pub state_toggler: Option<AccountId>,
|
pub bouncer: Option<AccountId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pool permissions and state
|
/// Pool permissions and state
|
||||||
@@ -734,11 +734,8 @@ impl<T: Config> BondedPool<T> {
|
|||||||
self.roles.root.as_ref().map_or(false, |root| root == who)
|
self.roles.root.as_ref().map_or(false, |root| root == who)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_state_toggler(&self, who: &T::AccountId) -> bool {
|
fn is_bouncer(&self, who: &T::AccountId) -> bool {
|
||||||
self.roles
|
self.roles.bouncer.as_ref().map_or(false, |bouncer| bouncer == who)
|
||||||
.state_toggler
|
|
||||||
.as_ref()
|
|
||||||
.map_or(false, |state_toggler| state_toggler == who)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_update_roles(&self, who: &T::AccountId) -> bool {
|
fn can_update_roles(&self, who: &T::AccountId) -> bool {
|
||||||
@@ -751,15 +748,15 @@ impl<T: Config> BondedPool<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn can_kick(&self, who: &T::AccountId) -> bool {
|
fn can_kick(&self, who: &T::AccountId) -> bool {
|
||||||
self.state == PoolState::Blocked && (self.is_root(who) || self.is_state_toggler(who))
|
self.state == PoolState::Blocked && (self.is_root(who) || self.is_bouncer(who))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_toggle_state(&self, who: &T::AccountId) -> bool {
|
fn can_toggle_state(&self, who: &T::AccountId) -> bool {
|
||||||
(self.is_root(who) || self.is_state_toggler(who)) && !self.is_destroying()
|
(self.is_root(who) || self.is_bouncer(who)) && !self.is_destroying()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_set_metadata(&self, who: &T::AccountId) -> bool {
|
fn can_set_metadata(&self, who: &T::AccountId) -> bool {
|
||||||
self.is_root(who) || self.is_state_toggler(who)
|
self.is_root(who) || self.is_bouncer(who)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_destroying(&self) -> bool {
|
fn is_destroying(&self) -> bool {
|
||||||
@@ -1407,7 +1404,7 @@ pub mod pallet {
|
|||||||
/// can never change.
|
/// can never change.
|
||||||
RolesUpdated {
|
RolesUpdated {
|
||||||
root: Option<T::AccountId>,
|
root: Option<T::AccountId>,
|
||||||
state_toggler: Option<T::AccountId>,
|
bouncer: Option<T::AccountId>,
|
||||||
nominator: Option<T::AccountId>,
|
nominator: Option<T::AccountId>,
|
||||||
},
|
},
|
||||||
/// The active balance of pool `pool_id` has been slashed to `balance`.
|
/// The active balance of pool `pool_id` has been slashed to `balance`.
|
||||||
@@ -1630,8 +1627,8 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// # Conditions for a permissionless dispatch.
|
/// # Conditions for a permissionless dispatch.
|
||||||
///
|
///
|
||||||
/// * The pool is blocked and the caller is either the root or state-toggler. This is
|
/// * The pool is blocked and the caller is either the root or bouncer. This is refereed to
|
||||||
/// refereed to as a kick.
|
/// as a kick.
|
||||||
/// * The pool is destroying and the member is not the depositor.
|
/// * The pool is destroying and the member is not the depositor.
|
||||||
/// * The pool is destroying, the member is the depositor and no other members are in the
|
/// * The pool is destroying, the member is the depositor and no other members are in the
|
||||||
/// pool.
|
/// pool.
|
||||||
@@ -1754,7 +1751,7 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// * The pool is in destroy mode and the target is not the depositor.
|
/// * The pool is in destroy mode and the target is not the depositor.
|
||||||
/// * The target is the depositor and they are the only member in the sub pools.
|
/// * The target is the depositor and they are the only member in the sub pools.
|
||||||
/// * The pool is blocked and the caller is either the root or state-toggler.
|
/// * The pool is blocked and the caller is either the root or bouncer.
|
||||||
///
|
///
|
||||||
/// # Conditions for permissioned dispatch
|
/// # Conditions for permissioned dispatch
|
||||||
///
|
///
|
||||||
@@ -1879,7 +1876,7 @@ pub mod pallet {
|
|||||||
/// creating multiple pools in the same extrinsic.
|
/// creating multiple pools in the same extrinsic.
|
||||||
/// * `root` - The account to set as [`PoolRoles::root`].
|
/// * `root` - The account to set as [`PoolRoles::root`].
|
||||||
/// * `nominator` - The account to set as the [`PoolRoles::nominator`].
|
/// * `nominator` - The account to set as the [`PoolRoles::nominator`].
|
||||||
/// * `state_toggler` - The account to set as the [`PoolRoles::state_toggler`].
|
/// * `bouncer` - The account to set as the [`PoolRoles::bouncer`].
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
@@ -1892,7 +1889,7 @@ pub mod pallet {
|
|||||||
#[pallet::compact] amount: BalanceOf<T>,
|
#[pallet::compact] amount: BalanceOf<T>,
|
||||||
root: AccountIdLookupOf<T>,
|
root: AccountIdLookupOf<T>,
|
||||||
nominator: AccountIdLookupOf<T>,
|
nominator: AccountIdLookupOf<T>,
|
||||||
state_toggler: AccountIdLookupOf<T>,
|
bouncer: AccountIdLookupOf<T>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let depositor = ensure_signed(origin)?;
|
let depositor = ensure_signed(origin)?;
|
||||||
|
|
||||||
@@ -1901,7 +1898,7 @@ pub mod pallet {
|
|||||||
Ok(*id)
|
Ok(*id)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Self::do_create(depositor, amount, root, nominator, state_toggler, pool_id)
|
Self::do_create(depositor, amount, root, nominator, bouncer, pool_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new delegation pool with a previously used pool id
|
/// Create a new delegation pool with a previously used pool id
|
||||||
@@ -1917,7 +1914,7 @@ pub mod pallet {
|
|||||||
#[pallet::compact] amount: BalanceOf<T>,
|
#[pallet::compact] amount: BalanceOf<T>,
|
||||||
root: AccountIdLookupOf<T>,
|
root: AccountIdLookupOf<T>,
|
||||||
nominator: AccountIdLookupOf<T>,
|
nominator: AccountIdLookupOf<T>,
|
||||||
state_toggler: AccountIdLookupOf<T>,
|
bouncer: AccountIdLookupOf<T>,
|
||||||
pool_id: PoolId,
|
pool_id: PoolId,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let depositor = ensure_signed(origin)?;
|
let depositor = ensure_signed(origin)?;
|
||||||
@@ -1925,7 +1922,7 @@ pub mod pallet {
|
|||||||
ensure!(!BondedPools::<T>::contains_key(pool_id), Error::<T>::PoolIdInUse);
|
ensure!(!BondedPools::<T>::contains_key(pool_id), Error::<T>::PoolIdInUse);
|
||||||
ensure!(pool_id < LastPoolId::<T>::get(), Error::<T>::InvalidPoolId);
|
ensure!(pool_id < LastPoolId::<T>::get(), Error::<T>::InvalidPoolId);
|
||||||
|
|
||||||
Self::do_create(depositor, amount, root, nominator, state_toggler, pool_id)
|
Self::do_create(depositor, amount, root, nominator, bouncer, pool_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Nominate on behalf of the pool.
|
/// Nominate on behalf of the pool.
|
||||||
@@ -1955,7 +1952,7 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// The dispatch origin of this call must be either:
|
/// The dispatch origin of this call must be either:
|
||||||
///
|
///
|
||||||
/// 1. signed by the state toggler, or the root role of the pool,
|
/// 1. signed by the bouncer, or the root role of the pool,
|
||||||
/// 2. if the pool conditions to be open are NOT met (as described by `ok_to_be_open`), and
|
/// 2. if the pool conditions to be open are NOT met (as described by `ok_to_be_open`), and
|
||||||
/// then the state of the pool can be permissionlessly changed to `Destroying`.
|
/// then the state of the pool can be permissionlessly changed to `Destroying`.
|
||||||
#[pallet::call_index(9)]
|
#[pallet::call_index(9)]
|
||||||
@@ -1985,7 +1982,7 @@ pub mod pallet {
|
|||||||
|
|
||||||
/// Set a new metadata for the pool.
|
/// Set a new metadata for the pool.
|
||||||
///
|
///
|
||||||
/// The dispatch origin of this call must be signed by the state toggler, or the root role
|
/// The dispatch origin of this call must be signed by the bouncer, or the root role
|
||||||
/// of the pool.
|
/// of the pool.
|
||||||
#[pallet::call_index(10)]
|
#[pallet::call_index(10)]
|
||||||
#[pallet::weight(T::WeightInfo::set_metadata(metadata.len() as u32))]
|
#[pallet::weight(T::WeightInfo::set_metadata(metadata.len() as u32))]
|
||||||
@@ -2063,7 +2060,7 @@ pub mod pallet {
|
|||||||
pool_id: PoolId,
|
pool_id: PoolId,
|
||||||
new_root: ConfigOp<T::AccountId>,
|
new_root: ConfigOp<T::AccountId>,
|
||||||
new_nominator: ConfigOp<T::AccountId>,
|
new_nominator: ConfigOp<T::AccountId>,
|
||||||
new_state_toggler: ConfigOp<T::AccountId>,
|
new_bouncer: ConfigOp<T::AccountId>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let mut bonded_pool = match ensure_root(origin.clone()) {
|
let mut bonded_pool = match ensure_root(origin.clone()) {
|
||||||
Ok(()) => BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?,
|
Ok(()) => BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?,
|
||||||
@@ -2086,16 +2083,16 @@ pub mod pallet {
|
|||||||
ConfigOp::Remove => bonded_pool.roles.nominator = None,
|
ConfigOp::Remove => bonded_pool.roles.nominator = None,
|
||||||
ConfigOp::Set(v) => bonded_pool.roles.nominator = Some(v),
|
ConfigOp::Set(v) => bonded_pool.roles.nominator = Some(v),
|
||||||
};
|
};
|
||||||
match new_state_toggler {
|
match new_bouncer {
|
||||||
ConfigOp::Noop => (),
|
ConfigOp::Noop => (),
|
||||||
ConfigOp::Remove => bonded_pool.roles.state_toggler = None,
|
ConfigOp::Remove => bonded_pool.roles.bouncer = None,
|
||||||
ConfigOp::Set(v) => bonded_pool.roles.state_toggler = Some(v),
|
ConfigOp::Set(v) => bonded_pool.roles.bouncer = Some(v),
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::deposit_event(Event::<T>::RolesUpdated {
|
Self::deposit_event(Event::<T>::RolesUpdated {
|
||||||
root: bonded_pool.roles.root.clone(),
|
root: bonded_pool.roles.root.clone(),
|
||||||
nominator: bonded_pool.roles.nominator.clone(),
|
nominator: bonded_pool.roles.nominator.clone(),
|
||||||
state_toggler: bonded_pool.roles.state_toggler.clone(),
|
bouncer: bonded_pool.roles.bouncer.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
bonded_pool.put();
|
bonded_pool.put();
|
||||||
@@ -2336,12 +2333,12 @@ impl<T: Config> Pallet<T> {
|
|||||||
amount: BalanceOf<T>,
|
amount: BalanceOf<T>,
|
||||||
root: AccountIdLookupOf<T>,
|
root: AccountIdLookupOf<T>,
|
||||||
nominator: AccountIdLookupOf<T>,
|
nominator: AccountIdLookupOf<T>,
|
||||||
state_toggler: AccountIdLookupOf<T>,
|
bouncer: AccountIdLookupOf<T>,
|
||||||
pool_id: PoolId,
|
pool_id: PoolId,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let root = T::Lookup::lookup(root)?;
|
let root = T::Lookup::lookup(root)?;
|
||||||
let nominator = T::Lookup::lookup(nominator)?;
|
let nominator = T::Lookup::lookup(nominator)?;
|
||||||
let state_toggler = T::Lookup::lookup(state_toggler)?;
|
let bouncer = T::Lookup::lookup(bouncer)?;
|
||||||
|
|
||||||
ensure!(amount >= Pallet::<T>::depositor_min_bond(), Error::<T>::MinimumBondNotMet);
|
ensure!(amount >= Pallet::<T>::depositor_min_bond(), Error::<T>::MinimumBondNotMet);
|
||||||
ensure!(
|
ensure!(
|
||||||
@@ -2354,7 +2351,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
PoolRoles {
|
PoolRoles {
|
||||||
root: Some(root),
|
root: Some(root),
|
||||||
nominator: Some(nominator),
|
nominator: Some(nominator),
|
||||||
state_toggler: Some(state_toggler),
|
bouncer: Some(bouncer),
|
||||||
depositor: who.clone(),
|
depositor: who.clone(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub mod v1 {
|
|||||||
pub depositor: AccountId,
|
pub depositor: AccountId,
|
||||||
pub root: AccountId,
|
pub root: AccountId,
|
||||||
pub nominator: AccountId,
|
pub nominator: AccountId,
|
||||||
pub state_toggler: AccountId,
|
pub bouncer: AccountId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<AccountId> OldPoolRoles<AccountId> {
|
impl<AccountId> OldPoolRoles<AccountId> {
|
||||||
@@ -37,7 +37,7 @@ pub mod v1 {
|
|||||||
depositor: self.depositor,
|
depositor: self.depositor,
|
||||||
root: Some(self.root),
|
root: Some(self.root),
|
||||||
nominator: Some(self.nominator),
|
nominator: Some(self.nominator),
|
||||||
state_toggler: Some(self.state_toggler),
|
bouncer: Some(self.bouncer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ macro_rules! member_unbonding_eras {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const DEFAULT_ROLES: PoolRoles<AccountId> =
|
pub const DEFAULT_ROLES: PoolRoles<AccountId> =
|
||||||
PoolRoles { depositor: 10, root: Some(900), nominator: Some(901), state_toggler: Some(902) };
|
PoolRoles { depositor: 10, root: Some(900), nominator: Some(901), bouncer: Some(902) };
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_setup_works() {
|
fn test_setup_works() {
|
||||||
@@ -2148,7 +2148,7 @@ mod unbond {
|
|||||||
.add_members(vec![(20, 20)])
|
.add_members(vec![(20, 20)])
|
||||||
.build_and_execute(|| {
|
.build_and_execute(|| {
|
||||||
unsafe_set_state(1, PoolState::Blocked);
|
unsafe_set_state(1, PoolState::Blocked);
|
||||||
let kicker = DEFAULT_ROLES.state_toggler.unwrap();
|
let kicker = DEFAULT_ROLES.bouncer.unwrap();
|
||||||
|
|
||||||
// cannot be kicked to above the limit.
|
// cannot be kicked to above the limit.
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
@@ -2251,7 +2251,7 @@ mod unbond {
|
|||||||
|
|
||||||
// set the stage
|
// set the stage
|
||||||
unsafe_set_state(1, PoolState::Blocked);
|
unsafe_set_state(1, PoolState::Blocked);
|
||||||
let kicker = DEFAULT_ROLES.state_toggler.unwrap();
|
let kicker = DEFAULT_ROLES.bouncer.unwrap();
|
||||||
|
|
||||||
// cannot be kicked to above limit.
|
// cannot be kicked to above limit.
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
@@ -2590,7 +2590,7 @@ mod unbond {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unbond_kick_works() {
|
fn unbond_kick_works() {
|
||||||
// Kick: the pool is blocked and the caller is either the root or state-toggler.
|
// Kick: the pool is blocked and the caller is either the root or bouncer.
|
||||||
ExtBuilder::default()
|
ExtBuilder::default()
|
||||||
.add_members(vec![(100, 100), (200, 200)])
|
.add_members(vec![(100, 100), (200, 200)])
|
||||||
.build_and_execute(|| {
|
.build_and_execute(|| {
|
||||||
@@ -2599,7 +2599,7 @@ mod unbond {
|
|||||||
let bonded_pool = BondedPool::<Runtime>::get(1).unwrap();
|
let bonded_pool = BondedPool::<Runtime>::get(1).unwrap();
|
||||||
assert_eq!(bonded_pool.roles.root.unwrap(), 900);
|
assert_eq!(bonded_pool.roles.root.unwrap(), 900);
|
||||||
assert_eq!(bonded_pool.roles.nominator.unwrap(), 901);
|
assert_eq!(bonded_pool.roles.nominator.unwrap(), 901);
|
||||||
assert_eq!(bonded_pool.roles.state_toggler.unwrap(), 902);
|
assert_eq!(bonded_pool.roles.bouncer.unwrap(), 902);
|
||||||
|
|
||||||
// When the nominator tries to kick, then its a noop
|
// When the nominator tries to kick, then its a noop
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
@@ -2627,7 +2627,7 @@ mod unbond {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// When the state toggler kicks then its ok
|
// When the bouncer kicks then its ok
|
||||||
assert_ok!(Pools::fully_unbond(RuntimeOrigin::signed(902), 200));
|
assert_ok!(Pools::fully_unbond(RuntimeOrigin::signed(902), 200));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -3558,7 +3558,7 @@ mod withdraw_unbonded {
|
|||||||
// Can kick as root
|
// Can kick as root
|
||||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(900), 100, 0));
|
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(900), 100, 0));
|
||||||
|
|
||||||
// Can kick as state toggler
|
// Can kick as bouncer
|
||||||
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(900), 200, 0));
|
assert_ok!(Pools::withdraw_unbonded(RuntimeOrigin::signed(900), 200, 0));
|
||||||
|
|
||||||
assert_eq!(Balances::free_balance(100), 100 + 100);
|
assert_eq!(Balances::free_balance(100), 100 + 100);
|
||||||
@@ -4148,7 +4148,7 @@ mod create {
|
|||||||
depositor: 11,
|
depositor: 11,
|
||||||
root: Some(123),
|
root: Some(123),
|
||||||
nominator: Some(456),
|
nominator: Some(456),
|
||||||
state_toggler: Some(789)
|
bouncer: Some(789)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4232,7 +4232,7 @@ mod create {
|
|||||||
amount: 20,
|
amount: 20,
|
||||||
root: 11,
|
root: 11,
|
||||||
nominator: 11,
|
nominator: 11,
|
||||||
state_toggler: 11,
|
bouncer: 11,
|
||||||
});
|
});
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
create.dispatch(RuntimeOrigin::signed(11)),
|
create.dispatch(RuntimeOrigin::signed(11)),
|
||||||
@@ -4292,7 +4292,7 @@ mod nominate {
|
|||||||
Error::<Runtime>::NotNominator
|
Error::<Runtime>::NotNominator
|
||||||
);
|
);
|
||||||
|
|
||||||
// State toggler can't nominate
|
// bouncer can't nominate
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pools::nominate(RuntimeOrigin::signed(902), 1, vec![21]),
|
Pools::nominate(RuntimeOrigin::signed(902), 1, vec![21]),
|
||||||
Error::<Runtime>::NotNominator
|
Error::<Runtime>::NotNominator
|
||||||
@@ -4324,7 +4324,7 @@ mod set_state {
|
|||||||
// Given
|
// Given
|
||||||
assert_ok!(BondedPool::<Runtime>::get(1).unwrap().ok_to_be_open());
|
assert_ok!(BondedPool::<Runtime>::get(1).unwrap().ok_to_be_open());
|
||||||
|
|
||||||
// Only the root and state toggler can change the state when the pool is ok to be open.
|
// Only the root and bouncer can change the state when the pool is ok to be open.
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pools::set_state(RuntimeOrigin::signed(10), 1, PoolState::Blocked),
|
Pools::set_state(RuntimeOrigin::signed(10), 1, PoolState::Blocked),
|
||||||
Error::<Runtime>::CanNotChangeState
|
Error::<Runtime>::CanNotChangeState
|
||||||
@@ -4348,7 +4348,7 @@ mod set_state {
|
|||||||
|
|
||||||
assert_eq!(BondedPool::<Runtime>::get(1).unwrap().state, PoolState::Blocked);
|
assert_eq!(BondedPool::<Runtime>::get(1).unwrap().state, PoolState::Blocked);
|
||||||
|
|
||||||
// State toggler can change state
|
// bouncer can change state
|
||||||
assert_ok!(Pools::set_state(RuntimeOrigin::signed(902), 1, PoolState::Destroying));
|
assert_ok!(Pools::set_state(RuntimeOrigin::signed(902), 1, PoolState::Destroying));
|
||||||
assert_eq!(BondedPool::<Runtime>::get(1).unwrap().state, PoolState::Destroying);
|
assert_eq!(BondedPool::<Runtime>::get(1).unwrap().state, PoolState::Destroying);
|
||||||
|
|
||||||
@@ -4412,7 +4412,7 @@ mod set_metadata {
|
|||||||
assert_ok!(Pools::set_metadata(RuntimeOrigin::signed(900), 1, vec![1, 1]));
|
assert_ok!(Pools::set_metadata(RuntimeOrigin::signed(900), 1, vec![1, 1]));
|
||||||
assert_eq!(Metadata::<Runtime>::get(1), vec![1, 1]);
|
assert_eq!(Metadata::<Runtime>::get(1), vec![1, 1]);
|
||||||
|
|
||||||
// State toggler can set metadata
|
// bouncer can set metadata
|
||||||
assert_ok!(Pools::set_metadata(RuntimeOrigin::signed(902), 1, vec![2, 2]));
|
assert_ok!(Pools::set_metadata(RuntimeOrigin::signed(902), 1, vec![2, 2]));
|
||||||
assert_eq!(Metadata::<Runtime>::get(1), vec![2, 2]);
|
assert_eq!(Metadata::<Runtime>::get(1), vec![2, 2]);
|
||||||
|
|
||||||
@@ -4637,7 +4637,7 @@ mod update_roles {
|
|||||||
depositor: 10,
|
depositor: 10,
|
||||||
root: Some(900),
|
root: Some(900),
|
||||||
nominator: Some(901),
|
nominator: Some(901),
|
||||||
state_toggler: Some(902)
|
bouncer: Some(902)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -4676,7 +4676,7 @@ mod update_roles {
|
|||||||
),
|
),
|
||||||
Error::<Runtime>::DoesNotHavePermission,
|
Error::<Runtime>::DoesNotHavePermission,
|
||||||
);
|
);
|
||||||
// state-toggler
|
// bouncer
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pools::update_roles(
|
Pools::update_roles(
|
||||||
RuntimeOrigin::signed(902),
|
RuntimeOrigin::signed(902),
|
||||||
@@ -4702,21 +4702,12 @@ mod update_roles {
|
|||||||
vec![
|
vec![
|
||||||
Event::Created { depositor: 10, pool_id: 1 },
|
Event::Created { depositor: 10, pool_id: 1 },
|
||||||
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
|
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
|
||||||
Event::RolesUpdated {
|
Event::RolesUpdated { root: Some(5), bouncer: Some(7), nominator: Some(6) }
|
||||||
root: Some(5),
|
|
||||||
state_toggler: Some(7),
|
|
||||||
nominator: Some(6)
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||||
PoolRoles {
|
PoolRoles { depositor: 10, root: Some(5), nominator: Some(6), bouncer: Some(7) },
|
||||||
depositor: 10,
|
|
||||||
root: Some(5),
|
|
||||||
nominator: Some(6),
|
|
||||||
state_toggler: Some(7)
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// also root origin can
|
// also root origin can
|
||||||
@@ -4730,20 +4721,11 @@ mod update_roles {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pool_events_since_last_call(),
|
pool_events_since_last_call(),
|
||||||
vec![Event::RolesUpdated {
|
vec![Event::RolesUpdated { root: Some(1), bouncer: Some(3), nominator: Some(2) }]
|
||||||
root: Some(1),
|
|
||||||
state_toggler: Some(3),
|
|
||||||
nominator: Some(2)
|
|
||||||
}]
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||||
PoolRoles {
|
PoolRoles { depositor: 10, root: Some(1), nominator: Some(2), bouncer: Some(3) },
|
||||||
depositor: 10,
|
|
||||||
root: Some(1),
|
|
||||||
nominator: Some(2),
|
|
||||||
state_toggler: Some(3)
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Noop works
|
// Noop works
|
||||||
@@ -4757,21 +4739,12 @@ mod update_roles {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pool_events_since_last_call(),
|
pool_events_since_last_call(),
|
||||||
vec![Event::RolesUpdated {
|
vec![Event::RolesUpdated { root: Some(11), bouncer: Some(3), nominator: Some(2) }]
|
||||||
root: Some(11),
|
|
||||||
state_toggler: Some(3),
|
|
||||||
nominator: Some(2)
|
|
||||||
}]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||||
PoolRoles {
|
PoolRoles { depositor: 10, root: Some(11), nominator: Some(2), bouncer: Some(3) },
|
||||||
depositor: 10,
|
|
||||||
root: Some(11),
|
|
||||||
nominator: Some(2),
|
|
||||||
state_toggler: Some(3)
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove works
|
// Remove works
|
||||||
@@ -4785,12 +4758,12 @@ mod update_roles {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pool_events_since_last_call(),
|
pool_events_since_last_call(),
|
||||||
vec![Event::RolesUpdated { root: Some(69), state_toggler: None, nominator: None }]
|
vec![Event::RolesUpdated { root: Some(69), bouncer: None, nominator: None }]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BondedPools::<Runtime>::get(1).unwrap().roles,
|
BondedPools::<Runtime>::get(1).unwrap().roles,
|
||||||
PoolRoles { depositor: 10, root: Some(69), nominator: None, state_toggler: None },
|
PoolRoles { depositor: 10, root: Some(69), nominator: None, bouncer: None },
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user