Skip to content

Commit

Permalink
test for chill and unbond
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 27, 2024
1 parent a3f6c12 commit cef400f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ pub mod pallet {
}

#[pallet::call_index(2)]
// TODO
#[pallet::weight(<T as Config>::WeightInfo::withdraw_unbonded())]
pub fn unbonded(
pub fn unbond(
origin: OriginFor<T>,
#[pallet::compact] value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
Expand All @@ -425,6 +426,7 @@ pub mod pallet {
}

#[pallet::call_index(3)]
// TODO
#[pallet::weight(<T as Config>::WeightInfo::withdraw_unbonded())]
pub fn chill(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let controller = ensure_signed(origin.clone())?;
Expand All @@ -448,6 +450,7 @@ pub mod pallet {

/// Wraps's substrate withdraw unbonded but clears extra state if fully unbonded
#[pallet::call_index(4)]
// TODO: add contains O(n) to bench
#[pallet::weight(<T as Config>::WeightInfo::withdraw_unbonded())]
pub fn withdraw_unbonded(
origin: OriginFor<T>,
Expand Down
68 changes: 68 additions & 0 deletions pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,71 @@ fn it_confirms_keyshare() {
assert_eq!(Staking::signers(), [6, 5], "next signers rotated into current signers");
});
}

#[test]
fn it_stops_unbonded_when_signer_or_next_signer() {
new_test_ext().execute_with(|| {
Signers::<Test>::put(vec![5, 6]);
NextSigners::<Test>::put(NextSignerInfo {
next_signers: vec![7, 8],
confirmations: vec![],
});
start_active_era(1);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(7),
100u64,
pallet_staking::RewardDestination::Account(1),
));

assert_noop!(
Staking::unbond(RuntimeOrigin::signed(7), 0),
Error::<Test>::NoUnbodingWhenNextSigner
);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(8),
100u64,
pallet_staking::RewardDestination::Account(1),
));

assert_noop!(
Staking::unbond(RuntimeOrigin::signed(8), 0),
Error::<Test>::NoUnbodingWhenNextSigner
);
});
}

#[test]
fn it_stops_chill_when_signer_or_next_signer() {
new_test_ext().execute_with(|| {
Signers::<Test>::put(vec![5, 6]);
NextSigners::<Test>::put(NextSignerInfo {
next_signers: vec![7, 8],
confirmations: vec![],
});
start_active_era(1);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(7),
100u64,
pallet_staking::RewardDestination::Account(1),
));

assert_noop!(
Staking::chill(RuntimeOrigin::signed(7)),
Error::<Test>::NoUnbodingWhenNextSigner
);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(8),
100u64,
pallet_staking::RewardDestination::Account(1),
));

assert_noop!(
Staking::chill(RuntimeOrigin::signed(8)),
Error::<Test>::NoUnbodingWhenNextSigner
);
});
}

0 comments on commit cef400f

Please sign in to comment.