Skip to content

Commit

Permalink
add tests for nominators
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 30, 2024
1 parent b3d4f2c commit 135632f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
5 changes: 1 addition & 4 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,13 @@ benchmarks! {
let bonder: T::AccountId = account("bond", 0, SEED);
let threshold: T::AccountId = account("threshold", 0, SEED);

let signers = vec![validator_id_res.clone(); c as usize];
let signers = vec![validator_id_res.clone(); s as usize];
Signers::<T>::put(signers.clone());
NextSigners::<T>::put(NextSignerInfo {
next_signers: signers,
confirmations: vec![],
});

prep_bond_and_validate::<T>(true, caller.clone(), bonder.clone(), threshold, NULL_ARR);


}: _(RawOrigin::Signed(bonder.clone()), 10u32.into())
verify {
assert_last_event_frame_staking::<T>(FrameStakingEvent::Unbonded{ stash: bonder, amount: 10u32.into() }.into() );
Expand Down
46 changes: 42 additions & 4 deletions pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ fn it_deletes_when_no_bond_left() {
Error::<Test>::NoUnbondingWhenSigner
);

// test nominating flow
assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(101),
100u64,
pallet_staking::RewardDestination::Account(1),
));
assert_ok!(FrameStaking::nominate(RuntimeOrigin::signed(101), vec![7]));
assert_noop!(
Staking::withdraw_unbonded(RuntimeOrigin::signed(101), 0),
Error::<Test>::NoUnbondingWhenSigner
);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(8),
100u64,
Expand All @@ -335,6 +347,13 @@ fn it_deletes_when_no_bond_left() {
Staking::withdraw_unbonded(RuntimeOrigin::signed(8), 0),
Error::<Test>::NoUnbondingWhenNextSigner
);

// test nominating flow
assert_ok!(FrameStaking::nominate(RuntimeOrigin::signed(101), vec![8]));
assert_noop!(
Staking::withdraw_unbonded(RuntimeOrigin::signed(101), 0),
Error::<Test>::NoUnbondingWhenNextSigner
);
});
}

Expand Down Expand Up @@ -490,6 +509,18 @@ fn it_stops_unbonded_when_signer_or_next_signer() {
Signers::<Test>::put(vec![7]);
start_active_era(1);

// test nominating flow
assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(101),
100u64,
pallet_staking::RewardDestination::Account(1),
));
assert_ok!(FrameStaking::nominate(RuntimeOrigin::signed(101), vec![7]));
assert_noop!(
Staking::unbond(RuntimeOrigin::signed(101), 100u64),
Error::<Test>::NoUnbondingWhenSigner
);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(7),
100u64,
Expand All @@ -512,6 +543,13 @@ fn it_stops_unbonded_when_signer_or_next_signer() {
Staking::unbond(RuntimeOrigin::signed(8), 0),
Error::<Test>::NoUnbondingWhenNextSigner
);

// test nominating flow
assert_ok!(FrameStaking::nominate(RuntimeOrigin::signed(101), vec![8]));
assert_noop!(
Staking::unbond(RuntimeOrigin::signed(101), 100u64),
Error::<Test>::NoUnbondingWhenNextSigner
);
});
}

Expand All @@ -521,15 +559,15 @@ fn it_stops_chill_when_signer_or_next_signer() {
Signers::<Test>::put(vec![7]);
start_active_era(1);

// test nominating flow
assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(101),
100u64,
pallet_staking::RewardDestination::Account(1),
));
// test nominating flow
assert_ok!(FrameStaking::nominate(RuntimeOrigin::signed(101), vec![7]));
assert_noop!(
Staking::unbond(RuntimeOrigin::signed(101), 100u64),
Staking::chill(RuntimeOrigin::signed(101)),
Error::<Test>::NoUnbondingWhenSigner
);

Expand All @@ -556,10 +594,10 @@ fn it_stops_chill_when_signer_or_next_signer() {
Staking::chill(RuntimeOrigin::signed(8)),
Error::<Test>::NoUnbondingWhenNextSigner
);

// test nominating flow
assert_ok!(FrameStaking::nominate(RuntimeOrigin::signed(101), vec![8]));
assert_noop!(
Staking::unbond(RuntimeOrigin::signed(101), 100u64),
Staking::chill(RuntimeOrigin::signed(101)),
Error::<Test>::NoUnbondingWhenNextSigner
);
});
Expand Down

0 comments on commit 135632f

Please sign in to comment.