From 1e99f6b28385443cc60e37c987b56aaa44cc8c41 Mon Sep 17 00:00:00 2001 From: "[1000i100] Millicent Billette" <git@1000i100.fr> Date: Tue, 10 Dec 2024 16:46:11 +0100 Subject: [PATCH] test smith_members_should_not_be_able_to_invite_more_than_smith_cert_limit fail like observed in gdev. --- pallets/smith-members/src/lib.rs | 1 + pallets/smith-members/src/tests.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/pallets/smith-members/src/lib.rs b/pallets/smith-members/src/lib.rs index 35918f55a..9a002c544 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 0ac9ba7ed..146183806 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()); + } + }); +} -- GitLab