Skip to content
Snippets Groups Projects
Commit a674fd7b authored by Éloïs's avatar Éloïs
Browse files

fix(smith-wot): smith certs expiration should revoke smith membership (!79)

* fix(smith-wot): smith certs expiration should revoke smith membership
parent 7248a40b
No related branches found
No related tags found
1 merge request!79fix(smith-wot): smith certs expiration should revoke smith membership
...@@ -32,6 +32,7 @@ mod benchmarking;*/ ...@@ -32,6 +32,7 @@ mod benchmarking;*/
pub use pallet::*; pub use pallet::*;
pub use types::*; pub use types::*;
use frame_support::dispatch::UnfilteredDispatchable;
use frame_support::pallet_prelude::*; use frame_support::pallet_prelude::*;
use frame_system::RawOrigin; use frame_system::RawOrigin;
use pallet_certification::traits::SetNextIssuableOn; use pallet_certification::traits::SetNextIssuableOn;
...@@ -44,7 +45,6 @@ type IdtyIndex = u32; ...@@ -44,7 +45,6 @@ type IdtyIndex = u32;
#[frame_support::pallet] #[frame_support::pallet]
pub mod pallet { pub mod pallet {
use super::*; use super::*;
use frame_support::dispatch::UnfilteredDispatchable;
use frame_support::traits::StorageVersion; use frame_support::traits::StorageVersion;
/// The current storage version. /// The current storage version.
...@@ -288,7 +288,7 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnNewcert<IdtyIndex ...@@ -288,7 +288,7 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnNewcert<IdtyIndex
Some(receiver), Some(receiver),
) { ) {
sp_std::if_std! { sp_std::if_std! {
println!("fail to claim membership: {:?}", e) println!("fail to claim membership: {:?}", e)
} }
} }
} else { } else {
...@@ -319,12 +319,24 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnRemovedCert<IdtyI ...@@ -319,12 +319,24 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnRemovedCert<IdtyI
if receiver_received_count < T::MinCertForMembership::get() if receiver_received_count < T::MinCertForMembership::get()
&& pallet_membership::Pallet::<T, I>::is_member(&receiver) && pallet_membership::Pallet::<T, I>::is_member(&receiver)
{ {
// Revoke receiver membership and disable their identity 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 { Self::dispath_idty_call(pallet_identity::Call::remove_identity {
idty_index: receiver, idty_index: receiver,
idty_name: None, idty_name: None,
}); });
} }
}
0 0
} }
} }
...@@ -151,7 +151,7 @@ parameter_types! { ...@@ -151,7 +151,7 @@ parameter_types! {
pub const MinReceivedCertToBeAbleToIssueCert: u32 = 2; pub const MinReceivedCertToBeAbleToIssueCert: u32 = 2;
pub const CertRenewablePeriod: u64 = 4; pub const CertRenewablePeriod: u64 = 4;
pub const CertPeriod: u64 = 2; pub const CertPeriod: u64 = 2;
pub const ValidityPeriod: u64 = 10; pub const ValidityPeriod: u64 = 20;
} }
impl pallet_certification::Config<Instance1> for Test { impl pallet_certification::Config<Instance1> for Test {
...@@ -218,11 +218,11 @@ impl pallet_certification::Config<Instance2> for Test { ...@@ -218,11 +218,11 @@ impl pallet_certification::Config<Instance2> for Test {
type Event = Event; type Event = Event;
type IdtyIndex = IdtyIndex; type IdtyIndex = IdtyIndex;
type IdtyIndexOf = Identity; type IdtyIndexOf = Identity;
type IsCertAllowed = DuniterWot; type IsCertAllowed = SmithsSubWot;
type MaxByIssuer = SmithsMaxByIssuer; type MaxByIssuer = SmithsMaxByIssuer;
type MinReceivedCertToBeAbleToIssueCert = SmithsMinReceivedCertToBeAbleToIssueCert; type MinReceivedCertToBeAbleToIssueCert = SmithsMinReceivedCertToBeAbleToIssueCert;
type OnNewcert = DuniterWot; type OnNewcert = SmithsSubWot;
type OnRemovedCert = DuniterWot; type OnRemovedCert = SmithsSubWot;
type CertRenewablePeriod = SmithsCertRenewablePeriod; type CertRenewablePeriod = SmithsCertRenewablePeriod;
type ValidityPeriod = SmithsValidityPeriod; type ValidityPeriod = SmithsValidityPeriod;
} }
...@@ -295,7 +295,7 @@ pub fn new_test_ext( ...@@ -295,7 +295,7 @@ pub fn new_test_ext(
.unwrap(); .unwrap();
pallet_certification::GenesisConfig::<Test, Instance2> { 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, apply_cert_period_at_genesis: true,
} }
.assimilate_storage(&mut t) .assimilate_storage(&mut t)
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::Identity;
use crate::mock::*; use crate::mock::*;
use crate::mock::{Identity, System};
use frame_support::assert_noop; use frame_support::assert_noop;
use frame_support::assert_ok; use frame_support::assert_ok;
use frame_support::instances::Instance1; use frame_support::instances::Instance1;
...@@ -60,11 +60,31 @@ fn test_join_smiths() { ...@@ -60,11 +60,31 @@ fn test_join_smiths() {
Origin::signed(4), Origin::signed(4),
crate::MembershipMetaData(4) crate::MembershipMetaData(4)
)); ));
System::assert_has_event(Event::SmithsMembership(
run_to_block(3); pallet_membership::Event::MembershipRequested(4),
));
// Then, Alice should be able to send a smith cert to Dave // 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)); 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),
));
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment