Skip to content
Snippets Groups Projects
Verified Commit 2f97bbaf authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

feat(duniter-wot): remove received certs on unvalidated idty removal

parent aaecb8f7
No related branches found
No related tags found
1 merge request!74#66 remove received certs on unvalidated idty removal
...@@ -249,7 +249,20 @@ impl<T: Config<I>, I: 'static> pallet_identity::traits::OnIdtyChange<T> for Pall ...@@ -249,7 +249,20 @@ impl<T: Config<I>, I: 'static> pallet_identity::traits::OnIdtyChange<T> for Pall
} }
IdtyEvent::Confirmed => {} IdtyEvent::Confirmed => {}
IdtyEvent::Validated => {} IdtyEvent::Validated => {}
IdtyEvent::Removed => {} IdtyEvent::Removed { status } => {
if status != IdtyStatus::Validated {
if let Err(e) =
<pallet_certification::Pallet<T, I>>::remove_all_certs_received_by(
frame_system::Origin::<T>::Root.into(),
idty_index,
)
{
sp_std::if_std! {
println!("fail to remove certs received by some idty: {:?}", e)
}
}
}
}
} }
0 0
} }
......
...@@ -287,3 +287,25 @@ fn test_idty_membership_expire_them_requested() { ...@@ -287,3 +287,25 @@ fn test_idty_membership_expire_them_requested() {
); );
}); });
} }
#[test]
fn test_unvalidated_idty_certs_removal() {
new_test_ext(5, 2).execute_with(|| {
// Alice creates Ferdie identity
run_to_block(2);
assert_ok!(Identity::create_identity(Origin::signed(1), 6));
// Ferdie confirms his identity
run_to_block(3);
assert_ok!(Identity::confirm_identity(
Origin::signed(6),
IdtyName::from("Ferdie"),
));
// After PendingMembershipPeriod, Ferdie identity should expire
// and his received certifications should be removed
assert_eq!(Cert::certs_by_receiver(6).len(), 1);
run_to_block(6);
assert_eq!(Cert::certs_by_receiver(6).len(), 0);
});
}
...@@ -525,7 +525,12 @@ pub mod pallet { ...@@ -525,7 +525,12 @@ pub mod pallet {
Identities::<T>::remove(idty_index); Identities::<T>::remove(idty_index);
frame_system::Pallet::<T>::dec_sufficients(&idty_val.owner_key); frame_system::Pallet::<T>::dec_sufficients(&idty_val.owner_key);
Self::deposit_event(Event::IdtyRemoved { idty_index }); Self::deposit_event(Event::IdtyRemoved { idty_index });
T::OnIdtyChange::on_idty_change(idty_index, IdtyEvent::Removed); T::OnIdtyChange::on_idty_change(
idty_index,
IdtyEvent::Removed {
status: idty_val.status,
},
);
} }
0 0
} }
......
...@@ -27,7 +27,7 @@ pub enum IdtyEvent<T: crate::Config> { ...@@ -27,7 +27,7 @@ pub enum IdtyEvent<T: crate::Config> {
Created { creator: T::IdtyIndex }, Created { creator: T::IdtyIndex },
Confirmed, Confirmed,
Validated, Validated,
Removed, Removed { status: IdtyStatus },
} }
#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug)] #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug)]
......
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