Skip to content

Commit

Permalink
[pallet_collective] Enforce prime is a valid member of collective in …
Browse files Browse the repository at this point in the history
…set_members extrinsic (paritytech#14354)

* Updated set_members extrinsic to enforce prime is valid member of collective

* Added additional tests for set_members extrinsic

* applied the code review suggestions
  • Loading branch information
ToufeeqP authored and nathanwhit committed Jul 19, 2023
1 parent da1b8d6 commit c3cfaa1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ pub mod pallet {
WrongProposalWeight,
/// The given length bound for the proposal was too low.
WrongProposalLength,
/// Prime account is not a member
PrimeAccountNotMember,
}

#[pallet::hooks]
Expand Down Expand Up @@ -417,6 +419,9 @@ pub mod pallet {
old.len(),
);
}
if let Some(p) = &prime {
ensure!(new_members.contains(p), Error::<T, I>::PrimeAccountNotMember);
}
let mut new_members = new_members;
new_members.sort();
<Self as ChangeMembers<T::AccountId>>::set_members_sorted(&new_members, &old);
Expand Down
19 changes: 19 additions & 0 deletions frame/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@ fn initialize_members_sorts_members() {
});
}

#[test]
fn set_members_with_prime_works() {
ExtBuilder::default().build_and_execute(|| {
let members = vec![1, 2, 3];
assert_ok!(Collective::set_members(
RuntimeOrigin::root(),
members.clone(),
Some(3),
MaxMembers::get()
));
assert_eq!(Collective::members(), members.clone());
assert_eq!(Collective::prime(), Some(3));
assert_noop!(
Collective::set_members(RuntimeOrigin::root(), members, Some(4), MaxMembers::get()),
Error::<Test, Instance1>::PrimeAccountNotMember
);
});
}

#[test]
fn proposal_weight_limit_works() {
ExtBuilder::default().build_and_execute(|| {
Expand Down

0 comments on commit c3cfaa1

Please sign in to comment.