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 {
ReceiverHasNotBeenInvited,
/// Smith must be a member of the main WoT
NotAMember,
/// A smith has a limited stock of certifications
TooMuchCertificationsIssued,
}
#[pallet::call]
......@@ -357,13 +359,16 @@ impl<T: Config> Pallet<T> {
receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
ensure!(issuer != receiver, Error::<T>::CannotCertifySelf);
let issuer_status = Smiths::<T>::get(issuer)
.ok_or(Error::<T>::IssuerHasNoSmithStatus)?
.status;
let issuer = Smiths::<T>::get(issuer).ok_or(Error::<T>::IssuerHasNoSmithStatus)?;
ensure!(
issuer_status == SmithStatus::Smith,
issuer.status == SmithStatus::Smith,
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)
.ok_or(Error::<T>::ReceiverHasNotBeenInvited)?
.status;
......
......@@ -95,7 +95,7 @@ impl pallet_smith_members::Config for Runtime {
type IdtyIdOf = ConvertInto;
type MinCertForMembership = ConstU32<2>;
type MinCertForCreateIdtyRight = ConstU32<3>;
type MaxByIssuer = ConstU32<5>;
type MaxByIssuer = ConstU32<3>;
type InactivityMaxDuration = ConstU32<5>;
type OnSmithDelete = ();
type IdtyIdOfAuthorityId = ConvertInto;
......
......@@ -387,5 +387,19 @@ fn smith_coming_back_recovers_its_issued_certs() {
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.
Finish editing this message first!
Please register or to comment