Skip to content

Commit

Permalink
pallet-membership should implement ContainsLengthBound (#4865)
Browse files Browse the repository at this point in the history
### ISSUE
Link to the issue:
#1143

Deliverables
 - Implement trait `ContainsLengthBound` for pallet-membership
 

### Test Outcomes
___
Successful tests by running `cargo test -p pallet-membership --features
runtime-benchmarks`



running 22 tests
test tests::__construct_runtime_integrity_test::runtime_integrity_tests
... ok
test benchmark::bench_clear_prime ... ok
test tests::add_member_works ... ok
test tests::change_key_with_same_caller_as_argument_changes_nothing ...
ok
test tests::change_key_works ... ok
test benchmark::bench_set_prime ... ok
test benchmark::bench_remove_member ... ok
test benchmark::bench_change_key ... ok
test tests::change_key_works_that_does_not_change_order ... ok
test benchmark::bench_reset_members ... ok
test benchmark::bench_add_member ... ok
test tests::genesis_build_panics_with_duplicate_members - should panic
... ok
test benchmark::bench_swap_member ... ok
test tests::query_membership_works ... ok
test tests::prime_member_works ... ok
test tests::test_genesis_config_builds ... ok
test tests::remove_member_works ... ok
test tests::migration_v4 ... ok
test tests::swap_member_with_identical_arguments_changes_nothing ... ok
test tests::swap_member_works_that_does_not_change_order ... ok
test tests::swap_member_works ... ok
test tests::reset_members_works ... ok

test result: ok. 22 passed; 0 failed; 0 ignored; 0 measured; 0 filtered
out; finished in 0.01s

   Doc-tests pallet_membership

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered
out; finished in 0.00s

---------

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
Aideepakchaudhary and bkchr authored Jun 24, 2024
1 parent 7df94a4 commit fed81f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions prdoc/pr_4865.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Implement trait `ContainsLengthBound` for pallet-membership

doc:
- audience: Runtime Dev
description: |
Implement trait ContainsLengthBound for pallet membership otherwise we can't use it with pallet-tips without wrapper

crates:
- name: pallet-membership
bump: minor
13 changes: 12 additions & 1 deletion substrate/frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{
traits::{ChangeMembers, Contains, Get, InitializeMembers, SortedMembers},
traits::{ChangeMembers, Contains, ContainsLengthBound, Get, InitializeMembers, SortedMembers},
BoundedVec,
};
use sp_runtime::traits::{StaticLookup, UniqueSaturatedInto};
Expand Down Expand Up @@ -361,6 +361,17 @@ impl<T: Config<I>, I: 'static> Contains<T::AccountId> for Pallet<T, I> {
}
}

impl<T: Config> ContainsLengthBound for Pallet<T> {
fn min_len() -> usize {
0
}

/// Implementation uses a parameter type so calling is cost-free.
fn max_len() -> usize {
T::MaxMembers::get() as usize
}
}

impl<T: Config<I>, I: 'static> SortedMembers<T::AccountId> for Pallet<T, I> {
fn sorted_members() -> Vec<T::AccountId> {
Self::members().to_vec()
Expand Down

0 comments on commit fed81f7

Please sign in to comment.