diff --git a/pallets/smith-members/src/lib.rs b/pallets/smith-members/src/lib.rs index 288b5661ba3ed70cdedac1d50555b7de234b00b3..d02cfb788cd61403ac945e887417339e0fae374e 100644 --- a/pallets/smith-members/src/lib.rs +++ b/pallets/smith-members/src/lib.rs @@ -140,6 +140,11 @@ pub mod pallet { idty_index: 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()`). PromotedToSmith { idty_index: T::IdtyIndex }, /// A smith has been removed from the smiths set. @@ -493,11 +498,15 @@ impl<T: Config> Pallet<T> { } }); // We remove the lost certs from their issuer's stock - for lost_cert in lost_certs { - Smiths::<T>::mutate(lost_cert, |maybe_smith_meta| { + for lost_cert_issuer in lost_certs { + Smiths::<T>::mutate(lost_cert_issuer, |maybe_smith_meta| { if let Some(smith_meta) = maybe_smith_meta { if let Ok(index) = smith_meta.issued_certs.binary_search(&idty_index) { smith_meta.issued_certs.remove(index); + Self::deposit_event(Event::<T>::SmithCertificationRemoved { + idty_index, + issued_by: lost_cert_issuer, + }); } } }); diff --git a/pallets/smith-members/src/tests.rs b/pallets/smith-members/src/tests.rs index 026e6252e74dc98d7d22a6b1a1784aac854abac6..f9ec6024247e1ab85f111f33308bfc422722ff5f 100644 --- a/pallets/smith-members/src/tests.rs +++ b/pallets/smith-members/src/tests.rs @@ -123,12 +123,60 @@ fn process_to_become_a_smith_and_lose_it() { System::assert_has_event(RuntimeEvent::Smith(Event::<Runtime>::SmithExcluded { 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 { 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 { 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!( Smiths::<Runtime>::get(1), Some(SmithMeta { diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index cfc3cb05d3e533518bb32eb7768a12de8cd09a55..c912e5848b03f7074d300c0d5d636f428d7c95b5 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -1542,6 +1542,18 @@ fn test_smith_member_can_revoke_its_idty() { System::assert_has_event(RuntimeEvent::SmithMembers( 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 assert!(pallet_authority_members::OutgoingAuthorities::<Runtime>::get().contains(&3)); });