Skip to content

Commit

Permalink
chore(pallet-communities): add tests for unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Mar 4, 2024
1 parent 68ede9f commit c1df84b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pallets/communities/src/tests/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,62 @@ mod vote {
// TODO: Implement rank-based voting first
}
}

mod unlock {
use super::*;

#[test]
fn fails_if_trying_to_unlock_on_an_ongoing_poll() {
new_test_ext().execute_with(|| {
// Since BOB never casted a vote, a lock wasn't put in place
assert_noop!(
Communities::unlock(RuntimeOrigin::signed(BOB), 1),
Error::AlreadyOngoing
);
});
}

#[test]
fn fails_if_no_locks_in_place() {
new_test_ext().execute_with(|| {
tick_blocks(6);

// Since BOB never casted a vote, a lock wasn't put in place
assert_noop!(
Communities::unlock(RuntimeOrigin::signed(BOB), 1),
Error::NoLocksInPlace
);

// Since CHARLIE never casted a vote, a freeze wasn't put in place
assert_noop!(
Communities::unlock(RuntimeOrigin::signed(CHARLIE), 2),
Error::NoLocksInPlace
);
});
}

#[test]
fn it_works() {
new_test_ext().execute_with(|| {
assert_ok!(Communities::vote(
RuntimeOrigin::signed(BOB),
MembershipId(COMMUNITY_B, 1),
1,
Vote::AssetBalance(true, COMMUNITY_B_ASSET_ID, 9)
));

assert_ok!(Communities::vote(
RuntimeOrigin::signed(CHARLIE),
MembershipId(COMMUNITY_C, 3),
2,
Vote::NativeBalance(true, 15)
));

tick_blocks(6);

assert_ok!(Communities::unlock(RuntimeOrigin::signed(BOB), 1));

assert_ok!(Communities::unlock(RuntimeOrigin::signed(CHARLIE), 2));
});
}
}

0 comments on commit c1df84b

Please sign in to comment.