Skip to content
Snippets Groups Projects
Commit f9b04638 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

feat(smith-members): max stock of certifications per smith

parent 1cefacba
No related branches found
No related tags found
No related merge requests found
...@@ -245,6 +245,8 @@ pub mod pallet { ...@@ -245,6 +245,8 @@ pub mod pallet {
ReceiverHasNotBeenInvited, ReceiverHasNotBeenInvited,
/// Smith must be a member of the main WoT /// Smith must be a member of the main WoT
NotAMember, NotAMember,
/// A smith has a limited stock of certifications
TooMuchCertificationsIssued,
} }
#[pallet::call] #[pallet::call]
...@@ -357,13 +359,16 @@ impl<T: Config> Pallet<T> { ...@@ -357,13 +359,16 @@ impl<T: Config> Pallet<T> {
receiver: T::IdtyIndex, receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo { ) -> DispatchResultWithPostInfo {
ensure!(issuer != receiver, Error::<T>::CannotCertifySelf); ensure!(issuer != receiver, Error::<T>::CannotCertifySelf);
let issuer_status = Smiths::<T>::get(issuer) let issuer = Smiths::<T>::get(issuer).ok_or(Error::<T>::IssuerHasNoSmithStatus)?;
.ok_or(Error::<T>::IssuerHasNoSmithStatus)?
.status;
ensure!( ensure!(
issuer_status == SmithStatus::Smith, issuer.status == SmithStatus::Smith,
Error::<T>::IssuerIsNotASmith Error::<T>::IssuerIsNotASmith
); );
let issued_certs = issuer.issued_certs.len() as u32;
ensure!(
issued_certs < T::MaxByIssuer::get(),
Error::<T>::TooMuchCertificationsIssued
);
let receiver_status = Smiths::<T>::get(receiver) let receiver_status = Smiths::<T>::get(receiver)
.ok_or(Error::<T>::ReceiverHasNotBeenInvited)? .ok_or(Error::<T>::ReceiverHasNotBeenInvited)?
.status; .status;
......
...@@ -95,7 +95,7 @@ impl pallet_smith_members::Config for Runtime { ...@@ -95,7 +95,7 @@ impl pallet_smith_members::Config for Runtime {
type IdtyIdOf = ConvertInto; type IdtyIdOf = ConvertInto;
type MinCertForMembership = ConstU32<2>; type MinCertForMembership = ConstU32<2>;
type MinCertForCreateIdtyRight = ConstU32<3>; type MinCertForCreateIdtyRight = ConstU32<3>;
type MaxByIssuer = ConstU32<5>; type MaxByIssuer = ConstU32<3>;
type InactivityMaxDuration = ConstU32<5>; type InactivityMaxDuration = ConstU32<5>;
type OnSmithDelete = (); type OnSmithDelete = ();
type IdtyIdOfAuthorityId = ConvertInto; type IdtyIdOfAuthorityId = ConvertInto;
......
...@@ -387,5 +387,19 @@ fn smith_coming_back_recovers_its_issued_certs() { ...@@ -387,5 +387,19 @@ fn smith_coming_back_recovers_its_issued_certs() {
received_certs: vec![1, 3] received_certs: vec![1, 3]
}) })
); );
// We can verify it with the stock rule
assert_ok!(Pallet::<Runtime>::certify_smith(
RuntimeOrigin::signed(2),
3
));
assert_ok!(Pallet::<Runtime>::certify_smith(
RuntimeOrigin::signed(2),
4
));
// Max stock is reached (3 = 1 recovered + 2 new)
assert_err!(
Pallet::<Runtime>::certify_smith(RuntimeOrigin::signed(2), 5),
Error::<Runtime>::TooMuchCertificationsIssued
);
}); });
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment