From caa9a2766dc81e1dea3ad2257490f321fef73903 Mon Sep 17 00:00:00 2001 From: Amiya Behera Date: Thu, 26 Sep 2024 17:42:14 +0530 Subject: [PATCH] benchmarking --- .../project-tips/src/benchmarking.rs | 34 +++++++++++++++++++ custom-pallets/project-tips/src/extras.rs | 2 +- notes | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/custom-pallets/project-tips/src/benchmarking.rs b/custom-pallets/project-tips/src/benchmarking.rs index 98c8bcd..28da0e0 100644 --- a/custom-pallets/project-tips/src/benchmarking.rs +++ b/custom-pallets/project-tips/src/benchmarking.rs @@ -6,9 +6,15 @@ use crate::types::{Incentives, TippingName}; #[allow(unused)] use crate::Pallet as ProjectTips; use frame_benchmarking::v2::*; +use frame_support::{assert_noop, assert_ok}; use frame_system::RawOrigin; +use pallet_schelling_game_shared::PeriodName; +use pallet_schelling_game_shared::StakingStartTime; +use pallet_sortition_sum_game::SortitionSumTrees; use pallet_support::Content; +const SEED: u32 = 0; + #[benchmarks] mod benchmarks { use super::*; @@ -33,5 +39,33 @@ mod benchmarks { create_project(RawOrigin::Signed(caller), 5, content.clone(), tipping_name, funding_needed); } + #[benchmark] + fn apply_staking_period() { + let tipping_name = TippingName::SmallTipper; + let tipping_value = ProjectTips::::value_of_tipping_name(tipping_name); + let max_tipping_value = tipping_value.max_tipping_value; + let sub_value = ProjectTips::::u64_to_balance_saturated(100); + let funding_needed = max_tipping_value - sub_value; + let content: Content = Content::IPFS( + "bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy" + .as_bytes() + .to_vec(), + ); + + let account1 = account::("account1", 1, SEED); + assert_ok!(ProjectTips::::create_project( + RawOrigin::Signed(account1.clone()).into(), + 2, + content, + tipping_name, + funding_needed + )); + + #[extrinsic_call] + apply_staking_period(RawOrigin::Signed(account1), 1); + + // assert_eq!(>::get(project_id), Some(now)); + } + impl_benchmark_test_suite!(ProjectTips, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/custom-pallets/project-tips/src/extras.rs b/custom-pallets/project-tips/src/extras.rs index 6c5e6ee..40da5ee 100644 --- a/custom-pallets/project-tips/src/extras.rs +++ b/custom-pallets/project-tips/src/extras.rs @@ -78,7 +78,7 @@ impl Pallet { input.saturated_into::>() } - pub(super) fn _u64_to_block_saturated(input: u64) -> BlockNumberOf { + pub(super) fn u64_to_block_saturated(input: u64) -> BlockNumberOf { input.saturated_into::>() } diff --git a/notes b/notes index f30656d..fdb00c3 100644 --- a/notes +++ b/notes @@ -3,6 +3,8 @@ Benchmarking v2: look at collective pallet cargo build --release --features runtime-benchmarks +cargo check --features runtime-benchmarks + ./target/release/node-template benchmark pallet --chain dev --pallet pallet_template --extrinsic * --steps=50 --repeat=20 --execution=wasm --wasm-execution=compiled --output pallets/template/src/weights.rs --template ../../.maintain/frame-weight-template.hbs ./target/release/node-template benchmark pallet --chain dev --pallet pallet-project-tips --extrinsic "*" --steps=50 --repeat=20 --wasm-execution=compiled --output custom-pallets/project-tips/src/weights.rs --template ./.maintain/frame-weight-template.hbs