Skip to content
Snippets Groups Projects
Commit a1cff7e3 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

feat(#173): add SmithCertificationRemoved event

parent 515e5b8b
No related branches found
No related tags found
1 merge request!228Resolve "Améliorations pour smith-members"
...@@ -140,6 +140,11 @@ pub mod pallet { ...@@ -140,6 +140,11 @@ pub mod pallet {
idty_index: T::IdtyIndex, idty_index: T::IdtyIndex,
issued_by: T::IdtyIndex, issued_by: T::IdtyIndex,
}, },
/// Certification lost
SmithCertificationRemoved {
idty_index: T::IdtyIndex,
issued_by: T::IdtyIndex,
},
/// A smith gathered enough certifications to become an authority (can call `go_online()`). /// A smith gathered enough certifications to become an authority (can call `go_online()`).
PromotedToSmith { idty_index: T::IdtyIndex }, PromotedToSmith { idty_index: T::IdtyIndex },
/// A smith has been removed from the smiths set. /// A smith has been removed from the smiths set.
...@@ -493,11 +498,15 @@ impl<T: Config> Pallet<T> { ...@@ -493,11 +498,15 @@ impl<T: Config> Pallet<T> {
} }
}); });
// We remove the lost certs from their issuer's stock // We remove the lost certs from their issuer's stock
for lost_cert in lost_certs { for lost_cert_issuer in lost_certs {
Smiths::<T>::mutate(lost_cert, |maybe_smith_meta| { Smiths::<T>::mutate(lost_cert_issuer, |maybe_smith_meta| {
if let Some(smith_meta) = maybe_smith_meta { if let Some(smith_meta) = maybe_smith_meta {
if let Ok(index) = smith_meta.issued_certs.binary_search(&idty_index) { if let Ok(index) = smith_meta.issued_certs.binary_search(&idty_index) {
smith_meta.issued_certs.remove(index); smith_meta.issued_certs.remove(index);
Self::deposit_event(Event::<T>::SmithCertificationRemoved {
idty_index,
issued_by: lost_cert_issuer,
});
} }
} }
}); });
......
...@@ -123,12 +123,60 @@ fn process_to_become_a_smith_and_lose_it() { ...@@ -123,12 +123,60 @@ fn process_to_become_a_smith_and_lose_it() {
System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded { System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded {
idty_index: 1, idty_index: 1,
})); }));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 1,
issued_by: 2,
},
));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 1,
issued_by: 3,
},
));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 1,
issued_by: 4,
},
));
System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded { System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded {
idty_index: 2, idty_index: 2,
})); }));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 2,
issued_by: 3,
},
));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 2,
issued_by: 4,
},
));
System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded { System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded {
idty_index: 5, idty_index: 5,
})); }));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 1,
issued_by: 3,
},
));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 5,
issued_by: 1,
},
));
System::assert_has_event(RuntimeEvent::Smith(
Event::<Runtime>::SmithCertificationRemoved {
idty_index: 5,
issued_by: 2,
},
));
assert_eq!( assert_eq!(
Smiths::<Runtime>::get(1), Smiths::<Runtime>::get(1),
Some(SmithMeta { Some(SmithMeta {
......
...@@ -1542,6 +1542,18 @@ fn test_smith_member_can_revoke_its_idty() { ...@@ -1542,6 +1542,18 @@ fn test_smith_member_can_revoke_its_idty() {
System::assert_has_event(RuntimeEvent::SmithMembers( System::assert_has_event(RuntimeEvent::SmithMembers(
pallet_smith_members::Event::SmithExcluded { idty_index: 3 }, pallet_smith_members::Event::SmithExcluded { idty_index: 3 },
)); ));
System::assert_has_event(RuntimeEvent::SmithMembers(
pallet_smith_members::Event::SmithCertificationRemoved {
idty_index: 3,
issued_by: 1,
},
));
System::assert_has_event(RuntimeEvent::SmithMembers(
pallet_smith_members::Event::SmithCertificationRemoved {
idty_index: 3,
issued_by: 2,
},
));
// Now Charlie is going out // Now Charlie is going out
assert!(pallet_authority_members::OutgoingAuthorities::<Runtime>::get().contains(&3)); assert!(pallet_authority_members::OutgoingAuthorities::<Runtime>::get().contains(&3));
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment