Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Simplifies test assertions; tests events
Browse files Browse the repository at this point in the history
  • Loading branch information
gpestana committed Jul 17, 2023
1 parent bb8adf5 commit 598c162
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod mock;

pub(crate) const LOG_TARGET: &str = "tests::e2e-epm";

use frame_support::{assert_err, assert_ok};
use frame_support::{assert_err, assert_noop, assert_ok};
use mock::*;
use sp_core::Get;
use sp_npos_elections::{to_supports, StakedAssignment};
Expand Down Expand Up @@ -287,7 +287,7 @@ fn set_validation_intention_after_chilled() {
///
/// Related to <https://github.com/paritytech/substrate/issues/14246>.
fn ledger_consistency_active_balance_below_ed() {
use pallet_staking::Error;
use pallet_staking::{Error, Event};

ExtBuilder::default()
.staking(StakingExtBuilder::default())
Expand All @@ -296,18 +296,17 @@ fn ledger_consistency_active_balance_below_ed() {

// unbonding total of active stake fails because the active ledger balance would fall
// below the `MinNominatorBond`.
assert_err!(
assert_noop!(
Staking::unbond(RuntimeOrigin::signed(11), 1000),
Error::<Runtime>::InsufficientBond
);
assert_eq!(Staking::ledger(&11).unwrap().active, 1000);

// however, chilling works as expected.
assert_ok!(Staking::chill(RuntimeOrigin::signed(11)));

// now unbonding the full active balance works, since remainer of the active balance is
// not enforced to be below `MinNominatorBond` if the stash has been chilled.
assert_ok!(Staking::unbond(RuntimeOrigin::signed(11), 1000),);
assert_ok!(Staking::unbond(RuntimeOrigin::signed(11), 1000));

// the active balance of the ledger entry is 0, while total balance is 1000 until
// `withdraw_unbonded` is called.
Expand All @@ -326,6 +325,12 @@ fn ledger_consistency_active_balance_below_ed() {
Error::<Runtime>::FundedTarget,
);

// check the events so far: 1x Chilled and 1x Unbounded
assert_eq!(
staking_events(),
[Event::Chilled { stash: 11 }, Event::Unbonded { stash: 11, amount: 1000 }]
);

// after advancing `BondingDuration` eras, the `withdraw_unbonded` will unlock the
// chunks and the ledger entry will be cleared, since the ledger active balance is 0.
advance_eras(<Runtime as pallet_staking::Config>::BondingDuration::get() as usize);
Expand Down

0 comments on commit 598c162

Please sign in to comment.