diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 22669612004c9d49bbe6f43eebd7f2c77204e99f..693b30dd7d84d83ea5e6536daec967a8ea9dacfb 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -32,6 +32,7 @@ mod benchmarking;*/ pub use pallet::*; pub use types::*; +use frame_support::dispatch::UnfilteredDispatchable; use frame_support::pallet_prelude::*; use frame_system::RawOrigin; use pallet_certification::traits::SetNextIssuableOn; @@ -44,7 +45,6 @@ type IdtyIndex = u32; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::dispatch::UnfilteredDispatchable; use frame_support::traits::StorageVersion; /// The current storage version. @@ -288,7 +288,7 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnNewcert<IdtyIndex Some(receiver), ) { sp_std::if_std! { - println!("fail to claim membership:Â {:?}", e) + println!("fail to claim membership: {:?}", e) } } } else { @@ -319,11 +319,23 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnRemovedCert<IdtyI if receiver_received_count < T::MinCertForMembership::get() && pallet_membership::Pallet::<T, I>::is_member(&receiver) { - // Revoke receiver membership and disable their identity - Self::dispath_idty_call(pallet_identity::Call::remove_identity { - idty_index: receiver, - idty_name: None, - }); + if T::IsSubWot::get() { + // Revoke receiver membership + let call = pallet_membership::Call::<T, I>::revoke_membership { + maybe_idty_id: Some(receiver), + }; + if let Err(e) = call.dispatch_bypass_filter(RawOrigin::Root.into()) { + sp_std::if_std! { + println!("fail to dispatch membership call: {:?}", e) + } + } + } else { + // Revoke receiver membership and disable his identity + Self::dispath_idty_call(pallet_identity::Call::remove_identity { + idty_index: receiver, + idty_name: None, + }); + } } 0 } diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs index abcebb38cdb8d4f9546c116ff4a4ede3228de18e..ae08de65f1904dd7d340936b3e653c5acf8f0dd2 100644 --- a/pallets/duniter-wot/src/mock.rs +++ b/pallets/duniter-wot/src/mock.rs @@ -151,7 +151,7 @@ parameter_types! { pub const MinReceivedCertToBeAbleToIssueCert: u32 = 2; pub const CertRenewablePeriod: u64 = 4; pub const CertPeriod: u64 = 2; - pub const ValidityPeriod: u64 = 10; + pub const ValidityPeriod: u64 = 20; } impl pallet_certification::Config<Instance1> for Test { @@ -218,11 +218,11 @@ impl pallet_certification::Config<Instance2> for Test { type Event = Event; type IdtyIndex = IdtyIndex; type IdtyIndexOf = Identity; - type IsCertAllowed = DuniterWot; + type IsCertAllowed = SmithsSubWot; type MaxByIssuer = SmithsMaxByIssuer; type MinReceivedCertToBeAbleToIssueCert = SmithsMinReceivedCertToBeAbleToIssueCert; - type OnNewcert = DuniterWot; - type OnRemovedCert = DuniterWot; + type OnNewcert = SmithsSubWot; + type OnRemovedCert = SmithsSubWot; type CertRenewablePeriod = SmithsCertRenewablePeriod; type ValidityPeriod = SmithsValidityPeriod; } @@ -295,7 +295,7 @@ pub fn new_test_ext( .unwrap(); pallet_certification::GenesisConfig::<Test, Instance2> { - certs_by_issuer: clique_wot(initial_smiths_len, ValidityPeriod::get()), + certs_by_issuer: clique_wot(initial_smiths_len, SmithsValidityPeriod::get()), apply_cert_period_at_genesis: true, } .assimilate_storage(&mut t) diff --git a/pallets/duniter-wot/src/tests.rs b/pallets/duniter-wot/src/tests.rs index 5081c4073e4b044e675b83505a84dfcceaf0e35a..3e237c6090abd306fb4f42f6268a4bb6fe03c4ef 100644 --- a/pallets/duniter-wot/src/tests.rs +++ b/pallets/duniter-wot/src/tests.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU Affero General Public License // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. -use crate::mock::Identity; use crate::mock::*; +use crate::mock::{Identity, System}; use frame_support::assert_noop; use frame_support::assert_ok; use frame_support::instances::Instance1; @@ -60,11 +60,31 @@ fn test_join_smiths() { Origin::signed(4), crate::MembershipMetaData(4) )); - - run_to_block(3); + System::assert_has_event(Event::SmithsMembership( + pallet_membership::Event::MembershipRequested(4), + )); // Then, Alice should be able to send a smith cert to Dave + run_to_block(3); assert_ok!(SmithsCert::add_cert(Origin::signed(1), 4)); + + // Then, if Bob certify Dave, he should become member + run_to_block(4); + assert_ok!(SmithsCert::add_cert(Origin::signed(2), 4)); + System::assert_has_event(Event::SmithsMembership( + pallet_membership::Event::MembershipAcquired(4), + )); + }); +} + +#[test] +fn test_smith_certs_expirations_should_revoke_smith_membership() { + new_test_ext(5, 3).execute_with(|| { + // After block #10, alice membership should be revoked due to smith certs expiration + run_to_block(10); + System::assert_has_event(Event::SmithsMembership( + pallet_membership::Event::MembershipRevoked(1), + )); }); }