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

add negative tests #11995

Merged
merged 4 commits into from
Aug 26, 2022
Merged

Conversation

gilescope
Copy link
Contributor

Added some more negative tests to make sure a retired person has no special privileges.

The last 3 asserts currently return Ok(()) and thus fail the test.

We're using 4 and the announcement origin is defined as the following in the mock:

`type AnnouncementOrigin = EnsureSignedBy<Three, u64>;`

Maybe I have got the test wrong in some way?

@gilescope gilescope requested a review from muharem August 8, 2022 18:16
@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Aug 8, 2022
Comment on lines 474 to 478
assert_noop!(Alliance::add_unscrupulous_items(user.clone(), vec![]), BadOrigin);

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

assert_noop!(Alliance::announce(user, cid.clone()), Error::<Test, ()>::NotAlly);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there three checked by AnnouncementOrigin, which is configurable by user, and for these tests its mocked to return true for user 3

});
}

fn assert_powerless(user: Origin) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I think right not it make sense to check if method supposed to be executed by a member.
For add_unscrupulous_items for example, its not really a case, because its checked by AnnouncementOrigin provided by client of pallet.

If you think it should be different (should check if the caller is a member for example), I think we need a different issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise in this context we are not really checking than the retirement made the use powerless, but more that announcement functionality is allowed only for AnnouncementOrigin

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

assert_powerless(Origin::signed(3));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using 3, not 4


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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gilescope
the last one user.clone() could be just user

@muharem muharem merged commit 23bdc2e into pallet-alliance-retirement-notice Aug 26, 2022
@muharem muharem deleted the giles-add-negative-tests branch August 26, 2022 14:43
paritytech-processbot bot pushed a commit that referenced this pull request Aug 29, 2022
* Alliance pallet: retirement notice

* add alliance pallet to benchmark list for dev chain

* fix type

* ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance

* ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance

* link weight generated by bench for retirement_notice method

* migration to clear UpForKicking storage prefix

* rename migration from v1 to v0_to_v1

* Apply suggestions from code review

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* rename `retirement-notice to give-retirement-notice

* Apply suggestions from code review

Co-authored-by: Squirrel <gilescope@gmail.com>

* review fixes: update doc, saturating add, BlockNumber type alias

* add suffix to duratin consts *_IN_BLOCKS

* ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance

* add negative tests (#11995)

* 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>

Co-authored-by: command-bot <>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Squirrel <gilescope@gmail.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Alliance pallet: retirement notice

* add alliance pallet to benchmark list for dev chain

* fix type

* ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance

* ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance

* link weight generated by bench for retirement_notice method

* migration to clear UpForKicking storage prefix

* rename migration from v1 to v0_to_v1

* Apply suggestions from code review

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* rename `retirement-notice to give-retirement-notice

* Apply suggestions from code review

Co-authored-by: Squirrel <gilescope@gmail.com>

* review fixes: update doc, saturating add, BlockNumber type alias

* add suffix to duratin consts *_IN_BLOCKS

* ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance

* add negative tests (paritytech#11995)

* 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>

Co-authored-by: command-bot <>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Squirrel <gilescope@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants