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

Commit

Permalink
Fix invalid state transitions in pallet-bounties (paritytech#11630)
Browse files Browse the repository at this point in the history
* Pallet-bounty: disallow invalid state transitions

* Fix tests: funding only at even block numbers

* Fix benchmarks: bounties need to be funded

* fix on_initialize

Co-authored-by: Shawn Tabrizi <[email protected]>
  • Loading branch information
TorstenStueber and shawntabrizi committed Jul 18, 2022
1 parent 8016da9 commit 32bc42b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub mod pallet {
Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
let mut bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
match bounty.status {
BountyStatus::Proposed | BountyStatus::Approved | BountyStatus::Funded => {},
BountyStatus::Funded => {},
_ => return Err(Error::<T, I>::UnexpectedStatus.into()),
};

Expand Down
8 changes: 4 additions & 4 deletions frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,8 @@ fn accept_curator_handles_different_deposit_calculations() {
assert_ok!(Bounties::propose_bounty(Origin::signed(0), value, b"12345".to_vec()));
assert_ok!(Bounties::approve_bounty(Origin::root(), bounty_index));

System::set_block_number(3);
<Treasury as OnInitialize<u64>>::on_initialize(3);
System::set_block_number(4);
<Treasury as OnInitialize<u64>>::on_initialize(4);

assert_ok!(Bounties::propose_curator(Origin::root(), bounty_index, user, fee));
assert_ok!(Bounties::accept_curator(Origin::signed(user), bounty_index));
Expand All @@ -1150,8 +1150,8 @@ fn accept_curator_handles_different_deposit_calculations() {
assert_ok!(Bounties::propose_bounty(Origin::signed(0), value, b"12345".to_vec()));
assert_ok!(Bounties::approve_bounty(Origin::root(), bounty_index));

System::set_block_number(3);
<Treasury as OnInitialize<u64>>::on_initialize(3);
System::set_block_number(6);
<Treasury as OnInitialize<u64>>::on_initialize(6);

assert_ok!(Bounties::propose_curator(Origin::root(), bounty_index, user, fee));
assert_ok!(Bounties::accept_curator(Origin::signed(user), bounty_index));
Expand Down
4 changes: 2 additions & 2 deletions frame/child-bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ benchmarks! {
unassign_curator {
setup_pot_account::<T>();
let bounty_setup = activate_child_bounty::<T>(0, T::MaximumReasonLength::get())?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
Treasury::<T>::on_initialize(T::BlockNumber::zero());
frame_system::Pallet::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1u32.into());
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), bounty_setup.bounty_id,
Expand Down Expand Up @@ -295,7 +295,7 @@ benchmarks! {
close_child_bounty_active {
setup_pot_account::<T>();
let bounty_setup = activate_child_bounty::<T>(0, T::MaximumReasonLength::get())?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
Treasury::<T>::on_initialize(T::BlockNumber::zero());
}: close_child_bounty(RawOrigin::Root, bounty_setup.bounty_id, bounty_setup.child_bounty_id)
verify {
assert_last_event::<T>(Event::Canceled {
Expand Down

0 comments on commit 32bc42b

Please sign in to comment.