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