mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
make pallet-tips & pallet-bounties instantiable (#11473)
* make pallet-tips & pallet-bounties instantiable * update test * add default instance * update * cargo fmt * update * update * update * update * fix merge * fix tests * bounties benchmarking instantiable * fix benchmarks * make tips benchmarks instantible Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
|
||||
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelisted_caller};
|
||||
use frame_support::ensure;
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Saturating;
|
||||
@@ -30,7 +30,7 @@ use crate::Pallet as TipsMod;
|
||||
const SEED: u32 = 0;
|
||||
|
||||
// Create the pre-requisite information needed to create a `report_awesome`.
|
||||
fn setup_awesome<T: Config>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId) {
|
||||
fn setup_awesome<T: Config<I>, I: 'static>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId) {
|
||||
let caller = whitelisted_caller();
|
||||
let value = T::TipReportDepositBase::get() +
|
||||
T::DataDepositPerByte::get() * length.into() +
|
||||
@@ -42,10 +42,10 @@ fn setup_awesome<T: Config>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId
|
||||
}
|
||||
|
||||
// Create the pre-requisite information needed to call `tip_new`.
|
||||
fn setup_tip<T: Config>(
|
||||
fn setup_tip<T: Config<I>, I: 'static>(
|
||||
r: u32,
|
||||
t: u32,
|
||||
) -> Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T>), &'static str> {
|
||||
) -> Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T, I>), &'static str> {
|
||||
let tippers_count = T::Tippers::count();
|
||||
|
||||
for i in 0..t {
|
||||
@@ -64,13 +64,17 @@ fn setup_tip<T: Config>(
|
||||
|
||||
// Create `t` new tips for the tip proposal with `hash`.
|
||||
// This function automatically makes the tip able to close.
|
||||
fn create_tips<T: Config>(t: u32, hash: T::Hash, value: BalanceOf<T>) -> Result<(), &'static str> {
|
||||
fn create_tips<T: Config<I>, I: 'static>(
|
||||
t: u32,
|
||||
hash: T::Hash,
|
||||
value: BalanceOf<T, I>,
|
||||
) -> Result<(), &'static str> {
|
||||
for i in 0..t {
|
||||
let caller = account("member", i, SEED);
|
||||
ensure!(T::Tippers::contains(&caller), "caller is not a tipper");
|
||||
TipsMod::<T>::tip(RawOrigin::Signed(caller).into(), hash, value)?;
|
||||
TipsMod::<T, I>::tip(RawOrigin::Signed(caller).into(), hash, value)?;
|
||||
}
|
||||
Tips::<T>::mutate(hash, |maybe_tip| {
|
||||
Tips::<T, I>::mutate(hash, |maybe_tip| {
|
||||
if let Some(open_tip) = maybe_tip {
|
||||
open_tip.closes = Some(T::BlockNumber::zero());
|
||||
}
|
||||
@@ -78,16 +82,16 @@ fn create_tips<T: Config>(t: u32, hash: T::Hash, value: BalanceOf<T>) -> Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_pot_account<T: Config>() {
|
||||
let pot_account = TipsMod::<T>::account_id();
|
||||
fn setup_pot_account<T: Config<I>, I: 'static>() {
|
||||
let pot_account = TipsMod::<T, I>::account_id();
|
||||
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
|
||||
let _ = T::Currency::make_free_balance_be(&pot_account, value);
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
benchmarks_instance_pallet! {
|
||||
report_awesome {
|
||||
let r in 0 .. T::MaximumReasonLength::get();
|
||||
let (caller, reason, awesome_person) = setup_awesome::<T>(r);
|
||||
let (caller, reason, awesome_person) = setup_awesome::<T, I>(r);
|
||||
// Whitelist caller account from further DB operations.
|
||||
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
|
||||
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
|
||||
@@ -95,8 +99,8 @@ benchmarks! {
|
||||
|
||||
retract_tip {
|
||||
let r = T::MaximumReasonLength::get();
|
||||
let (caller, reason, awesome_person) = setup_awesome::<T>(r);
|
||||
TipsMod::<T>::report_awesome(
|
||||
let (caller, reason, awesome_person) = setup_awesome::<T, I>(r);
|
||||
TipsMod::<T, I>::report_awesome(
|
||||
RawOrigin::Signed(caller.clone()).into(),
|
||||
reason.clone(),
|
||||
awesome_person.clone()
|
||||
@@ -112,7 +116,7 @@ benchmarks! {
|
||||
let r in 0 .. T::MaximumReasonLength::get();
|
||||
let t in 1 .. T::Tippers::max_len() as u32;
|
||||
|
||||
let (caller, reason, beneficiary, value) = setup_tip::<T>(r, t)?;
|
||||
let (caller, reason, beneficiary, value) = setup_tip::<T, I>(r, t)?;
|
||||
// Whitelist caller account from further DB operations.
|
||||
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
|
||||
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
|
||||
@@ -120,9 +124,9 @@ benchmarks! {
|
||||
|
||||
tip {
|
||||
let t in 1 .. T::Tippers::max_len() as u32;
|
||||
let (member, reason, beneficiary, value) = setup_tip::<T>(0, t)?;
|
||||
let (member, reason, beneficiary, value) = setup_tip::<T, I>(0, t)?;
|
||||
let value = T::Currency::minimum_balance().saturating_mul(100u32.into());
|
||||
TipsMod::<T>::tip_new(
|
||||
TipsMod::<T, I>::tip_new(
|
||||
RawOrigin::Signed(member).into(),
|
||||
reason.clone(),
|
||||
beneficiary.clone(),
|
||||
@@ -130,8 +134,8 @@ benchmarks! {
|
||||
)?;
|
||||
let reason_hash = T::Hashing::hash(&reason[..]);
|
||||
let hash = T::Hashing::hash_of(&(&reason_hash, &beneficiary));
|
||||
ensure!(Tips::<T>::contains_key(hash), "tip does not exist");
|
||||
create_tips::<T>(t - 1, hash, value)?;
|
||||
ensure!(Tips::<T, I>::contains_key(hash), "tip does not exist");
|
||||
create_tips::<T, I>(t - 1, hash, value)?;
|
||||
let caller = account("member", t - 1, SEED);
|
||||
// Whitelist caller account from further DB operations.
|
||||
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
|
||||
@@ -142,12 +146,12 @@ benchmarks! {
|
||||
let t in 1 .. T::Tippers::max_len() as u32;
|
||||
|
||||
// Make sure pot is funded
|
||||
setup_pot_account::<T>();
|
||||
setup_pot_account::<T, I>();
|
||||
|
||||
// Set up a new tip proposal
|
||||
let (member, reason, beneficiary, value) = setup_tip::<T>(0, t)?;
|
||||
let (member, reason, beneficiary, value) = setup_tip::<T, I>(0, t)?;
|
||||
let value = T::Currency::minimum_balance().saturating_mul(100u32.into());
|
||||
TipsMod::<T>::tip_new(
|
||||
TipsMod::<T, I>::tip_new(
|
||||
RawOrigin::Signed(member).into(),
|
||||
reason.clone(),
|
||||
beneficiary.clone(),
|
||||
@@ -157,9 +161,9 @@ benchmarks! {
|
||||
// Create a bunch of tips
|
||||
let reason_hash = T::Hashing::hash(&reason[..]);
|
||||
let hash = T::Hashing::hash_of(&(&reason_hash, &beneficiary));
|
||||
ensure!(Tips::<T>::contains_key(hash), "tip does not exist");
|
||||
ensure!(Tips::<T, I>::contains_key(hash), "tip does not exist");
|
||||
|
||||
create_tips::<T>(t, hash, value)?;
|
||||
create_tips::<T, I>(t, hash, value)?;
|
||||
|
||||
let caller = account("caller", t, SEED);
|
||||
// Whitelist caller account from further DB operations.
|
||||
@@ -171,12 +175,12 @@ benchmarks! {
|
||||
let t in 1 .. T::Tippers::max_len() as u32;
|
||||
|
||||
// Make sure pot is funded
|
||||
setup_pot_account::<T>();
|
||||
setup_pot_account::<T, I>();
|
||||
|
||||
// Set up a new tip proposal
|
||||
let (member, reason, beneficiary, value) = setup_tip::<T>(0, t)?;
|
||||
let (member, reason, beneficiary, value) = setup_tip::<T, I>(0, t)?;
|
||||
let value = T::Currency::minimum_balance().saturating_mul(100u32.into());
|
||||
TipsMod::<T>::tip_new(
|
||||
TipsMod::<T, I>::tip_new(
|
||||
RawOrigin::Signed(member).into(),
|
||||
reason.clone(),
|
||||
beneficiary.clone(),
|
||||
@@ -185,7 +189,7 @@ benchmarks! {
|
||||
|
||||
let reason_hash = T::Hashing::hash(&reason[..]);
|
||||
let hash = T::Hashing::hash_of(&(&reason_hash, &beneficiary));
|
||||
ensure!(Tips::<T>::contains_key(hash), "tip does not exist");
|
||||
ensure!(Tips::<T, I>::contains_key(hash), "tip does not exist");
|
||||
}: _(RawOrigin::Root, hash)
|
||||
|
||||
impl_benchmark_test_suite!(TipsMod, crate::tests::new_test_ext(), crate::tests::Test);
|
||||
|
||||
Reference in New Issue
Block a user