mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
Tips Benchmarking to be Runtime Agnostic (#10368)
* use config traits instead of constants * bounties too * do bounties too * update docs
This commit is contained in:
@@ -33,7 +33,8 @@ const SEED: u32 = 0;
|
||||
// Create bounties that are approved for use in `on_initialize`.
|
||||
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);
|
||||
let (caller, _curator, _fee, value, reason) =
|
||||
setup_bounty::<T>(i, T::MaximumReasonLength::get());
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T>::get() - 1;
|
||||
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
|
||||
@@ -50,7 +51,8 @@ fn setup_bounty<T: Config>(
|
||||
let caller = account("caller", u, SEED);
|
||||
let value: BalanceOf<T> = T::BountyValueMinimum::get().saturating_mul(100u32.into());
|
||||
let fee = value / 2u32.into();
|
||||
let deposit = T::BountyDepositBase::get() + T::DataDepositPerByte::get() * MAX_BYTES.into();
|
||||
let deposit = T::BountyDepositBase::get() +
|
||||
T::DataDepositPerByte::get() * T::MaximumReasonLength::get().into();
|
||||
let _ = T::Currency::make_free_balance_be(&caller, deposit);
|
||||
let curator = account("curator", u, SEED);
|
||||
let _ = T::Currency::make_free_balance_be(&curator, fee / 2u32.into());
|
||||
@@ -60,7 +62,7 @@ fn setup_bounty<T: Config>(
|
||||
|
||||
fn create_bounty<T: Config>(
|
||||
) -> Result<(<T::Lookup as StaticLookup>::Source, BountyIndex), &'static str> {
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, T::MaximumReasonLength::get());
|
||||
let curator_lookup = T::Lookup::unlookup(curator.clone());
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T>::get() - 1;
|
||||
@@ -81,24 +83,22 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
|
||||
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
|
||||
}
|
||||
|
||||
const MAX_BYTES: u32 = 16384;
|
||||
|
||||
benchmarks! {
|
||||
propose_bounty {
|
||||
let d in 0 .. MAX_BYTES;
|
||||
let d in 0 .. T::MaximumReasonLength::get();
|
||||
|
||||
let (caller, curator, fee, value, description) = setup_bounty::<T>(0, d);
|
||||
}: _(RawOrigin::Signed(caller), value, description)
|
||||
|
||||
approve_bounty {
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, T::MaximumReasonLength::get());
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
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 (caller, curator, fee, value, reason) = setup_bounty::<T>(0, T::MaximumReasonLength::get());
|
||||
let curator_lookup = T::Lookup::unlookup(curator.clone());
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T>::get() - 1;
|
||||
@@ -118,7 +118,7 @@ benchmarks! {
|
||||
|
||||
accept_curator {
|
||||
setup_pot_account::<T>();
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, T::MaximumReasonLength::get());
|
||||
let curator_lookup = T::Lookup::unlookup(curator.clone());
|
||||
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T>::get() - 1;
|
||||
|
||||
@@ -195,6 +195,8 @@ pub mod pallet {
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// Maximum acceptable reason length.
|
||||
///
|
||||
/// Benchmarks depend on this value, be sure to update weights file when changing this value
|
||||
#[pallet::constant]
|
||||
type MaximumReasonLength: Get<u32>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user