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

Commit

Permalink
Bounties Pallet to FrameV2 (#9566)
Browse files Browse the repository at this point in the history
* migrate bounties pallet

* events in tests

* test import event

* Update frame/bounties/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* cargo fmt

* line width

* benchmarks compile

* add migrations

* fmt

* comments

* mod migrations

* fix Cargo.toml

* never remember cargo fmt

* fix migration

* migrations and test

* change checks in migration

* remove unused values

* Update frame/bounties/src/migrations/v4.rs

* cargo fmt

* fix benchmarking

* trigger ci

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
  • Loading branch information
3 people committed Sep 21, 2021
1 parent ce3c31f commit 78ce061
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 239 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions frame/bounties/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@ sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../pr
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
pallet-treasury = { version = "4.0.0-dev", default-features = false, path = "../treasury" }

sp-io = { version = "4.0.0-dev", path = "../../primitives/io", default-features = false }
sp-core = { version = "4.0.0-dev", path = "../../primitives/core", default-features = false }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
log = { version = "0.4.14", default-features = false }

[dev-dependencies]
sp-io = { version = "4.0.0-dev", path = "../../primitives/io" }
sp-core = { version = "4.0.0-dev", path = "../../primitives/core" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }

[features]
default = ["std"]
std = [
"codec/std",
"sp-core/std",
"sp-io/std",
"scale-info/std",
"sp-std/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"pallet-treasury/std",
"log/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
34 changes: 16 additions & 18 deletions frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
use super::*;

use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::traits::OnInitialize;
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;

use crate::Module as Bounties;
use crate::Pallet as Bounties;
use pallet_treasury::Pallet as Treasury;

const SEED: u32 = 0;
Expand All @@ -36,10 +35,10 @@ fn create_approved_bounties<T: Config>(n: u32) -> Result<(), &'static str> {
for i in 0..n {
let (caller, _curator, _fee, value, reason) = setup_bounty::<T>(i, MAX_BYTES);
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
}
ensure!(BountyApprovals::get().len() == n as usize, "Not all bounty approved");
ensure!(BountyApprovals::<T>::get().len() == n as usize, "Not all bounty approved");
Ok(())
}

Expand All @@ -64,7 +63,7 @@ fn create_bounty<T: Config>(
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Treasury::<T>::on_initialize(T::BlockNumber::zero());
Bounties::<T>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup.clone(), fee)?;
Expand Down Expand Up @@ -94,15 +93,15 @@ benchmarks! {
approve_bounty {
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
}: _(RawOrigin::Root, bounty_id)

propose_curator {
setup_pot_account::<T>();
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
}: _(RawOrigin::Root, bounty_id, curator_lookup, fee)
Expand All @@ -112,7 +111,7 @@ benchmarks! {
setup_pot_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
frame_system::Pallet::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1u32.into());
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), bounty_id)
Expand All @@ -122,7 +121,7 @@ benchmarks! {
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
Bounties::<T>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
Expand All @@ -133,7 +132,7 @@ benchmarks! {
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());

let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;

let beneficiary = T::Lookup::unlookup(account("beneficiary", 0, SEED));
Expand All @@ -144,10 +143,9 @@ benchmarks! {
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());

let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;


let beneficiary_account: T::AccountId = account("beneficiary", 0, SEED);
let beneficiary = T::Lookup::unlookup(beneficiary_account.clone());
Bounties::<T>::award_bounty(RawOrigin::Signed(curator.clone()).into(), bounty_id, beneficiary)?;
Expand All @@ -164,29 +162,29 @@ benchmarks! {
setup_pot_account::<T>();
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, 0);
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
}: close_bounty(RawOrigin::Root, bounty_id)

close_bounty_active {
setup_pot_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
}: close_bounty(RawOrigin::Root, bounty_id)
verify {
assert_last_event::<T>(RawEvent::BountyCanceled(bounty_id).into())
assert_last_event::<T>(Event::BountyCanceled(bounty_id).into())
}

extend_bounty_expiry {
setup_pot_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());

let bounty_id = BountyCount::get() - 1;
let bounty_id = BountyCount::<T>::get() - 1;
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
}: _(RawOrigin::Signed(curator), bounty_id, Vec::new())
verify {
assert_last_event::<T>(RawEvent::BountyExtended(bounty_id).into())
assert_last_event::<T>(Event::BountyExtended(bounty_id).into())
}

spend_funds {
Expand All @@ -209,7 +207,7 @@ benchmarks! {
verify {
ensure!(budget_remaining < BalanceOf::<T>::max_value(), "Budget not used");
ensure!(missed_any == false, "Missed some");
assert_last_event::<T>(RawEvent::BountyBecameActive(b - 1).into())
assert_last_event::<T>(Event::BountyBecameActive(b - 1).into())
}
}

Expand Down
Loading

0 comments on commit 78ce061

Please sign in to comment.