Bounties Pallet to FrameV2 (#9566)

* 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>
This commit is contained in:
ferrell-code
2021-09-21 09:07:36 -04:00
committed by GitHub
parent e2dcb4b657
commit eca9af1a0a
7 changed files with 561 additions and 234 deletions
+16 -18
View File
@@ -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;
@@ -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(())
}
@@ -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)?;
@@ -94,7 +93,7 @@ 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 {
@@ -102,7 +101,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());
}: _(RawOrigin::Root, bounty_id, curator_lookup, fee)
@@ -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)
@@ -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)?;
@@ -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));
@@ -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)?;
@@ -164,17 +162,17 @@ 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 {
@@ -182,11 +180,11 @@ 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)?;
}: _(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 {
@@ -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())
}
}