From 53ad646c9e3db564f8999eaa0d69bdf6a2ca5613 Mon Sep 17 00:00:00 2001 From: Gautham Date: Tue, 7 Nov 2023 20:47:25 +0530 Subject: [PATCH] Fix benchmarkign --- pallets/ocex/src/benchmarking.rs | 37 ++++++++--------------- pallets/thea-executor/src/benchmarking.rs | 2 +- pallets/thea-executor/src/lib.rs | 7 ++++- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/pallets/ocex/src/benchmarking.rs b/pallets/ocex/src/benchmarking.rs index 13e743b95..90ae13846 100644 --- a/pallets/ocex/src/benchmarking.rs +++ b/pallets/ocex/src/benchmarking.rs @@ -21,7 +21,10 @@ use super::*; use crate::Pallet as Ocex; -use frame_benchmarking::v1::{account, benchmarks}; +use frame_benchmarking::{ + v1::{account, benchmarks}, + whitelisted_caller, +}; use frame_support::{ traits::{EnsureOrigin, UnfilteredDispatchable}, BoundedVec, @@ -68,20 +71,11 @@ fn tpc(base_asset: AssetId, quote_asset: AssetId) -> TradingPairConfig { benchmarks! { register_main_account { - let b in 0 .. 50_000; - let origin = T::EnclaveOrigin::try_successful_origin().unwrap(); - let account = T::EnclaveOrigin::try_successful_origin().unwrap(); - let main: T::AccountId = match unsafe { origin.clone().into().unwrap_unchecked() } { - RawOrigin::Signed(account) => account.into(), - _ => panic!("wrong RawOrigin returned") - }; - let proxy: T::AccountId = match unsafe { account.into().unwrap_unchecked() } { - RawOrigin::Signed(account) => account.into(), - _ => panic!("wrong RawOrigin returned") - }; + let b in 0 .. 255; + let main: T::AccountId = whitelisted_caller(); + let proxy = T::AccountId::decode(&mut &[b as u8; 32].to_vec()[..]).unwrap(); >::put(true); - let call = Call::::register_main_account { proxy: proxy.clone() }; - }: { call.dispatch_bypass_filter(origin)? } + }: _(RawOrigin::Signed(main.clone()), proxy.clone()) verify { assert_last_event::(Event::MainAccountRegistered { main, @@ -91,18 +85,13 @@ benchmarks! { add_proxy_account { let x in 0 .. 255; // should not overflow u8 - let origin = T::EnclaveOrigin::try_successful_origin().unwrap(); - let main: T::AccountId = match unsafe { origin.clone().into().unwrap_unchecked() } { - RawOrigin::Signed(account) => account.into(), - _ => panic!("wrong RawOrigin returned") - }; + let main: T::AccountId = whitelisted_caller(); let proxy = T::AccountId::decode(&mut &[x as u8; 32].to_vec()[..]).unwrap(); >::put(true); - Ocex::::register_main_account(origin.clone(), main.clone())?; - let call = Call::::add_proxy_account { proxy: proxy.clone() }; - }: { call.dispatch_bypass_filter(origin)? } + Ocex::::register_main_account(RawOrigin::Signed(main.clone()).into(), main.clone())?; + }: _(RawOrigin::Signed(main.clone()), proxy.clone()) verify { - assert_last_event::(Event::MainAccountRegistered { + assert_last_event::(Event::NewProxyAdded { main, proxy }.into()); @@ -366,7 +355,7 @@ benchmarks! { BalanceOf::::decode(&mut &(u128::MAX).to_le_bytes()[..]).unwrap() )?; let call = Call::::claim_withdraw { snapshot_id: x as u64, account: main.clone() }; - }: { call.dispatch_bypass_filter(origin)? } + }: _(RawOrigin::Signed(main.clone()), x as u64, main.clone()) verify { assert_last_event::(Event::WithdrawalClaimed { main, diff --git a/pallets/thea-executor/src/benchmarking.rs b/pallets/thea-executor/src/benchmarking.rs index c23fcda10..5462b7ab9 100644 --- a/pallets/thea-executor/src/benchmarking.rs +++ b/pallets/thea-executor/src/benchmarking.rs @@ -62,7 +62,7 @@ benchmarks! { >::insert(100, metadata); ::Currency::mint_into(&account, 100_000_000_000_000u128.saturated_into()).unwrap(); >::insert(account.clone(), deposits); - }: _(RawOrigin::None, 10,account.clone()) + }: _(RawOrigin::Signed(account.clone()), 10,account.clone()) verify { let current_balance = ::Assets::balance(asset_id.into(), &account); assert_eq!(current_balance, 1_000_000_000_000_000u128.saturated_into()); diff --git a/pallets/thea-executor/src/lib.rs b/pallets/thea-executor/src/lib.rs index 47b565661..5def81c12 100644 --- a/pallets/thea-executor/src/lib.rs +++ b/pallets/thea-executor/src/lib.rs @@ -44,7 +44,12 @@ pub trait WeightInfo { #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::{pallet_prelude::*, sp_runtime::SaturatedConversion, traits::{fungible::Mutate, fungibles::Inspect, tokens::Preservation}, transactional}; + use frame_support::{ + pallet_prelude::*, + sp_runtime::SaturatedConversion, + traits::{fungible::Mutate, fungibles::Inspect, tokens::Preservation}, + transactional, + }; use frame_system::pallet_prelude::*; use pallet_asset_conversion::Swap; use polkadex_primitives::Resolver;