Skip to content

Commit

Permalink
benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Sep 26, 2024
1 parent 3a88c76 commit caa9a27
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
34 changes: 34 additions & 0 deletions custom-pallets/project-tips/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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::<T>::value_of_tipping_name(tipping_name);
let max_tipping_value = tipping_value.max_tipping_value;
let sub_value = ProjectTips::<T>::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::<T::AccountId>("account1", 1, SEED);
assert_ok!(ProjectTips::<T>::create_project(
RawOrigin::Signed(account1.clone()).into(),
2,
content,
tipping_name,
funding_needed
));

#[extrinsic_call]
apply_staking_period(RawOrigin::Signed(account1), 1);

// assert_eq!(<ValidationBlock<T>>::get(project_id), Some(now));
}

impl_benchmark_test_suite!(ProjectTips, crate::mock::new_test_ext(), crate::mock::Test);
}
2 changes: 1 addition & 1 deletion custom-pallets/project-tips/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T: Config> Pallet<T> {
input.saturated_into::<BalanceOf<T>>()
}

pub(super) fn _u64_to_block_saturated(input: u64) -> BlockNumberOf<T> {
pub(super) fn u64_to_block_saturated(input: u64) -> BlockNumberOf<T> {
input.saturated_into::<BlockNumberOf<T>>()
}

Expand Down
2 changes: 2 additions & 0 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit caa9a27

Please sign in to comment.