[FRAME] Make core-fellowship ans salary work for swapped members (#3156)

Fixup for https://github.com/paritytech/polkadot-sdk/pull/2587 to make
the `core-fellowship` crate work with swapped members.

Adds a `MemberSwappedHandler` to the `ranked-collective` pallet that are
implemented by `core-fellowship+salary`.
There is are exhaustive tests
[here](https://github.com/paritytech/polkadot-sdk/blob/72aa7ac17a0e5b16faab5d2992aa2db2e01b05d0/substrate/frame/core-fellowship/src/tests/integration.rs#L338)
and
[here](https://github.com/paritytech/polkadot-sdk/blob/ab3cdb05a5ebc1ff841f8dda67edef0ea40bbba5/substrate/frame/salary/src/tests/integration.rs#L224)
to check that adding member `1` is equivalent to adding member `0` and
then swapping.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2024-01-31 17:29:48 +01:00
committed by GitHub
parent 6ea472ad5a
commit 07e55006ad
25 changed files with 795 additions and 69 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ pub use members::{AllowAll, DenyAll, Filter};
pub use members::{
AsContains, ChangeMembers, Contains, ContainsLengthBound, ContainsPair, Equals, Everything,
EverythingBut, FromContainsPair, InitializeMembers, InsideBoth, IsInVec, Nothing,
RankedMembers, SortedMembers, TheseExcept,
RankedMembers, RankedMembersSwapHandler, SortedMembers, TheseExcept,
};
mod validation;
@@ -490,7 +490,7 @@ pub trait OriginTrait: Sized {
/// Add a filter to the origin.
fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static);
/// Reset origin filters to default one, i.e `frame_system::Config::BaseCallFilter`.
/// Reset origin filters to default one, i.e `frame_system::1fig::BaseCallFilter`.
fn reset_filter(&mut self);
/// Replace the caller with caller from the other origin
@@ -297,6 +297,13 @@ pub trait RankedMembers {
fn demote(who: &Self::AccountId) -> DispatchResult;
}
/// Handler that can deal with the swap of two members.
#[impl_trait_for_tuples::impl_for_tuples(16)]
pub trait RankedMembersSwapHandler<AccountId, Rank> {
/// Member `old` was swapped with `new` at `rank`.
fn swapped(who: &AccountId, new_who: &AccountId, rank: Rank);
}
/// Trait for type that can handle the initialization of account IDs at genesis.
pub trait InitializeMembers<AccountId> {
/// Initialize the members to the given `members`.