mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Benchmark's successful origin api update (#13146)
* try successful origin unimplemented by default * error as a default impl for try_successful_origin * remove successful_origin func of EnsureOrigin trait * default impl -> unimplemented!() * update EnsureOriginWithArg * fix EnsureOriginWithArg * prefix unused arg with underscore * use try_successful_origin instead successful_origin, map err to Weightless * fix tests * remove default impl * unwrap for indirect origin dep * replace unwrap by expect with a message --------- Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -25,7 +25,7 @@ use sp_std::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet};
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, BenchmarkError};
|
||||
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
|
||||
use frame_system::{Pallet as System, RawOrigin as SystemOrigin};
|
||||
|
||||
@@ -581,7 +581,8 @@ benchmarks_instance_pallet! {
|
||||
let rule = rule(b"hello world");
|
||||
|
||||
let call = Call::<T, I>::set_rule { rule: rule.clone() };
|
||||
let origin = T::AdminOrigin::successful_origin();
|
||||
let origin =
|
||||
T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert_eq!(Alliance::<T, I>::rule(), Some(rule.clone()));
|
||||
@@ -594,7 +595,8 @@ benchmarks_instance_pallet! {
|
||||
let announcement = announcement(b"hello world");
|
||||
|
||||
let call = Call::<T, I>::announce { announcement: announcement.clone() };
|
||||
let origin = T::AnnouncementOrigin::successful_origin();
|
||||
let origin =
|
||||
T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert!(Alliance::<T, I>::announcements().contains(&announcement));
|
||||
@@ -609,7 +611,8 @@ benchmarks_instance_pallet! {
|
||||
Announcements::<T, I>::put(announcements);
|
||||
|
||||
let call = Call::<T, I>::remove_announcement { announcement: announcement.clone() };
|
||||
let origin = T::AnnouncementOrigin::successful_origin();
|
||||
let origin =
|
||||
T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert!(Alliance::<T, I>::announcements().is_empty());
|
||||
@@ -665,7 +668,8 @@ benchmarks_instance_pallet! {
|
||||
|
||||
let ally1_lookup = T::Lookup::unlookup(ally1.clone());
|
||||
let call = Call::<T, I>::elevate_ally { ally: ally1_lookup };
|
||||
let origin = T::MembershipManager::successful_origin();
|
||||
let origin =
|
||||
T::MembershipManager::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert!(!Alliance::<T, I>::is_ally(&ally1));
|
||||
@@ -725,7 +729,8 @@ benchmarks_instance_pallet! {
|
||||
|
||||
let fellow2_lookup = T::Lookup::unlookup(fellow2.clone());
|
||||
let call = Call::<T, I>::kick_member { who: fellow2_lookup };
|
||||
let origin = T::MembershipManager::successful_origin();
|
||||
let origin =
|
||||
T::MembershipManager::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert!(!Alliance::<T, I>::is_member(&fellow2));
|
||||
@@ -754,7 +759,8 @@ benchmarks_instance_pallet! {
|
||||
unscrupulous_list.extend(websites.into_iter().map(UnscrupulousItem::Website));
|
||||
|
||||
let call = Call::<T, I>::add_unscrupulous_items { items: unscrupulous_list.clone() };
|
||||
let origin = T::AnnouncementOrigin::successful_origin();
|
||||
let origin =
|
||||
T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert_last_event::<T, I>(Event::UnscrupulousItemAdded { items: unscrupulous_list }.into());
|
||||
@@ -784,7 +790,8 @@ benchmarks_instance_pallet! {
|
||||
unscrupulous_list.extend(websites.into_iter().map(UnscrupulousItem::Website));
|
||||
|
||||
let call = Call::<T, I>::remove_unscrupulous_items { items: unscrupulous_list.clone() };
|
||||
let origin = T::AnnouncementOrigin::successful_origin();
|
||||
let origin =
|
||||
T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert_last_event::<T, I>(Event::UnscrupulousItemRemoved { items: unscrupulous_list }.into());
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::{
|
||||
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
|
||||
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_support::{
|
||||
dispatch::UnfilteredDispatchable,
|
||||
@@ -135,7 +135,8 @@ fn assert_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::Runti
|
||||
benchmarks_instance_pallet! {
|
||||
create {
|
||||
let asset_id = default_asset_id::<T, I>();
|
||||
let origin = T::CreateOrigin::successful_origin(&asset_id.into());
|
||||
let origin = T::CreateOrigin::try_successful_origin(&asset_id.into())
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let caller = T::CreateOrigin::ensure_origin(origin, &asset_id.into()).unwrap();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
|
||||
@@ -362,7 +363,8 @@ benchmarks_instance_pallet! {
|
||||
|
||||
let (asset_id, _, _) = create_default_asset::<T, I>(true);
|
||||
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::force_set_metadata {
|
||||
id: asset_id,
|
||||
name: name.clone(),
|
||||
@@ -382,7 +384,8 @@ benchmarks_instance_pallet! {
|
||||
let origin = SystemOrigin::Signed(caller).into();
|
||||
Assets::<T, I>::set_metadata(origin, asset_id, dummy.clone(), dummy, 12)?;
|
||||
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::force_clear_metadata { id: asset_id };
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
@@ -392,7 +395,8 @@ benchmarks_instance_pallet! {
|
||||
force_asset_status {
|
||||
let (asset_id, caller, caller_lookup) = create_default_asset::<T, I>(true);
|
||||
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::force_asset_status {
|
||||
id: asset_id,
|
||||
owner: caller_lookup.clone(),
|
||||
|
||||
@@ -173,7 +173,8 @@ benchmarks_instance_pallet! {
|
||||
let (caller, curator, fee, value, reason) = setup_bounty::<T, I>(0, 0);
|
||||
Bounties::<T, I>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
|
||||
let bounty_id = BountyCount::<T, I>::get() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
let approve_origin =
|
||||
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: close_bounty<T::RuntimeOrigin>(approve_origin, bounty_id)
|
||||
|
||||
close_bounty_active {
|
||||
@@ -181,7 +182,8 @@ benchmarks_instance_pallet! {
|
||||
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
|
||||
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
|
||||
let bounty_id = BountyCount::<T, I>::get() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
let approve_origin =
|
||||
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: close_bounty<T::RuntimeOrigin>(approve_origin, bounty_id)
|
||||
verify {
|
||||
assert_last_event::<T, I>(Event::BountyCanceled { index: bounty_id }.into())
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelist_account};
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelist_account, BenchmarkError};
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok,
|
||||
traits::{Currency, EnsureOrigin, Get, OnInitialize, UnfilteredDispatchable},
|
||||
@@ -177,7 +177,8 @@ benchmarks! {
|
||||
}
|
||||
|
||||
emergency_cancel {
|
||||
let origin = T::CancellationOrigin::successful_origin();
|
||||
let origin =
|
||||
T::CancellationOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let ref_index = add_referendum::<T>(0).0;
|
||||
assert_ok!(Democracy::<T>::referendum_status(ref_index));
|
||||
}: _<T::RuntimeOrigin>(origin, ref_index)
|
||||
@@ -200,10 +201,13 @@ benchmarks! {
|
||||
let (ref_index, hash) = add_referendum::<T>(0);
|
||||
assert_ok!(Democracy::<T>::referendum_status(ref_index));
|
||||
// Place our proposal in the external queue, too.
|
||||
assert_ok!(
|
||||
Democracy::<T>::external_propose(T::ExternalOrigin::successful_origin(), make_proposal::<T>(0))
|
||||
);
|
||||
let origin = T::BlacklistOrigin::successful_origin();
|
||||
assert_ok!(Democracy::<T>::external_propose(
|
||||
T::ExternalOrigin::try_successful_origin()
|
||||
.expect("ExternalOrigin has no successful origin required for the benchmark"),
|
||||
make_proposal::<T>(0)
|
||||
));
|
||||
let origin =
|
||||
T::BlacklistOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(origin, hash, Some(ref_index))
|
||||
verify {
|
||||
// Referendum has been canceled
|
||||
@@ -215,7 +219,8 @@ benchmarks! {
|
||||
|
||||
// Worst case scenario, we external propose a previously blacklisted proposal
|
||||
external_propose {
|
||||
let origin = T::ExternalOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ExternalOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let proposal = make_proposal::<T>(0);
|
||||
// Add proposal to blacklist with block number 0
|
||||
|
||||
@@ -233,7 +238,8 @@ benchmarks! {
|
||||
}
|
||||
|
||||
external_propose_majority {
|
||||
let origin = T::ExternalMajorityOrigin::successful_origin();
|
||||
let origin = T::ExternalMajorityOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let proposal = make_proposal::<T>(0);
|
||||
}: _<T::RuntimeOrigin>(origin, proposal)
|
||||
verify {
|
||||
@@ -242,7 +248,8 @@ benchmarks! {
|
||||
}
|
||||
|
||||
external_propose_default {
|
||||
let origin = T::ExternalDefaultOrigin::successful_origin();
|
||||
let origin = T::ExternalDefaultOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let proposal = make_proposal::<T>(0);
|
||||
}: _<T::RuntimeOrigin>(origin, proposal)
|
||||
verify {
|
||||
@@ -251,13 +258,15 @@ benchmarks! {
|
||||
}
|
||||
|
||||
fast_track {
|
||||
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
|
||||
let origin_propose = T::ExternalDefaultOrigin::try_successful_origin()
|
||||
.expect("ExternalDefaultOrigin has no successful origin required for the benchmark");
|
||||
let proposal = make_proposal::<T>(0);
|
||||
let proposal_hash = proposal.hash();
|
||||
Democracy::<T>::external_propose_default(origin_propose, proposal)?;
|
||||
|
||||
// NOTE: Instant origin may invoke a little bit more logic, but may not always succeed.
|
||||
let origin_fast_track = T::FastTrackOrigin::successful_origin();
|
||||
let origin_fast_track =
|
||||
T::FastTrackOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let voting_period = T::FastTrackVotingPeriod::get();
|
||||
let delay = 0u32;
|
||||
}: _<T::RuntimeOrigin>(origin_fast_track, proposal_hash, voting_period, delay.into())
|
||||
@@ -269,7 +278,8 @@ benchmarks! {
|
||||
let proposal = make_proposal::<T>(0);
|
||||
let proposal_hash = proposal.hash();
|
||||
|
||||
let origin_propose = T::ExternalDefaultOrigin::successful_origin();
|
||||
let origin_propose = T::ExternalDefaultOrigin::try_successful_origin()
|
||||
.expect("ExternalDefaultOrigin has no successful origin required for the benchmark");
|
||||
Democracy::<T>::external_propose_default(origin_propose, proposal)?;
|
||||
|
||||
let mut vetoers: BoundedVec<T::AccountId, _> = Default::default();
|
||||
@@ -279,7 +289,7 @@ benchmarks! {
|
||||
vetoers.sort();
|
||||
Blacklist::<T>::insert(proposal_hash, (T::BlockNumber::zero(), vetoers));
|
||||
|
||||
let origin = T::VetoOrigin::successful_origin();
|
||||
let origin = T::VetoOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
ensure!(NextExternal::<T>::get().is_some(), "no external proposal");
|
||||
}: _<T::RuntimeOrigin>(origin, proposal_hash)
|
||||
verify {
|
||||
@@ -293,7 +303,8 @@ benchmarks! {
|
||||
for i in 0 .. T::MaxProposals::get() {
|
||||
add_proposal::<T>(i)?;
|
||||
}
|
||||
let cancel_origin = T::CancelProposalOrigin::successful_origin();
|
||||
let cancel_origin = T::CancelProposalOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(cancel_origin, 0)
|
||||
|
||||
cancel_referendum {
|
||||
@@ -313,7 +324,8 @@ benchmarks! {
|
||||
// Launch external
|
||||
LastTabledWasExternal::<T>::put(false);
|
||||
|
||||
let origin = T::ExternalMajorityOrigin::successful_origin();
|
||||
let origin = T::ExternalMajorityOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let proposal = make_proposal::<T>(r);
|
||||
let call = Call::<T>::external_propose_majority { proposal };
|
||||
call.dispatch_bypass_filter(origin)?;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use crate::{types::*, Pallet as FastUnstake, *};
|
||||
use frame_benchmarking::v1::{benchmarks, whitelist_account};
|
||||
use frame_benchmarking::v1::{benchmarks, whitelist_account, BenchmarkError};
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
traits::{Currency, EnsureOrigin, Get, Hooks},
|
||||
@@ -192,7 +192,8 @@ benchmarks! {
|
||||
}
|
||||
|
||||
control {
|
||||
let origin = <T as Config>::ControlOrigin::successful_origin();
|
||||
let origin = <T as Config>::ControlOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
}
|
||||
: _<T::RuntimeOrigin>(origin, T::MaxErasToCheckPerBlock::get())
|
||||
verify {}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
use super::*;
|
||||
|
||||
use crate::Pallet as Identity;
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
|
||||
use frame_support::{
|
||||
ensure,
|
||||
traits::{EnsureOrigin, Get},
|
||||
@@ -42,7 +42,8 @@ fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> {
|
||||
let registrar: T::AccountId = account("registrar", i, SEED);
|
||||
let registrar_lookup = T::Lookup::unlookup(registrar.clone());
|
||||
let _ = T::Currency::make_free_balance_be(®istrar, BalanceOf::<T>::max_value());
|
||||
let registrar_origin = T::RegistrarOrigin::successful_origin();
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, registrar_lookup)?;
|
||||
Identity::<T>::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?;
|
||||
let fields =
|
||||
@@ -121,7 +122,8 @@ benchmarks! {
|
||||
add_registrar {
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
|
||||
let origin = T::RegistrarOrigin::successful_origin();
|
||||
let origin =
|
||||
T::RegistrarOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));
|
||||
}: _<T::RuntimeOrigin>(origin, account)
|
||||
verify {
|
||||
@@ -280,7 +282,8 @@ benchmarks! {
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::successful_origin();
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), "Fee already set.");
|
||||
@@ -297,7 +300,8 @@ benchmarks! {
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::successful_origin();
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set.");
|
||||
@@ -315,7 +319,8 @@ benchmarks! {
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::successful_origin();
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
let fields = IdentityFields(
|
||||
IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot
|
||||
@@ -347,7 +352,8 @@ benchmarks! {
|
||||
let info_hash = T::Hashing::hash_of(&info);
|
||||
Identity::<T>::set_identity(user_origin.clone(), Box::new(info))?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::successful_origin();
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
Identity::<T>::request_judgement(user_origin, r, 10u32.into())?;
|
||||
}: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable, info_hash)
|
||||
@@ -385,7 +391,8 @@ benchmarks! {
|
||||
)?;
|
||||
}
|
||||
ensure!(IdentityOf::<T>::contains_key(&target), "Identity not set");
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(origin, target_lookup)
|
||||
verify {
|
||||
ensure!(!IdentityOf::<T>::contains_key(&target), "Identity not removed");
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
|
||||
use frame_support::{
|
||||
storage::bounded_vec::BoundedVec,
|
||||
traits::{EnsureOrigin, OnInitialize},
|
||||
@@ -43,7 +43,8 @@ fn setup_lottery<T: Config>(repeat: bool) -> Result<(), &'static str> {
|
||||
];
|
||||
// Last call will be the match for worst case scenario.
|
||||
calls.push(frame_system::Call::<T>::remark { remark: vec![] }.into());
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
let origin = T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark");
|
||||
Lottery::<T>::set_calls(origin.clone(), calls)?;
|
||||
Lottery::<T>::start_lottery(origin, price, length, delay, repeat)?;
|
||||
Ok(())
|
||||
@@ -76,7 +77,8 @@ benchmarks! {
|
||||
set_calls {
|
||||
let n in 0 .. T::MaxCalls::get() as u32;
|
||||
let calls = vec![frame_system::Call::<T>::remark { remark: vec![] }.into(); n as usize];
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
assert!(CallIndices::<T>::get().is_empty());
|
||||
}: _<T::RuntimeOrigin>(origin, calls)
|
||||
verify {
|
||||
@@ -89,7 +91,8 @@ benchmarks! {
|
||||
let price = BalanceOf::<T>::max_value();
|
||||
let end = 10u32.into();
|
||||
let payout = 5u32.into();
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(origin, price, end, payout, true)
|
||||
verify {
|
||||
assert!(crate::Lottery::<T>::get().is_some());
|
||||
@@ -98,7 +101,8 @@ benchmarks! {
|
||||
stop_repeat {
|
||||
setup_lottery::<T>(true)?;
|
||||
assert_eq!(crate::Lottery::<T>::get().unwrap().repeat, true);
|
||||
let origin = T::ManagerOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(origin)
|
||||
verify {
|
||||
assert_eq!(crate::Lottery::<T>::get().unwrap().repeat, false);
|
||||
|
||||
@@ -362,15 +362,17 @@ impl<T: Config<I>, I: 'static> SortedMembers<T::AccountId> for Pallet<T, I> {
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmark {
|
||||
use super::{Pallet as Membership, *};
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelist};
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelist, BenchmarkError};
|
||||
use frame_support::{assert_ok, traits::EnsureOrigin};
|
||||
use frame_system::RawOrigin;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
fn set_members<T: Config<I>, I: 'static>(members: Vec<T::AccountId>, prime: Option<usize>) {
|
||||
let reset_origin = T::ResetOrigin::successful_origin();
|
||||
let prime_origin = T::PrimeOrigin::successful_origin();
|
||||
let reset_origin = T::ResetOrigin::try_successful_origin()
|
||||
.expect("ResetOrigin has no successful origin required for the benchmark");
|
||||
let prime_origin = T::PrimeOrigin::try_successful_origin()
|
||||
.expect("PrimeOrigin has no successful origin required for the benchmark");
|
||||
|
||||
assert_ok!(<Membership<T, I>>::reset_members(reset_origin, members.clone()));
|
||||
if let Some(prime) = prime.map(|i| members[i].clone()) {
|
||||
@@ -390,9 +392,11 @@ mod benchmark {
|
||||
let new_member = account::<T::AccountId>("add", m, SEED);
|
||||
let new_member_lookup = T::Lookup::unlookup(new_member.clone());
|
||||
}: {
|
||||
assert_ok!(<Membership<T, I>>::add_member(T::AddOrigin::successful_origin(), new_member_lookup));
|
||||
}
|
||||
verify {
|
||||
assert_ok!(<Membership<T, I>>::add_member(
|
||||
T::AddOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
new_member_lookup,
|
||||
));
|
||||
} verify {
|
||||
assert!(<Members<T, I>>::get().contains(&new_member));
|
||||
#[cfg(test)] crate::tests::clean();
|
||||
}
|
||||
@@ -408,7 +412,10 @@ mod benchmark {
|
||||
let to_remove = members.first().cloned().unwrap();
|
||||
let to_remove_lookup = T::Lookup::unlookup(to_remove.clone());
|
||||
}: {
|
||||
assert_ok!(<Membership<T, I>>::remove_member(T::RemoveOrigin::successful_origin(), to_remove_lookup));
|
||||
assert_ok!(<Membership<T, I>>::remove_member(
|
||||
T::RemoveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
to_remove_lookup,
|
||||
));
|
||||
} verify {
|
||||
assert!(!<Members<T, I>>::get().contains(&to_remove));
|
||||
// prime is rejigged
|
||||
@@ -428,7 +435,7 @@ mod benchmark {
|
||||
let remove_lookup = T::Lookup::unlookup(remove.clone());
|
||||
}: {
|
||||
assert_ok!(<Membership<T, I>>::swap_member(
|
||||
T::SwapOrigin::successful_origin(),
|
||||
T::SwapOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
remove_lookup,
|
||||
add_lookup,
|
||||
));
|
||||
@@ -448,7 +455,10 @@ mod benchmark {
|
||||
set_members::<T, I>(members.clone(), Some(members.len() - 1));
|
||||
let mut new_members = (m..2*m).map(|i| account("member", i, SEED)).collect::<Vec<T::AccountId>>();
|
||||
}: {
|
||||
assert_ok!(<Membership<T, I>>::reset_members(T::ResetOrigin::successful_origin(), new_members.clone()));
|
||||
assert_ok!(<Membership<T, I>>::reset_members(
|
||||
T::ResetOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
new_members.clone(),
|
||||
));
|
||||
} verify {
|
||||
new_members.sort();
|
||||
assert_eq!(<Members<T, I>>::get(), new_members);
|
||||
@@ -485,7 +495,10 @@ mod benchmark {
|
||||
let prime_lookup = T::Lookup::unlookup(prime.clone());
|
||||
set_members::<T, I>(members, None);
|
||||
}: {
|
||||
assert_ok!(<Membership<T, I>>::set_prime(T::PrimeOrigin::successful_origin(), prime_lookup));
|
||||
assert_ok!(<Membership<T, I>>::set_prime(
|
||||
T::PrimeOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
prime_lookup,
|
||||
));
|
||||
} verify {
|
||||
assert!(<Prime<T, I>>::get().is_some());
|
||||
assert!(<T::MembershipChanged>::get_prime().is_some());
|
||||
@@ -498,7 +511,9 @@ mod benchmark {
|
||||
let prime = members.last().cloned().unwrap();
|
||||
set_members::<T, I>(members, None);
|
||||
}: {
|
||||
assert_ok!(<Membership<T, I>>::clear_prime(T::PrimeOrigin::successful_origin()));
|
||||
assert_ok!(<Membership<T, I>>::clear_prime(
|
||||
T::PrimeOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
));
|
||||
} verify {
|
||||
assert!(<Prime<T, I>>::get().is_none());
|
||||
assert!(<T::MembershipChanged>::get_prime().is_none());
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
use super::*;
|
||||
use enumflags2::{BitFlag, BitFlags};
|
||||
use frame_benchmarking::v1::{
|
||||
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
|
||||
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
@@ -151,7 +151,8 @@ fn default_item_config() -> ItemConfig {
|
||||
benchmarks_instance_pallet! {
|
||||
create {
|
||||
let collection = T::Helper::collection(0);
|
||||
let origin = T::CreateOrigin::successful_origin(&collection);
|
||||
let origin = T::CreateOrigin::try_successful_origin(&collection)
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let caller = T::CreateOrigin::ensure_origin(origin.clone(), &collection).unwrap();
|
||||
whitelist_account!(caller);
|
||||
let admin = T::Lookup::unlookup(caller.clone());
|
||||
@@ -311,7 +312,8 @@ benchmarks_instance_pallet! {
|
||||
|
||||
force_collection_owner {
|
||||
let (collection, _, _) = create_collection::<T, I>();
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance());
|
||||
@@ -326,7 +328,8 @@ benchmarks_instance_pallet! {
|
||||
|
||||
force_collection_config {
|
||||
let (collection, caller, _) = create_collection::<T, I>();
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::force_collection_config {
|
||||
collection,
|
||||
config: make_collection_config::<T, I>(CollectionSetting::DepositRequired.into()),
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
|
||||
use frame_support::traits::{nonfungible::Inspect, Currency, EnsureOrigin, Get};
|
||||
use frame_system::RawOrigin;
|
||||
use sp_arithmetic::Perquintill;
|
||||
@@ -100,7 +100,8 @@ benchmarks! {
|
||||
}
|
||||
|
||||
fund_deficit {
|
||||
let origin = T::FundOrigin::successful_origin();
|
||||
let origin =
|
||||
T::FundOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let bid = T::MinBid::get().max(One::one());
|
||||
T::Currency::make_free_balance_be(&caller, bid);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Preimage pallet benchmarking.
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelist_account};
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelist_account, BenchmarkError};
|
||||
use frame_support::assert_ok;
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Bounded;
|
||||
@@ -62,7 +62,11 @@ benchmarks! {
|
||||
let caller = funded_account::<T>("caller", 0);
|
||||
whitelist_account!(caller);
|
||||
let (preimage, hash) = sized_preimage_and_hash::<T>(s);
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
}: note_preimage(RawOrigin::Signed(caller), preimage)
|
||||
verify {
|
||||
assert!(Preimage::<T>::have_preimage(&hash));
|
||||
@@ -71,9 +75,15 @@ benchmarks! {
|
||||
note_no_deposit_preimage {
|
||||
let s in 0 .. MAX_SIZE;
|
||||
let (preimage, hash) = sized_preimage_and_hash::<T>(s);
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
}: note_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), preimage)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
}: note_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
preimage
|
||||
) verify {
|
||||
assert!(Preimage::<T>::have_preimage(&hash));
|
||||
}
|
||||
|
||||
@@ -90,9 +100,15 @@ benchmarks! {
|
||||
// Cheap unnote - will not unreserve since there's no deposit held.
|
||||
unnote_no_deposit_preimage {
|
||||
let (preimage, hash) = preimage_and_hash::<T>();
|
||||
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
|
||||
}: unnote_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::note_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
preimage,
|
||||
));
|
||||
}: unnote_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
assert!(!Preimage::<T>::have_preimage(&hash));
|
||||
}
|
||||
|
||||
@@ -102,8 +118,10 @@ benchmarks! {
|
||||
let noter = funded_account::<T>("noter", 0);
|
||||
whitelist_account!(noter);
|
||||
assert_ok!(Preimage::<T>::note_preimage(RawOrigin::Signed(noter.clone()).into(), preimage));
|
||||
}: _<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
}: _<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
let deposit = T::BaseDeposit::get() + T::ByteDeposit::get() * MAX_SIZE.into();
|
||||
let s = RequestStatus::Requested { deposit: Some((noter, deposit)), count: 1, len: Some(MAX_SIZE) };
|
||||
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
|
||||
@@ -111,26 +129,40 @@ benchmarks! {
|
||||
// Cheap request - would unreserve the deposit but none was held.
|
||||
request_no_deposit_preimage {
|
||||
let (preimage, hash) = preimage_and_hash::<T>();
|
||||
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
|
||||
}: request_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::note_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
preimage,
|
||||
));
|
||||
}: request_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
let s = RequestStatus::Requested { deposit: None, count: 2, len: Some(MAX_SIZE) };
|
||||
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
|
||||
}
|
||||
// Cheap request - the preimage is not yet noted, so deposit to unreserve.
|
||||
request_unnoted_preimage {
|
||||
let (_, hash) = preimage_and_hash::<T>();
|
||||
}: request_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
}: request_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
let s = RequestStatus::Requested { deposit: None, count: 1, len: None };
|
||||
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
|
||||
}
|
||||
// Cheap request - the preimage is already requested, so just a counter bump.
|
||||
request_requested_preimage {
|
||||
let (_, hash) = preimage_and_hash::<T>();
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
}: request_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
}: request_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
let s = RequestStatus::Requested { deposit: None, count: 2, len: None };
|
||||
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
|
||||
}
|
||||
@@ -138,27 +170,53 @@ benchmarks! {
|
||||
// Expensive unrequest - last reference and it's noted, so will destroy the preimage.
|
||||
unrequest_preimage {
|
||||
let (preimage, hash) = preimage_and_hash::<T>();
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
|
||||
}: _<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
assert_ok!(Preimage::<T>::note_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
preimage,
|
||||
));
|
||||
}: _<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
assert_eq!(StatusFor::<T>::get(&hash), None);
|
||||
}
|
||||
// Cheap unrequest - last reference, but it's not noted.
|
||||
unrequest_unnoted_preimage {
|
||||
let (_, hash) = preimage_and_hash::<T>();
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
}: unrequest_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
}: unrequest_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
assert_eq!(StatusFor::<T>::get(&hash), None);
|
||||
}
|
||||
// Cheap unrequest - not the last reference.
|
||||
unrequest_multi_referenced_preimage {
|
||||
let (_, hash) = preimage_and_hash::<T>();
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
|
||||
}: unrequest_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
|
||||
verify {
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
assert_ok!(Preimage::<T>::request_preimage(
|
||||
T::ManagerOrigin::try_successful_origin()
|
||||
.expect("ManagerOrigin has no successful origin required for the benchmark"),
|
||||
hash,
|
||||
));
|
||||
}: unrequest_preimage<T::RuntimeOrigin>(
|
||||
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
hash
|
||||
) verify {
|
||||
let s = RequestStatus::Requested { deposit: None, count: 1, len: None };
|
||||
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ use super::*;
|
||||
#[allow(unused_imports)]
|
||||
use crate::Pallet as RankedCollective;
|
||||
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
|
||||
use frame_benchmarking::v1::{
|
||||
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_support::{assert_ok, dispatch::UnfilteredDispatchable};
|
||||
use frame_system::RawOrigin as SystemOrigin;
|
||||
|
||||
@@ -35,13 +37,15 @@ fn make_member<T: Config<I>, I: 'static>(rank: Rank) -> T::AccountId {
|
||||
let who = account::<T::AccountId>("member", MemberCount::<T, I>::get(0), SEED);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
assert_ok!(Pallet::<T, I>::add_member(
|
||||
T::PromoteOrigin::successful_origin(),
|
||||
who_lookup.clone()
|
||||
T::PromoteOrigin::try_successful_origin()
|
||||
.expect("PromoteOrigin has no successful origin required for the benchmark"),
|
||||
who_lookup.clone(),
|
||||
));
|
||||
for _ in 0..rank {
|
||||
assert_ok!(Pallet::<T, I>::promote_member(
|
||||
T::PromoteOrigin::successful_origin(),
|
||||
who_lookup.clone()
|
||||
T::PromoteOrigin::try_successful_origin()
|
||||
.expect("PromoteOrigin has no successful origin required for the benchmark"),
|
||||
who_lookup.clone(),
|
||||
));
|
||||
}
|
||||
who
|
||||
@@ -51,7 +55,8 @@ benchmarks_instance_pallet! {
|
||||
add_member {
|
||||
let who = account::<T::AccountId>("member", 0, SEED);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
let origin = T::PromoteOrigin::successful_origin();
|
||||
let origin =
|
||||
T::PromoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::add_member { who: who_lookup };
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
@@ -67,7 +72,8 @@ benchmarks_instance_pallet! {
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
let last = make_member::<T, I>(rank);
|
||||
let last_index = (0..=rank).map(|r| IdToIndex::<T, I>::get(r, &last).unwrap()).collect::<Vec<_>>();
|
||||
let origin = T::DemoteOrigin::successful_origin();
|
||||
let origin =
|
||||
T::DemoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::remove_member { who: who_lookup, min_rank: rank };
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
@@ -83,7 +89,8 @@ benchmarks_instance_pallet! {
|
||||
let rank = r as u16;
|
||||
let who = make_member::<T, I>(rank);
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
let origin = T::PromoteOrigin::successful_origin();
|
||||
let origin =
|
||||
T::PromoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::promote_member { who: who_lookup };
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
@@ -99,7 +106,8 @@ benchmarks_instance_pallet! {
|
||||
let who_lookup = T::Lookup::unlookup(who.clone());
|
||||
let last = make_member::<T, I>(rank);
|
||||
let last_index = IdToIndex::<T, I>::get(rank, &last).unwrap();
|
||||
let origin = T::DemoteOrigin::successful_origin();
|
||||
let origin =
|
||||
T::DemoteOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::demote_member { who: who_lookup };
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
@@ -115,14 +123,19 @@ benchmarks_instance_pallet! {
|
||||
vote {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
assert_ok!(Pallet::<T, I>::add_member(T::PromoteOrigin::successful_origin(), caller_lookup.clone()));
|
||||
assert_ok!(Pallet::<T, I>::add_member(
|
||||
T::PromoteOrigin::try_successful_origin()
|
||||
.expect("PromoteOrigin has no successful origin required for the benchmark"),
|
||||
caller_lookup.clone(),
|
||||
));
|
||||
// Create a poll
|
||||
let class = T::Polls::classes().into_iter().next().unwrap();
|
||||
let rank = T::MinRankOfClass::convert(class.clone());
|
||||
for _ in 0..rank {
|
||||
assert_ok!(Pallet::<T, I>::promote_member(
|
||||
T::PromoteOrigin::successful_origin(),
|
||||
caller_lookup.clone()
|
||||
T::PromoteOrigin::try_successful_origin()
|
||||
.expect("PromoteOrigin has no successful origin required for the benchmark"),
|
||||
caller_lookup.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -259,19 +259,6 @@ impl<T: Config<I>, I: 'static, const MIN_RANK: u16> EnsureOrigin<T::RuntimeOrigi
|
||||
let who = IndexToId::<T, I>::get(MIN_RANK, 0).ok_or(())?;
|
||||
Ok(frame_system::RawOrigin::Signed(who).into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> T::RuntimeOrigin {
|
||||
match Self::try_successful_origin() {
|
||||
Ok(o) => o,
|
||||
Err(()) => {
|
||||
let who: T::AccountId = frame_benchmarking::whitelisted_caller();
|
||||
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), MIN_RANK)
|
||||
.expect("failed to add ranked member");
|
||||
frame_system::RawOrigin::Signed(who).into()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Guard to ensure that the given origin is a member of the collective. The account ID of the
|
||||
@@ -295,19 +282,6 @@ impl<T: Config<I>, I: 'static, const MIN_RANK: u16> EnsureOrigin<T::RuntimeOrigi
|
||||
let who = IndexToId::<T, I>::get(MIN_RANK, 0).ok_or(())?;
|
||||
Ok(frame_system::RawOrigin::Signed(who).into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> T::RuntimeOrigin {
|
||||
match Self::try_successful_origin() {
|
||||
Ok(o) => o,
|
||||
Err(()) => {
|
||||
let who: T::AccountId = frame_benchmarking::whitelisted_caller();
|
||||
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), MIN_RANK)
|
||||
.expect("failed to add ranked member");
|
||||
frame_system::RawOrigin::Signed(who).into()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Guard to ensure that the given origin is a member of the collective. The pair of both the
|
||||
@@ -331,19 +305,6 @@ impl<T: Config<I>, I: 'static, const MIN_RANK: u16> EnsureOrigin<T::RuntimeOrigi
|
||||
let who = IndexToId::<T, I>::get(MIN_RANK, 0).ok_or(())?;
|
||||
Ok(frame_system::RawOrigin::Signed(who).into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> T::RuntimeOrigin {
|
||||
match Self::try_successful_origin() {
|
||||
Ok(o) => o,
|
||||
Err(()) => {
|
||||
let who: T::AccountId = frame_benchmarking::whitelisted_caller();
|
||||
crate::Pallet::<T, I>::do_add_member_to_rank(who.clone(), MIN_RANK)
|
||||
.expect("failed to add ranked member");
|
||||
frame_system::RawOrigin::Signed(who).into()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[frame_support::pallet]
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
use super::*;
|
||||
use crate::Pallet as Referenda;
|
||||
use assert_matches::assert_matches;
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelist_account};
|
||||
use frame_benchmarking::v1::{
|
||||
account, benchmarks_instance_pallet, whitelist_account, BenchmarkError,
|
||||
};
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
dispatch::UnfilteredDispatchable,
|
||||
@@ -48,8 +50,7 @@ fn dummy_call<T: Config<I>, I: 'static>() -> Bounded<<T as Config<I>>::RuntimeCa
|
||||
T::Preimages::bound(call).unwrap()
|
||||
}
|
||||
|
||||
fn create_referendum<T: Config<I>, I: 'static>() -> (T::RuntimeOrigin, ReferendumIndex) {
|
||||
let origin: T::RuntimeOrigin = T::SubmitOrigin::successful_origin();
|
||||
fn create_referendum<T: Config<I>, I: 'static>(origin: T::RuntimeOrigin) -> ReferendumIndex {
|
||||
if let Ok(caller) = frame_system::ensure_signed(origin.clone()) {
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
||||
whitelist_account!(caller);
|
||||
@@ -61,7 +62,7 @@ fn create_referendum<T: Config<I>, I: 'static>() -> (T::RuntimeOrigin, Referendu
|
||||
let call = crate::Call::<T, I>::submit { proposal_origin, proposal, enactment_moment };
|
||||
assert_ok!(call.dispatch_bypass_filter(origin.clone()));
|
||||
let index = ReferendumCount::<T, I>::get() - 1;
|
||||
(origin, index)
|
||||
index
|
||||
}
|
||||
|
||||
fn place_deposit<T: Config<I>, I: 'static>(index: ReferendumIndex) {
|
||||
@@ -75,6 +76,7 @@ fn nudge<T: Config<I>, I: 'static>(index: ReferendumIndex) {
|
||||
}
|
||||
|
||||
fn fill_queue<T: Config<I>, I: 'static>(
|
||||
origin: T::RuntimeOrigin,
|
||||
index: ReferendumIndex,
|
||||
spaces: u32,
|
||||
pass_after: u32,
|
||||
@@ -82,7 +84,7 @@ fn fill_queue<T: Config<I>, I: 'static>(
|
||||
// First, create enough other referendums to fill the track.
|
||||
let mut others = vec![];
|
||||
for _ in 0..info::<T, I>(index).max_deciding {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
others.push(index);
|
||||
}
|
||||
@@ -90,7 +92,7 @@ fn fill_queue<T: Config<I>, I: 'static>(
|
||||
// We will also need enough referenda which are queued and passing, we want `MaxQueued - 1`
|
||||
// in order to force the maximum amount of work to insert ours into the queue.
|
||||
for _ in spaces..T::MaxQueued::get() {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
make_passing_after::<T, I>(index, Perbill::from_percent(pass_after));
|
||||
others.push(index);
|
||||
@@ -194,7 +196,8 @@ fn is_not_confirming<T: Config<I>, I: 'static>(index: ReferendumIndex) -> bool {
|
||||
|
||||
benchmarks_instance_pallet! {
|
||||
submit {
|
||||
let origin: T::RuntimeOrigin = T::SubmitOrigin::successful_origin();
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
if let Ok(caller) = frame_system::ensure_signed(origin.clone()) {
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
|
||||
whitelist_account!(caller);
|
||||
@@ -210,15 +213,19 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
place_decision_deposit_preparing {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
|
||||
verify {
|
||||
assert!(Referenda::<T, I>::ensure_ongoing(index).unwrap().decision_deposit.is_some());
|
||||
}
|
||||
|
||||
place_decision_deposit_queued {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
fill_queue::<T, I>(index, 1, 90);
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
fill_queue::<T, I>(origin.clone(), index, 1, 90);
|
||||
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
|
||||
verify {
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
@@ -227,8 +234,10 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
place_decision_deposit_not_queued {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
fill_queue::<T, I>(index, 0, 90);
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
fill_queue::<T, I>(origin.clone(), index, 0, 90);
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
assert_eq!(TrackQueue::<T, I>::get(&track).len() as u32, T::MaxQueued::get());
|
||||
assert!(TrackQueue::<T, I>::get(&track).into_iter().all(|(i, _)| i != index));
|
||||
@@ -239,7 +248,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
place_decision_deposit_passing {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
skip_prepare_period::<T, I>(index);
|
||||
make_passing::<T, I>(index);
|
||||
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
|
||||
@@ -248,7 +259,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
place_decision_deposit_failing {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
skip_prepare_period::<T, I>(index);
|
||||
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
|
||||
verify {
|
||||
@@ -256,19 +269,31 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
refund_decision_deposit {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
assert_ok!(Referenda::<T, I>::cancel(T::CancelOrigin::successful_origin(), index));
|
||||
assert_ok!(Referenda::<T, I>::cancel(
|
||||
T::CancelOrigin::try_successful_origin()
|
||||
.expect("CancelOrigin has no successful origin required for the benchmark"),
|
||||
index,
|
||||
));
|
||||
}: _<T::RuntimeOrigin>(origin, index)
|
||||
verify {
|
||||
assert_matches!(ReferendumInfoFor::<T, I>::get(index), Some(ReferendumInfo::Cancelled(_, _, None)));
|
||||
}
|
||||
|
||||
refund_submission_deposit {
|
||||
let (origin, index) = create_referendum::<T, I>();
|
||||
let origin =
|
||||
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
let caller = frame_system::ensure_signed(origin.clone()).unwrap();
|
||||
let balance = T::Currency::free_balance(&caller);
|
||||
assert_ok!(Referenda::<T, I>::cancel(T::CancelOrigin::successful_origin(), index));
|
||||
assert_ok!(Referenda::<T, I>::cancel(
|
||||
T::CancelOrigin::try_successful_origin()
|
||||
.expect("CancelOrigin has no successful origin required for the benchmark"),
|
||||
index,
|
||||
));
|
||||
assert_matches!(ReferendumInfoFor::<T, I>::get(index), Some(ReferendumInfo::Cancelled(_, Some(_), _)));
|
||||
}: _<T::RuntimeOrigin>(origin, index)
|
||||
verify {
|
||||
@@ -279,28 +304,42 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
cancel {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
}: _<T::RuntimeOrigin>(T::CancelOrigin::successful_origin(), index)
|
||||
verify {
|
||||
}: _<T::RuntimeOrigin>(
|
||||
T::CancelOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
index
|
||||
) verify {
|
||||
assert_matches!(ReferendumInfoFor::<T, I>::get(index), Some(ReferendumInfo::Cancelled(..)));
|
||||
}
|
||||
|
||||
kill {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
}: _<T::RuntimeOrigin>(T::KillOrigin::successful_origin(), index)
|
||||
verify {
|
||||
}: _<T::RuntimeOrigin>(
|
||||
T::KillOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
|
||||
index
|
||||
) verify {
|
||||
assert_matches!(ReferendumInfoFor::<T, I>::get(index), Some(ReferendumInfo::Killed(..)));
|
||||
}
|
||||
|
||||
one_fewer_deciding_queue_empty {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
nudge::<T, I>(index);
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
assert_ok!(Referenda::<T, I>::cancel(T::CancelOrigin::successful_origin(), index));
|
||||
assert_ok!(Referenda::<T, I>::cancel(
|
||||
T::CancelOrigin::try_successful_origin()
|
||||
.expect("CancelOrigin has no successful origin required for the benchmark"),
|
||||
index,
|
||||
));
|
||||
assert_eq!(DecidingCount::<T, I>::get(&track), 1);
|
||||
}: one_fewer_deciding(RawOrigin::Root, track)
|
||||
verify {
|
||||
@@ -308,11 +347,17 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
one_fewer_deciding_failing {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
// No spaces free in the queue.
|
||||
let queued = fill_queue::<T, I>(index, 0, 90);
|
||||
let queued = fill_queue::<T, I>(origin, index, 0, 90);
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
assert_ok!(Referenda::<T, I>::cancel(T::CancelOrigin::successful_origin(), queued[0]));
|
||||
assert_ok!(Referenda::<T, I>::cancel(
|
||||
T::CancelOrigin::try_successful_origin()
|
||||
.expect("CancelOrigin has no successful origin required for the benchmark"),
|
||||
queued[0],
|
||||
));
|
||||
assert_eq!(TrackQueue::<T, I>::get(&track).len() as u32, T::MaxQueued::get());
|
||||
let deciding_count = DecidingCount::<T, I>::get(&track);
|
||||
}: one_fewer_deciding(RawOrigin::Root, track)
|
||||
@@ -327,11 +372,17 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
one_fewer_deciding_passing {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
// No spaces free in the queue.
|
||||
let queued = fill_queue::<T, I>(index, 0, 0);
|
||||
let queued = fill_queue::<T, I>(origin, index, 0, 0);
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
assert_ok!(Referenda::<T, I>::cancel(T::CancelOrigin::successful_origin(), queued[0]));
|
||||
assert_ok!(Referenda::<T, I>::cancel(
|
||||
T::CancelOrigin::try_successful_origin()
|
||||
.expect("CancelOrigin has no successful origin required for the benchmark"),
|
||||
queued[0],
|
||||
));
|
||||
assert_eq!(TrackQueue::<T, I>::get(&track).len() as u32, T::MaxQueued::get());
|
||||
let deciding_count = DecidingCount::<T, I>::get(&track);
|
||||
}: one_fewer_deciding(RawOrigin::Root, track)
|
||||
@@ -346,10 +397,12 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_requeued_insertion {
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
// First create our referendum and place the deposit. It will be failing.
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
fill_queue::<T, I>(index, 0, 90);
|
||||
fill_queue::<T, I>(origin, index, 0, 90);
|
||||
|
||||
// Now nudge ours, with the track now full and the queue full of referenda with votes,
|
||||
// ours will not be in the queue.
|
||||
@@ -367,10 +420,12 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_requeued_slide {
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
// First create our referendum and place the deposit. It will be failing.
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
fill_queue::<T, I>(index, 1, 90);
|
||||
fill_queue::<T, I>(origin, index, 1, 90);
|
||||
|
||||
// Now nudge ours, with the track now full, ours will be queued, but with no votes, it
|
||||
// will have the worst position.
|
||||
@@ -393,10 +448,12 @@ benchmarks_instance_pallet! {
|
||||
// free and this failing. It would result in `QUEUE_SIZE - 1` items being shifted for the
|
||||
// insertion at the beginning.
|
||||
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
// First create our referendum and place the deposit. It will be failing.
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
fill_queue::<T, I>(index, 1, 0);
|
||||
fill_queue::<T, I>(origin, index, 1, 0);
|
||||
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
assert_eq!(TrackQueue::<T, I>::get(&track).len() as u32, T::MaxQueued::get() - 1);
|
||||
@@ -410,10 +467,12 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_not_queued {
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
// First create our referendum and place the deposit. It will be failing.
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let index = create_referendum::<T, I>(origin.clone());
|
||||
place_deposit::<T, I>(index);
|
||||
fill_queue::<T, I>(index, 0, 0);
|
||||
fill_queue::<T, I>(origin, index, 0, 0);
|
||||
|
||||
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
|
||||
assert_eq!(TrackQueue::<T, I>::get(&track).len() as u32, T::MaxQueued::get());
|
||||
@@ -427,7 +486,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_no_deposit {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
}: nudge_referendum(RawOrigin::Root, index)
|
||||
verify {
|
||||
@@ -436,7 +497,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_preparing {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
}: nudge_referendum(RawOrigin::Root, index)
|
||||
verify {
|
||||
@@ -445,7 +508,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_timed_out {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
skip_timeout_period::<T, I>(index);
|
||||
}: nudge_referendum(RawOrigin::Root, index)
|
||||
verify {
|
||||
@@ -454,7 +519,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_begin_deciding_failing {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
}: nudge_referendum(RawOrigin::Root, index)
|
||||
@@ -463,7 +530,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_begin_deciding_passing {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
make_passing::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
@@ -473,7 +542,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_begin_confirming {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
nudge::<T, I>(index);
|
||||
@@ -485,7 +556,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_end_confirming {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
make_passing::<T, I>(index);
|
||||
@@ -498,7 +571,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_continue_not_confirming {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
nudge::<T, I>(index);
|
||||
@@ -512,7 +587,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_continue_confirming {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
make_passing::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
@@ -525,7 +602,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_approved {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
make_passing::<T, I>(index);
|
||||
@@ -538,7 +617,9 @@ benchmarks_instance_pallet! {
|
||||
}
|
||||
|
||||
nudge_referendum_rejected {
|
||||
let (_origin, index) = create_referendum::<T, I>();
|
||||
let origin = T::SubmitOrigin::try_successful_origin()
|
||||
.expect("SubmitOrigin has no successful origin required for the benchmark");
|
||||
let index = create_referendum::<T, I>(origin);
|
||||
place_deposit::<T, I>(index);
|
||||
skip_prepare_period::<T, I>(index);
|
||||
make_failing::<T, I>(index);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Scheduler pallet benchmarking.
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::{account, benchmarks};
|
||||
use frame_benchmarking::v1::{account, benchmarks, BenchmarkError};
|
||||
use frame_support::{
|
||||
ensure,
|
||||
traits::{schedule::Priority, BoundedInline},
|
||||
@@ -244,7 +244,8 @@ benchmarks! {
|
||||
|
||||
fill_schedule::<T>(when, s)?;
|
||||
assert_eq!(Agenda::<T>::get(when).len(), s as usize);
|
||||
let schedule_origin = T::ScheduleOrigin::successful_origin();
|
||||
let schedule_origin =
|
||||
T::ScheduleOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<SystemOrigin<T>>(schedule_origin, when, 0)
|
||||
verify {
|
||||
ensure!(
|
||||
|
||||
@@ -40,25 +40,12 @@ pub trait EnsureOrigin<OuterOrigin> {
|
||||
/// Perform the origin check.
|
||||
fn try_origin(o: OuterOrigin) -> Result<Self::Success, OuterOrigin>;
|
||||
|
||||
/// Returns an outer origin capable of passing `try_origin` check.
|
||||
///
|
||||
/// NOTE: This should generally *NOT* be reimplemented. Instead implement
|
||||
/// `try_successful_origin`.
|
||||
/// Attempt to get an outer origin capable of passing `try_origin` check. May return `Err` if it
|
||||
/// is impossible.
|
||||
///
|
||||
/// ** Should be used for benchmarking only!!! **
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> OuterOrigin {
|
||||
Self::try_successful_origin().expect("No origin exists which can satisfy the guard")
|
||||
}
|
||||
|
||||
/// Attept to get an outer origin capable of passing `try_origin` check. May return `Err` if it
|
||||
/// is impossible. Default implementation just uses `successful_origin()`.
|
||||
///
|
||||
/// ** Should be used for benchmarking only!!! **
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin() -> Result<OuterOrigin, ()> {
|
||||
Ok(Self::successful_origin())
|
||||
}
|
||||
fn try_successful_origin() -> Result<OuterOrigin, ()>;
|
||||
}
|
||||
|
||||
/// [`EnsureOrigin`] implementation that always fails.
|
||||
@@ -171,25 +158,12 @@ pub trait EnsureOriginWithArg<OuterOrigin, Argument> {
|
||||
/// Perform the origin check, returning the origin value if unsuccessful. This allows chaining.
|
||||
fn try_origin(o: OuterOrigin, a: &Argument) -> Result<Self::Success, OuterOrigin>;
|
||||
|
||||
/// Returns an outer origin capable of passing `try_origin` check.
|
||||
///
|
||||
/// NOTE: This should generally *NOT* be reimplemented. Instead implement
|
||||
/// `try_successful_origin`.
|
||||
/// Attempt to get an outer origin capable of passing `try_origin` check. May return `Err` if it
|
||||
/// is impossible.
|
||||
///
|
||||
/// ** Should be used for benchmarking only!!! **
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin(a: &Argument) -> OuterOrigin {
|
||||
Self::try_successful_origin(a).expect("No origin exists which can satisfy the guard")
|
||||
}
|
||||
|
||||
/// Attept to get an outer origin capable of passing `try_origin` check. May return `Err` if it
|
||||
/// is impossible. Default implementation just uses `successful_origin()`.
|
||||
///
|
||||
/// ** Should be used for benchmarking only!!! **
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin(a: &Argument) -> Result<OuterOrigin, ()> {
|
||||
Ok(Self::successful_origin(a))
|
||||
}
|
||||
fn try_successful_origin(a: &Argument) -> Result<OuterOrigin, ()>;
|
||||
}
|
||||
|
||||
pub struct AsEnsureOriginWithArg<EO>(sp_std::marker::PhantomData<EO>);
|
||||
|
||||
@@ -679,10 +679,13 @@ fn ensure_signed_stuff_works() {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
{
|
||||
let successful_origin: RuntimeOrigin = EnsureSigned::successful_origin();
|
||||
let successful_origin: RuntimeOrigin = EnsureSigned::try_successful_origin()
|
||||
.expect("EnsureSigned has no successful origin required for the test");
|
||||
assert_ok!(EnsureSigned::try_origin(successful_origin));
|
||||
|
||||
let successful_origin: RuntimeOrigin = EnsureSignedBy::<Members, _>::successful_origin();
|
||||
let successful_origin: RuntimeOrigin =
|
||||
EnsureSignedBy::<Members, _>::try_successful_origin()
|
||||
.expect("EnsureSignedBy has no successful origin required for the test");
|
||||
assert_ok!(EnsureSignedBy::<Members, _>::try_origin(successful_origin));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
|
||||
use frame_benchmarking::v1::{
|
||||
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_support::ensure;
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Saturating;
|
||||
@@ -196,7 +198,8 @@ benchmarks_instance_pallet! {
|
||||
let reason_hash = T::Hashing::hash(&reason[..]);
|
||||
let hash = T::Hashing::hash_of(&(&reason_hash, &beneficiary));
|
||||
ensure!(Tips::<T, I>::contains_key(hash), "tip does not exist");
|
||||
let reject_origin = T::RejectOrigin::successful_origin();
|
||||
let reject_origin =
|
||||
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(reject_origin, hash)
|
||||
|
||||
impl_benchmark_test_suite!(TipsMod, crate::tests::new_test_ext(), crate::tests::Test);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
use super::{Pallet as Treasury, *};
|
||||
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet};
|
||||
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, BenchmarkError};
|
||||
use frame_support::{
|
||||
dispatch::UnfilteredDispatchable,
|
||||
ensure,
|
||||
@@ -99,7 +99,8 @@ benchmarks_instance_pallet! {
|
||||
beneficiary_lookup
|
||||
)?;
|
||||
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
|
||||
let reject_origin = T::RejectOrigin::successful_origin();
|
||||
let reject_origin =
|
||||
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(reject_origin, proposal_id)
|
||||
|
||||
approve_proposal {
|
||||
@@ -112,7 +113,8 @@ benchmarks_instance_pallet! {
|
||||
beneficiary_lookup
|
||||
)?;
|
||||
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
let approve_origin =
|
||||
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(approve_origin, proposal_id)
|
||||
|
||||
remove_approval {
|
||||
@@ -124,7 +126,8 @@ benchmarks_instance_pallet! {
|
||||
)?;
|
||||
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
|
||||
Treasury::<T, I>::approve_proposal(RawOrigin::Root.into(), proposal_id)?;
|
||||
let reject_origin = T::RejectOrigin::successful_origin();
|
||||
let reject_origin =
|
||||
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(reject_origin, proposal_id)
|
||||
|
||||
on_initialize_proposals {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::{
|
||||
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
|
||||
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_support::{
|
||||
dispatch::UnfilteredDispatchable,
|
||||
@@ -137,7 +137,8 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
|
||||
benchmarks_instance_pallet! {
|
||||
create {
|
||||
let collection = T::Helper::collection(0);
|
||||
let origin = T::CreateOrigin::successful_origin(&collection);
|
||||
let origin = T::CreateOrigin::try_successful_origin(&collection)
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let caller = T::CreateOrigin::ensure_origin(origin.clone(), &collection).unwrap();
|
||||
whitelist_account!(caller);
|
||||
let admin = T::Lookup::unlookup(caller.clone());
|
||||
@@ -290,7 +291,8 @@ benchmarks_instance_pallet! {
|
||||
|
||||
force_item_status {
|
||||
let (collection, caller, caller_lookup) = create_collection::<T, I>();
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call = Call::<T, I>::force_item_status {
|
||||
collection,
|
||||
owner: caller_lookup.clone(),
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::benchmarks;
|
||||
use frame_benchmarking::v1::{benchmarks, BenchmarkError};
|
||||
use frame_support::{ensure, traits::EnsureOrigin};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -28,7 +28,8 @@ use crate::Pallet as Whitelist;
|
||||
|
||||
benchmarks! {
|
||||
whitelist_call {
|
||||
let origin = T::WhitelistOrigin::successful_origin();
|
||||
let origin =
|
||||
T::WhitelistOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call_hash = Default::default();
|
||||
}: _<T::RuntimeOrigin>(origin, call_hash)
|
||||
verify {
|
||||
@@ -43,7 +44,8 @@ benchmarks! {
|
||||
}
|
||||
|
||||
remove_whitelisted_call {
|
||||
let origin = T::WhitelistOrigin::successful_origin();
|
||||
let origin =
|
||||
T::WhitelistOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call_hash = Default::default();
|
||||
Pallet::<T>::whitelist_call(origin.clone(), call_hash)
|
||||
.expect("whitelisting call must be successful");
|
||||
@@ -70,7 +72,8 @@ benchmarks! {
|
||||
// NOTE: we remove `10` because we need some bytes to encode the variants and vec length
|
||||
let n in 1 .. T::Preimages::MAX_LENGTH as u32 - 10;
|
||||
|
||||
let origin = T::DispatchWhitelistedOrigin::successful_origin();
|
||||
let origin = T::DispatchWhitelistedOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let remark = sp_std::vec![1u8; n as usize];
|
||||
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark }.into();
|
||||
let call_weight = call.get_dispatch_info().weight;
|
||||
@@ -98,7 +101,8 @@ benchmarks! {
|
||||
dispatch_whitelisted_call_with_preimage {
|
||||
let n in 1 .. 10_000;
|
||||
|
||||
let origin = T::DispatchWhitelistedOrigin::successful_origin();
|
||||
let origin = T::DispatchWhitelistedOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let remark = sp_std::vec![1u8; n as usize];
|
||||
|
||||
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark }.into();
|
||||
|
||||
Reference in New Issue
Block a user