diff --git a/pallets/smith-members/src/lib.rs b/pallets/smith-members/src/lib.rs index 0bffb76319a755133a94aa05f04c32097c0586f1..c8f929c3f32af0ed66ad62db2086ac0f6cfde759 100644 --- a/pallets/smith-members/src/lib.rs +++ b/pallets/smith-members/src/lib.rs @@ -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(), diff --git a/pallets/smith-members/src/tests.rs b/pallets/smith-members/src/tests.rs index 405015f2b76bdd38f4a59c6117a27c49faa01285..82c57582f2f218b337879d7756a4f5f28de559b2 100644 --- a/pallets/smith-members/src/tests.rs +++ b/pallets/smith-members/src/tests.rs @@ -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);