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;*/
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
}
......
......@@ -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)
......
......@@ -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),
));
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment