diff --git a/pallets/smith-members/src/lib.rs b/pallets/smith-members/src/lib.rs index 35918f55a00283378fd80f27686c8ecf7c6e0845..9a002c5442033093096a80e938e2f0a87e32920f 100644 --- a/pallets/smith-members/src/lib.rs +++ b/pallets/smith-members/src/lib.rs @@ -186,6 +186,7 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig<T: Config> { + /// Receiver -> (is_online, issuers) pub initial_smiths: BTreeMap<T::IdtyIndex, (bool, Vec<T::IdtyIndex>)>, } diff --git a/pallets/smith-members/src/tests.rs b/pallets/smith-members/src/tests.rs index 0ac9ba7ed63137d4519d484f20523a607cc6c329..1461838060d0111019a1da49aeb8ecad7a87626d 100644 --- a/pallets/smith-members/src/tests.rs +++ b/pallets/smith-members/src/tests.rs @@ -721,3 +721,31 @@ fn losing_wot_membership_cascades_to_smith_members() { ); }); } +#[test] +fn smith_members_should_not_be_able_to_invite_more_than_smith_cert_limit() { // MaxByIssuer + new_test_ext(GenesisConfig { + initial_smiths: btreemap![ + 1 => (true, vec![2, 3, 4]), + 2 => (false, vec![3, 4]), + 3 => (false, vec![1, 2]), + 4 => (false, vec![]), + ], + }) + .execute_with(|| { + let max_by_issuer:u32 = <mock::Runtime as pallet::Config>::MaxByIssuer::get(); + let max_by_issuer:u64 = max_by_issuer as _; + // Smith 1 Invite MaxByIssuer+1 member to become Simth + // Theses invites should pass + // Only MaxByIssuer - already_certified_by_1 (here -1 : smith 3) are invited + for i in 0..max_by_issuer-1 { + Pallet::<Runtime>::invite_smith(RuntimeOrigin::signed(1), 11+i).unwrap(); + assert!(Smiths::<Runtime>::get(11+i).is_some()); + } + // Theses invites should fail + // the other try to invite (here the 2 last) return error and are not invited + for i in max_by_issuer-1..max_by_issuer+1 { + Pallet::<Runtime>::invite_smith(RuntimeOrigin::signed(1), 11+i).unwrap_err(); + assert!(Smiths::<Runtime>::get(11+i).is_none()); + } + }); +}