Skip to content

Commit

Permalink
Ensure no pending vote when unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ark930 committed Oct 18, 2023
1 parent be8b59a commit 17a278c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions pallets/vtoken-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ pub mod pallet {
Self::ensure_referendum_completed(vtoken, poll_index)
.or(Self::ensure_referendum_killed(vtoken, poll_index))
.map_err(|_| Error::<T>::NoPermissionYet)?;
Self::ensure_no_pending_vote(vtoken, poll_index)?;

Self::try_remove_vote(&who, vtoken, poll_index, UnvoteScope::Any)?;
Self::update_lock(&who, vtoken, &poll_index)?;
Expand Down
10 changes: 10 additions & 0 deletions pallets/vtoken-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,17 @@ fn successful_conviction_vote_balance_stays_locked_for_correct_time() {
fn lock_amalgamation_valid_with_multiple_removed_votes() {
new_test_ext().execute_with(|| {
let vtoken = VKSM;
let response = response_success();

assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, 0, aye(5, 1)));
assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, 1, aye(10, 1)));
assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, 2, aye(5, 2)));
assert_eq!(usable_balance(vtoken, &ALICE), 0);

assert_ok!(VtokenVoting::notify_vote(origin_response(), 0, response.clone()));
assert_ok!(VtokenVoting::notify_vote(origin_response(), 1, response.clone()));
assert_ok!(VtokenVoting::notify_vote(origin_response(), 2, response.clone()));

assert_ok!(VtokenVoting::set_referendum_status(
RuntimeOrigin::root(),
vtoken,
Expand Down Expand Up @@ -406,12 +411,17 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
fn removed_votes_when_referendum_killed() {
new_test_ext().execute_with(|| {
let vtoken = VKSM;
let response = response_success();

assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, 0, aye(5, 1)));
assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, 1, aye(10, 1)));
assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, 2, aye(5, 2)));
assert_eq!(usable_balance(vtoken, &ALICE), 0);

assert_ok!(VtokenVoting::notify_vote(origin_response(), 0, response.clone()));
assert_ok!(VtokenVoting::notify_vote(origin_response(), 1, response.clone()));
assert_ok!(VtokenVoting::notify_vote(origin_response(), 2, response.clone()));

assert_ok!(VtokenVoting::set_referendum_status(
RuntimeOrigin::root(),
vtoken,
Expand Down

0 comments on commit 17a278c

Please sign in to comment.