Skip to content

Commit

Permalink
dApp Staking v3 - Unbond During Decommission (#1135)
Browse files Browse the repository at this point in the history
* Allow users to get unbond during decommission

* Expand test
  • Loading branch information
Dinonard authored Jan 17, 2024
1 parent ffe8628 commit 95c25de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 0 additions & 2 deletions pallets/dapps-staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ pub mod pallet {
#[pallet::compact] value: Balance,
) -> DispatchResultWithPostInfo {
Self::ensure_pallet_enabled()?;
Self::ensure_not_in_decommission()?;
let staker = ensure_signed(origin)?;

ensure!(value > Zero::zero(), Error::<T>::UnstakingWithNoValue);
Expand Down Expand Up @@ -630,7 +629,6 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::withdraw_unbonded())]
pub fn withdraw_unbonded(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Self::ensure_pallet_enabled()?;
Self::ensure_not_in_decommission()?;
let staker = ensure_signed(origin)?;

let mut ledger = Self::ledger(&staker);
Expand Down
25 changes: 16 additions & 9 deletions pallets/dapps-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2146,10 +2146,6 @@ fn decommision_is_ok() {
DappsStaking::bond_and_stake(RuntimeOrigin::signed(account), contract_id, 100),
Error::<TestRuntime>::DecommissionInProgress
);
assert_noop!(
DappsStaking::unbond_and_unstake(RuntimeOrigin::signed(account), contract_id, 100),
Error::<TestRuntime>::DecommissionInProgress
);
assert_noop!(
DappsStaking::nomination_transfer(
RuntimeOrigin::signed(account),
Expand All @@ -2159,10 +2155,6 @@ fn decommision_is_ok() {
),
Error::<TestRuntime>::DecommissionInProgress
);
assert_noop!(
DappsStaking::withdraw_unbonded(RuntimeOrigin::signed(account)),
Error::<TestRuntime>::DecommissionInProgress
);

// Ensure that expected calls still work (or at least don't fail with `DecommissionInProgress` error)
assert_noop!(
Expand All @@ -2173,11 +2165,26 @@ fn decommision_is_ok() {
DappsStaking::claim_dapp(RuntimeOrigin::signed(account), contract_id, 1,),
Error::<TestRuntime>::NotOperatedContract
);
assert_noop!(
DappsStaking::unbond_and_unstake(RuntimeOrigin::signed(account), contract_id, 100),
Error::<TestRuntime>::NotOperatedContract
);
assert_noop!(
DappsStaking::withdraw_unbonded(RuntimeOrigin::signed(account)),
Error::<TestRuntime>::NothingToWithdraw
);
assert_noop!(
DappsStaking::set_reward_destination(
RuntimeOrigin::signed(account),
RewardDestination::StakeBalance
),
Error::<TestRuntime>::NotActiveStaker
);
})
}

#[test]
fn no_era_change_during_decommision() {
fn no_era_change_during_decommission() {
ExternalityBuilder::build().execute_with(|| {
initialize_first_block();

Expand Down

0 comments on commit 95c25de

Please sign in to comment.