Skip to content

Commit

Permalink
fix(pallet-communities): on tests, must unlock on casted votes
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Apr 22, 2024
1 parent 0107bad commit b49a3ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
11 changes: 3 additions & 8 deletions pallets/communities/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<T: Config> Pallet<T> {
let (tally, class) = poll_status.ensure_ongoing().ok_or(Error::<T>::NotOngoing)?;
ensure!(community_id == class, Error::<T>::InvalidTrack);

let (vote, _) = CommunityVotes::<T>::get(poll_index, membership_id).ok_or(Error::<T>::NoVoteCasted)?;
let (vote, voter) = CommunityVotes::<T>::get(poll_index, membership_id).ok_or(Error::<T>::NoVoteCasted)?;
let vote_multiplier = match CommunityDecisionMethod::<T>::get(community_id) {
DecisionMethod::Rank => T::MemberMgmt::rank_of(&community_id, &membership_id)
.unwrap_or_default()
Expand All @@ -133,16 +133,11 @@ impl<T: Config> Pallet<T> {
let vote_weight = VoteWeight::from(&vote);
tally.remove_vote(vote.say(), vote_multiplier * vote_weight, vote_weight);

Self::do_unlock(membership_id, poll_index)
CommunityVotes::<T>::remove(poll_index, membership_id);
Self::update_locks(&voter, poll_index, &vote, LockUpdateType::Remove)
})
}

pub(crate) fn do_unlock(membership_id: MembershipIdOf<T>, poll_index: PollIndexOf<T>) -> DispatchResult {
let (vote, voter) = CommunityVotes::<T>::get(poll_index, membership_id).ok_or(Error::<T>::NoVoteCasted)?;
CommunityVotes::<T>::remove(poll_index, membership_id);
Self::update_locks(&voter, poll_index, &vote, LockUpdateType::Remove)
}

pub(crate) fn update_locks(
who: &AccountIdOf<T>,
poll_index: PollIndexOf<T>,
Expand Down
3 changes: 2 additions & 1 deletion pallets/communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ pub mod pallet {
let who = ensure_signed(origin)?;
T::MemberMgmt::check_membership(&who, &membership_id).ok_or(Error::<T>::NotAMember)?;
ensure!(T::Polls::as_ongoing(poll_index).is_none(), Error::<T>::AlreadyOngoing);
Self::do_unlock(membership_id, poll_index)
let vote = CommunityVoteLocks::<T>::get(&who, poll_index).ok_or(Error::<T>::NoLocksInPlace)?;
Self::update_locks(&who, poll_index, &vote, LockUpdateType::Remove)
}

/// Dispatch a callable as the community account
Expand Down
4 changes: 2 additions & 2 deletions pallets/communities/src/tests/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,13 +1171,13 @@ mod unlock {

assert_ok!(Communities::unlock(
RuntimeOrigin::signed(BOB),
membership(COMMUNITY_C, 2),
membership(COMMUNITY_B, 1),
1
));

assert_ok!(Communities::unlock(
RuntimeOrigin::signed(CHARLIE),
membership(COMMUNITY_D, 3),
membership(COMMUNITY_C, 3),
2
));
});
Expand Down

0 comments on commit b49a3ee

Please sign in to comment.