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

Commit

Permalink
Update benchmark's successful origin api (#6598)
Browse files Browse the repository at this point in the history
* Update benchmark's successful origin api

* rustfmt

* unwrap for indirect origin dep

* replace unwrap by expect with a message

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
muharem authored Jan 29, 2023
1 parent 6cde7fa commit f0e1ed0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
14 changes: 9 additions & 5 deletions runtime/common/src/auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ mod benchmarking {
use frame_system::RawOrigin;
use sp_runtime::{traits::Bounded, SaturatedConversion};

use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError};

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
Expand Down Expand Up @@ -1786,7 +1786,8 @@ mod benchmarking {
new_auction {
let duration = T::BlockNumber::max_value();
let lease_period_index = LeasePeriodOf::<T>::max_value();
let origin = T::InitiateOrigin::successful_origin();
let origin =
T::InitiateOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: _<T::RuntimeOrigin>(origin, duration, lease_period_index)
verify {
assert_last_event::<T>(Event::<T>::AuctionStarted {
Expand All @@ -1805,7 +1806,8 @@ mod benchmarking {
// Create a new auction
let duration = T::BlockNumber::max_value();
let lease_period_index = LeasePeriodOf::<T>::zero();
let origin = T::InitiateOrigin::successful_origin();
let origin = T::InitiateOrigin::try_successful_origin()
.expect("InitiateOrigin has no successful origin required for the benchmark");
Auctions::<T>::new_auction(origin, duration, lease_period_index)?;

let para = ParaId::from(0);
Expand Down Expand Up @@ -1857,7 +1859,8 @@ mod benchmarking {
let duration: T::BlockNumber = lease_length / 2u32.into();
let lease_period_index = LeasePeriodOf::<T>::zero();
let now = frame_system::Pallet::<T>::block_number();
let origin = T::InitiateOrigin::successful_origin();
let origin = T::InitiateOrigin::try_successful_origin()
.expect("InitiateOrigin has no successful origin required for the benchmark");
Auctions::<T>::new_auction(origin, duration, lease_period_index)?;

fill_winners::<T>(lease_period_index);
Expand Down Expand Up @@ -1901,7 +1904,8 @@ mod benchmarking {
let duration: T::BlockNumber = lease_length / 2u32.into();
let lease_period_index = LeasePeriodOf::<T>::zero();
let now = frame_system::Pallet::<T>::block_number();
let origin = T::InitiateOrigin::successful_origin();
let origin = T::InitiateOrigin::try_successful_origin()
.expect("InitiateOrigin has no successful origin required for the benchmark");
Auctions::<T>::new_auction(origin, duration, lease_period_index)?;

fill_winners::<T>(lease_period_index);
Expand Down
14 changes: 9 additions & 5 deletions runtime/common/src/slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ mod benchmarking {
use frame_system::RawOrigin;
use sp_runtime::traits::{Bounded, One};

use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError};

use crate::slots::Pallet as Slots;

Expand Down Expand Up @@ -1027,7 +1027,8 @@ mod benchmarking {
let amount = T::Currency::minimum_balance();
let period_begin = 69u32.into();
let period_count = 3u32.into();
let origin = T::ForceOrigin::successful_origin();
let origin =
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: _<T::RuntimeOrigin>(origin, para, leaser.clone(), amount, period_begin, period_count)
verify {
assert_last_event::<T>(Event::<T>::Leased {
Expand Down Expand Up @@ -1061,7 +1062,8 @@ mod benchmarking {
// T parathread are upgrading to parachains
for (para, leaser) in paras_info {
let amount = T::Currency::minimum_balance();
let origin = T::ForceOrigin::successful_origin();
let origin = T::ForceOrigin::try_successful_origin()
.expect("ForceOrigin has no successful origin required for the benchmark");
Slots::<T>::force_lease(origin, para, leaser, amount, period_begin, period_count)?;
}

Expand Down Expand Up @@ -1112,7 +1114,8 @@ mod benchmarking {
// Average slot has 4 lease periods.
let period_count: LeasePeriodOf<T> = 4u32.into();
let period_begin = period_count * i.into();
let origin = T::ForceOrigin::successful_origin();
let origin = T::ForceOrigin::try_successful_origin()
.expect("ForceOrigin has no successful origin required for the benchmark");
Slots::<T>::force_lease(origin, para, leaser, amount, period_begin, period_count)?;
}

Expand All @@ -1121,7 +1124,8 @@ mod benchmarking {
assert_eq!(T::Currency::reserved_balance(&leaser), T::Currency::minimum_balance());
}

let origin = T::ForceOrigin::successful_origin();
let origin =
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: _<T::RuntimeOrigin>(origin, para)
verify {
for i in 0 .. max_people {
Expand Down
12 changes: 8 additions & 4 deletions xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type RuntimeOrigin<T> = <T as frame_system::Config>::RuntimeOrigin;

benchmarks! {
send {
let send_origin = T::SendXcmOrigin::successful_origin();
let send_origin =
T::SendXcmOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
if T::SendXcmOrigin::try_origin(send_origin.clone()).is_err() {
return Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))
}
Expand All @@ -40,7 +41,8 @@ benchmarks! {

teleport_assets {
let asset: MultiAsset = (Here, 10).into();
let send_origin = T::ExecuteXcmOrigin::successful_origin();
let send_origin =
T::ExecuteXcmOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let origin_location = T::ExecuteXcmOrigin::try_origin(send_origin.clone())
.map_err(|_| BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?;
if !T::XcmTeleportFilter::contains(&(origin_location, vec![asset.clone()])) {
Expand All @@ -59,7 +61,8 @@ benchmarks! {

reserve_transfer_assets {
let asset: MultiAsset = (Here, 10).into();
let send_origin = T::ExecuteXcmOrigin::successful_origin();
let send_origin =
T::ExecuteXcmOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let origin_location = T::ExecuteXcmOrigin::try_origin(send_origin.clone())
.map_err(|_| BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?;
if !T::XcmReserveTransferFilter::contains(&(origin_location, vec![asset.clone()])) {
Expand All @@ -77,7 +80,8 @@ benchmarks! {
}: _<RuntimeOrigin<T>>(send_origin, Box::new(versioned_dest), Box::new(versioned_beneficiary), Box::new(versioned_assets), 0)

execute {
let execute_origin = T::ExecuteXcmOrigin::successful_origin();
let execute_origin =
T::ExecuteXcmOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let origin_location = T::ExecuteXcmOrigin::try_origin(execute_origin.clone())
.map_err(|_| BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?;
let msg = Xcm(vec![ClearOrigin]);
Expand Down

0 comments on commit f0e1ed0

Please sign in to comment.