Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cunningly reduce complexity
  • Loading branch information
gavofyork committed Jan 18, 2020
commit ecb2a0e25aed98acd93c45dba215f7fa0444ecf1
17 changes: 9 additions & 8 deletions frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,12 @@ decl_module! {

/// Anull the founding of the society.
///
/// This may be done when there is only one member.
///
/// The dispatch origin for this call must be Signed, and the signing account must be the
/// `Founder`.
/// The dispatch origin for this call must be Signed, and the signing account must be both
/// the `Founder` and the `Head`. This implies that it may only be done when there is one
/// member.
///
/// # <weight>
/// - One storage read, O(M).
/// - Two storage reads O(1).
/// - Four storage removals O(1).
/// - One event.
///
Expand All @@ -850,8 +849,8 @@ decl_module! {
#[weight = SimpleDispatchInfo::FixedNormal(20_000)]
fn unfound(origin) {
let founder = ensure_signed(origin)?;
let members = <Members<T, I>>::get();
ensure!(members.len() == 1 && &members[0] == &founder, Error::<T, I>::NotFounder);
ensure!(Founder::<T, I>::get() == Some(founder.clone()), Error::<T, I>::NotFounder);
ensure!(Head::<T, I>::get() == Some(founder.clone()), Error::<T, I>::NotHead);

Members::<T, I>::kill();
Head::<T, I>::kill();
Expand Down Expand Up @@ -1082,8 +1081,10 @@ decl_error! {
NotCandidate,
/// Too many members in the society.
MaxMembers,
/// The society is not a single member who is the caller.
/// The caller is not the founder.
NotFounder,
/// The caller is not the head.
NotHead,
}
}

Expand Down
2 changes: 1 addition & 1 deletion frame/society/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn unfounding_works() {
run_to_block(8);

// Unfounding won't work now, even though it's from 20.
assert_noop!(Society::unfound(Origin::signed(20)), Error::<Test, _>::NotFounder);
assert_noop!(Society::unfound(Origin::signed(20)), Error::<Test, _>::NotHead);
});
}

Expand Down