Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
add negative tests (#11995)
Browse files Browse the repository at this point in the history
* add negative tests

* remove tests powerless asserts checking against announcment origin

* assert bad origin from announcement origin checks

Co-authored-by: muharem <ismailov.m.h@gmail.com>
  • Loading branch information
gilescope and muharem authored Aug 26, 2022
1 parent 69f0802 commit 23bdc2e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ fn set_rule_works() {
fn announce_works() {
new_test_ext().execute_with(|| {
let cid = test_cid();

assert_noop!(Alliance::announce(Origin::signed(2), cid.clone()), BadOrigin);

assert_ok!(Alliance::announce(Origin::signed(3), cid.clone()));
assert_eq!(Alliance::announcements(), vec![cid.clone()]);

Expand Down Expand Up @@ -438,9 +441,39 @@ fn retire_works() {
member: (3),
unreserved: None,
}));

// Move time on:
System::set_block_number(System::block_number() + RetirementPeriod::get());

assert_powerless(Origin::signed(3));
});
}

fn assert_powerless(user: Origin) {
//vote / veto with a valid propsal
let cid = test_cid();
let proposal = make_proposal(42);

assert_noop!(Alliance::init_members(user.clone(), vec![], vec![], vec![]), BadOrigin);

assert_noop!(Alliance::set_rule(user.clone(), cid.clone()), BadOrigin);

assert_noop!(Alliance::retire(user.clone()), Error::<Test, ()>::RetirementNoticeNotGiven);

assert_noop!(Alliance::give_retirement_notice(user.clone()), Error::<Test, ()>::NotMember);

assert_noop!(Alliance::elevate_ally(user.clone(), 4), BadOrigin);

assert_noop!(Alliance::kick_member(user.clone(), 1), BadOrigin);

assert_noop!(Alliance::nominate_ally(user.clone(), 4), Error::<Test, ()>::NoVotingRights);

assert_noop!(
Alliance::propose(user.clone(), 5, Box::new(proposal), 1000),
Error::<Test, ()>::NoVotingRights
);
}

#[test]
fn kick_member_works() {
new_test_ext().execute_with(|| {
Expand All @@ -463,6 +496,8 @@ fn kick_member_works() {
#[test]
fn add_unscrupulous_items_works() {
new_test_ext().execute_with(|| {
assert_noop!(Alliance::add_unscrupulous_items(Origin::signed(2), vec![]), BadOrigin);

assert_ok!(Alliance::add_unscrupulous_items(
Origin::signed(3),
vec![
Expand All @@ -486,6 +521,8 @@ fn add_unscrupulous_items_works() {
#[test]
fn remove_unscrupulous_items_works() {
new_test_ext().execute_with(|| {
assert_noop!(Alliance::remove_unscrupulous_items(Origin::signed(2), vec![]), BadOrigin);

assert_noop!(
Alliance::remove_unscrupulous_items(
Origin::signed(3),
Expand Down

0 comments on commit 23bdc2e

Please sign in to comment.