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

feat(smith-members): only online smiths can invite/certify other smiths

parent 1a837959
No related branches found
No related tags found
No related merge requests found
Pipeline #34961 passed
This commit is part of merge request !217. Comments created here will be created in the context of that merge request.
......@@ -232,6 +232,8 @@ pub mod pallet {
OriginHasNeverBeenInvited,
/// Invitation is reseverd to smiths
InvitationIsASmithPrivilege,
/// Invitation is reseverd to online smiths
InvitationIsAOnlineSmithPrivilege,
/// Invitation must not have been accepted yet
InvitationAlreadyAccepted,
/// Invitation of an already known smith is forbidden except if it has been excluded
......@@ -244,6 +246,8 @@ pub mod pallet {
CertificationOnExcludedIsForbidden,
/// Issuer must be a smith
CertificationIsASmithPrivilege,
/// Only online smiths can certify
CertificationIsAOnlineSmithPrivilege,
/// Smith cannot certify itself
CertificationOfSelfIsForbidden,
/// Receiver must be invited by another smith
......@@ -300,13 +304,15 @@ impl<T: Config> Pallet<T> {
issuer: T::IdtyIndex,
receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
let issuer_status = Smiths::<T>::get(issuer)
.ok_or(Error::<T>::OriginHasNeverBeenInvited)?
.status;
let issuer = Smiths::<T>::get(issuer).ok_or(Error::<T>::OriginHasNeverBeenInvited)?;
ensure!(
issuer_status == SmithStatus::Smith,
issuer.status == SmithStatus::Smith,
Error::<T>::InvitationIsASmithPrivilege
);
ensure!(
issuer.expires_on.is_none(),
Error::<T>::InvitationIsAOnlineSmithPrivilege
);
if let Some(receiver_meta) = Smiths::<T>::get(receiver) {
ensure!(
receiver_meta.status == SmithStatus::Excluded,
......@@ -384,6 +390,10 @@ impl<T: Config> Pallet<T> {
issuer.status == SmithStatus::Smith,
Error::<T>::CertificationIsASmithPrivilege
);
ensure!(
issuer.expires_on.is_none(),
Error::<T>::CertificationIsAOnlineSmithPrivilege
);
let issued_certs = issuer.issued_certs.len() as u32;
ensure!(
issued_certs < T::MaxByIssuer::get(),
......
......@@ -36,6 +36,9 @@ fn process_to_become_a_smith_and_lose_it() {
],
})
.execute_with(|| {
// Go online to be able to invite+certify
Pallet::<Runtime>::smith_goes_online(1);
Pallet::<Runtime>::smith_goes_online(2);
// Events cannot be recorded on genesis
run_to_block(1);
// State before
......@@ -106,6 +109,9 @@ fn process_to_become_a_smith_and_lose_it() {
received_certs: vec![1, 2],
}
);
// Go online to be able to invite+certify
Pallet::<Runtime>::smith_goes_offline(1);
Pallet::<Runtime>::smith_goes_offline(2);
// On session 4 everything if fine
Pallet::<Runtime>::on_new_session(4);
......@@ -164,12 +170,14 @@ fn should_have_checks_on_certify() {
],
})
.execute_with(|| {
// Go online to be able to invite+certify
Pallet::<Runtime>::smith_goes_online(1);
// Initially
assert_eq!(
Smiths::<Runtime>::get(1).unwrap(),
SmithMeta {
status: SmithStatus::Smith,
expires_on: Some(5),
status: Smith,
expires_on: None,
issued_certs: vec![4],
received_certs: vec![2, 3, 4],
}
......@@ -177,7 +185,7 @@ fn should_have_checks_on_certify() {
assert_eq!(
Smiths::<Runtime>::get(2).unwrap(),
SmithMeta {
status: SmithStatus::Smith,
status: Smith,
expires_on: Some(5),
issued_certs: vec![1, 4],
received_certs: vec![3, 4],
......@@ -186,7 +194,7 @@ fn should_have_checks_on_certify() {
assert_eq!(
Smiths::<Runtime>::get(3).unwrap(),
SmithMeta {
status: SmithStatus::Pending,
status: Pending,
expires_on: Some(5),
issued_certs: vec![1, 2],
received_certs: vec![4],
......@@ -195,7 +203,7 @@ fn should_have_checks_on_certify() {
assert_eq!(
Smiths::<Runtime>::get(4).unwrap(),
SmithMeta {
status: SmithStatus::Smith,
status: Smith,
expires_on: Some(5),
issued_certs: vec![1, 2, 3],
received_certs: vec![1, 2],
......@@ -224,8 +232,8 @@ fn should_have_checks_on_certify() {
assert_eq!(
Smiths::<Runtime>::get(3).unwrap(),
SmithMeta {
status: SmithStatus::Pending,
expires_on: Some(5),
status: Pending,
expires_on: Some(5), // TODO: hmmm?
issued_certs: vec![1, 2],
received_certs: vec![4],
}
......@@ -356,7 +364,7 @@ fn smith_coming_back_recovers_its_issued_certs() {
assert_eq!(
Smiths::<Runtime>::get(2),
Some(SmithMeta {
status: SmithStatus::Excluded,
status: Excluded,
expires_on: None,
issued_certs: vec![1],
received_certs: vec![]
......@@ -379,12 +387,13 @@ fn smith_coming_back_recovers_its_issued_certs() {
assert_eq!(
Smiths::<Runtime>::get(2),
Some(SmithMeta {
status: SmithStatus::Smith,
status: Smith,
expires_on: Some(10),
issued_certs: vec![1],
received_certs: vec![1, 3]
})
);
Pallet::<Runtime>::smith_goes_online(2);
// We can verify it with the stock rule
assert_ok!(Pallet::<Runtime>::certify_smith(
RuntimeOrigin::signed(2),
......@@ -413,6 +422,10 @@ fn certifying_on_different_status() {
],
})
.execute_with(|| {
// Go online to be able to invite+certify
Pallet::<Runtime>::smith_goes_online(1);
Pallet::<Runtime>::smith_goes_online(2);
Pallet::<Runtime>::smith_goes_online(3);
// State before
assert_eq!(Smiths::<Runtime>::get(5), None);
assert_err!(
......@@ -476,6 +489,8 @@ fn invitation_on_non_wot_member() {
],
})
.execute_with(|| {
// Go online to be able to invite+certify
Pallet::<Runtime>::smith_goes_online(1);
// State before
assert_eq!(Smiths::<Runtime>::get(10), None);
......
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