Skip to content

Commit

Permalink
check keys registered in invulnerables too
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed Feb 8, 2024
1 parent 534d09d commit 01cb45b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pallets/invulnerables/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ pub mod pallet {
AlreadyInvulnerable,
/// Account is not an Invulnerable.
NotInvulnerable,
/// Account does not have keys registered
NoKeysRegistered,
}

#[pallet::call]
Expand Down Expand Up @@ -221,6 +223,14 @@ pub mod pallet {
who: T::AccountId,
) -> DispatchResultWithPostInfo {
T::UpdateOrigin::ensure_origin(origin)?;
// don't let one unprepared collator ruin things for everyone.
let collator_id = T::CollatorIdOf::convert(who.clone());

// Ensure it has keys registered
ensure!(
collator_id.map_or(false, |key| T::CollatorRegistration::is_registered(&key)),
Error::<T>::NoKeysRegistered
);

<Invulnerables<T>>::try_mutate(|invulnerables| -> DispatchResult {
if invulnerables.contains(&who) {
Expand Down
14 changes: 14 additions & 0 deletions pallets/invulnerables/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ fn add_invulnerable_works() {
});
}

#[test]
fn add_invulnerable_does_not_work_if_not_registered() {
new_test_ext().execute_with(|| {
initialize_to_block(1);
assert_eq!(Invulnerables::invulnerables(), vec![1, 2]);
let new = 42;

assert_noop!(
Invulnerables::add_invulnerable(RuntimeOrigin::signed(RootAccount::get()), new),
Error::<Test>::NoKeysRegistered
);
});
}

#[test]
fn invulnerable_limit_works() {
new_test_ext().execute_with(|| {
Expand Down

0 comments on commit 01cb45b

Please sign in to comment.