diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 5afc0ce52f6fe78b4c9b60a8849557067ef9a7de..c687359bf070fe9c45e7a6d870502871e36a5167 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -117,6 +117,10 @@ pub mod pallet { IssuerCanNotEmitCert, /// Can not issue cert to unconfirmed identity CertToUnconfirmedIdty, + /// Issuer not found + IssuerNotFound, + /// Receiver not found + ReceiverNotFound, } } @@ -206,16 +210,19 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id for Pallet<T, I> { fn check_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> Result<(), DispatchError> { - if let Some(issuer_data) = pallet_identity::Pallet::<T>::identity(issuer) { - if issuer_data.status != IdtyStatus::Validated { - return Err(Error::<T, I>::IssuerCanNotEmitCert.into()); - } - if let Some(receiver_data) = pallet_identity::Pallet::<T>::identity(receiver) { - match receiver_data.status { - IdtyStatus::ConfirmedByOwner | IdtyStatus::Validated => (), - IdtyStatus::Created => return Err(Error::<T, I>::CertToUnconfirmedIdty.into()), - } - }; + match pallet_identity::Pallet::<T>::identity(issuer) { + Some(issuer_data) => ensure!( + issuer_data.status == IdtyStatus::Validated, + Error::<T, I>::IssuerCanNotEmitCert + ), + None => return Err(Error::<T, I>::IssuerNotFound.into()), + }; + match pallet_identity::Pallet::<T>::identity(receiver) { + Some(receiver_data) => ensure!( + receiver_data.status != IdtyStatus::Created, + Error::<T, I>::CertToUnconfirmedIdty + ), + None => return Err(Error::<T, I>::ReceiverNotFound.into()), }; Ok(()) } diff --git a/pallets/duniter-wot/src/tests.rs b/pallets/duniter-wot/src/tests.rs index 63ad3bcddc160a25c90bb541b689b8430026fc1e..84f1076138c02eb292f6769fb7478408ecdfa09d 100644 --- a/pallets/duniter-wot/src/tests.rs +++ b/pallets/duniter-wot/src/tests.rs @@ -16,8 +16,9 @@ use crate::mock::*; use crate::mock::{Identity, System}; +use crate::pallet as pallet_duniter_wot; use codec::Encode; -use frame_support::instances::Instance1; +use frame_support::instances::{Instance1, Instance2}; use frame_support::{assert_noop, assert_ok}; use pallet_identity::{ IdtyName, IdtyStatus, NewOwnerKeyPayload, RevocationPayload, NEW_OWNER_KEY_PAYLOAD_PREFIX, @@ -46,9 +47,10 @@ fn test_creator_not_allowed_to_create_idty() { // Alice should not be able to create an identity before block #2 // because Alice.next_issuable_on = 2 + // but the true reason is that alice did not receive enough certs assert_noop!( Identity::create_identity(Origin::signed(1), 4), - pallet_identity::Error::<Test>::IdtyCreationPeriodNotRespected + pallet_duniter_wot::Error::<Test, Instance1>::NotEnoughReceivedCertsToCreateIdty ); }); } @@ -114,7 +116,7 @@ fn test_smith_member_cant_change_its_idty_address() { 13, TestSignature(13, (NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode()) ), - pallet_identity::Error::<Test>::NotAllowedToChangeIdtyAddress + pallet_duniter_wot::Error::<Test, Instance2>::NotAllowedToChangeIdtyAddress ); }); } @@ -137,7 +139,7 @@ fn test_smith_member_cant_revoke_its_idty() { 3, TestSignature(3, (REVOCATION_PAYLOAD_PREFIX, revocation_payload).encode()) ), - pallet_identity::Error::<Test>::NotAllowedToRemoveIdty + pallet_duniter_wot::Error::<Test, Instance2>::NotAllowedToRemoveIdty ); }); } @@ -269,7 +271,7 @@ fn test_idty_membership_expire_them_requested() { // Alice can't renew her cert to Charlie assert_noop!( Cert::add_cert(Origin::signed(1), 1, 3), - pallet_certification::Error::<Test, Instance1>::CertNotAllowed + pallet_duniter_wot::Error::<Test, Instance1>::ReceiverNotFound ); }); }