From 6dc6a015293accd1184ebbb9fba79100b8e2d398 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Fri, 12 May 2023 17:38:16 +0200 Subject: [PATCH] reveal smith certification quirck smith certification do not require smith membership request --- pallets/duniter-wot/src/lib.rs | 5 ++++ runtime/gdev/tests/integration_tests.rs | 35 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index bcd64dafa..b25d29d34 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -209,6 +209,7 @@ 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> { + // ensure issuer has validated identity if let Some(issuer_data) = pallet_identity::Pallet::<T>::identity(issuer) { ensure!( issuer_data.status == IdtyStatus::Validated, @@ -217,6 +218,7 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id } else { return Err(Error::<T, I>::IdtyNotFound.into()); } + // ensure receiver has confirmed or validated identity if let Some(receiver_data) = pallet_identity::Pallet::<T>::identity(receiver) { match receiver_data.status { IdtyStatus::ConfirmedByOwner | IdtyStatus::Validated => {} // able to receive cert @@ -225,6 +227,9 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id } else { return Err(Error::<T, I>::IdtyNotFound.into()); } + /* if T::IsSubWot::get() { + // in case of smith wot no additional constraint + } */ Ok(()) } } diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index b7eb8a87f..60783623a 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -631,6 +631,41 @@ fn test_remove_smith_identity() { )); }); } +use pallet_certification::Instance2; +#[test] +fn test_smith_certification() { + // 3 smith (1. alice, 2. bob, 3. charlie) + // 4 identities (4. dave) + // no identity 5. eve + ExtBuilder::new(1, 3, 4).build().execute_with(|| { + run_to_block(1); + + // alice can renew smith cert to bob + assert_ok!(SmithCert::add_cert( + frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(), + 1, // alice + 2 // bob + )); + + // bob can add new smith cert to to dave even he did not requested smith membership + assert_ok!(SmithCert::add_cert( + frame_system::RawOrigin::Signed(AccountKeyring::Bob.to_account_id()).into(), + 2, // bob + 4 // dave + )); + + // charlie can not add new cert to to eve (no identity) + assert_noop!( + SmithCert::add_cert( + frame_system::RawOrigin::Signed(AccountKeyring::Charlie.to_account_id()).into(), + 3, // charlie + 5 // eve + ), + // SmithSubWot::Error::IdtyNotFound, + pallet_duniter_wot::Error::<gdev_runtime::Runtime, Instance2>::IdtyNotFound, + ); + }); +} /// test create new account with balance lower than existential deposit // the treasury gets the dust -- GitLab