Skip to content
Snippets Groups Projects
Commit 40533983 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

wip fix tests

parent 2a46c45b
No related branches found
No related tags found
No related merge requests found
......@@ -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(())
}
......
......@@ -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
);
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment