Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds benchmarks
  • Loading branch information
gupnik committed Jun 2, 2023
commit 93d5aa8022cbf6bf30e48c587b1b763861a9f891
7 changes: 5 additions & 2 deletions frame/examples/kitchensink/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

// Only enable this module for benchmarking.
#![cfg(feature = "runtime-benchmarks")]
use super::*;

#[allow(unused)]
use crate::Pallet as Kitchensink;

use crate::*;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;

Expand Down Expand Up @@ -59,5 +62,5 @@ mod benchmarks {
//
// The line generates three steps per benchmark, with repeat=1 and the three steps are
// [low, mid, high] of the range.
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test);
impl_benchmark_test_suite!(Kitchensink, crate::tests::new_test_ext(), crate::tests::Test);
}
19 changes: 13 additions & 6 deletions frame/examples/kitchensink/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
/// The kitchen-sink catalog of the the FRAME macros and their various syntax options.
///
/// This example does not focus on pallet instancing, `dev_mode`, and does nto include any 'where'
Expand All @@ -12,11 +13,15 @@ pub use pallet::*;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;

pub mod weights;
pub use weights::*;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -45,6 +50,9 @@ pub mod pallet {
/// The overarching runtime event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;

/// This is a normal Rust type, nothing specific to FRAME here.
type Currency: frame_support::traits::tokens::fungible::Inspect<Self::AccountId>;

Expand Down Expand Up @@ -83,8 +91,8 @@ pub mod pallet {
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::origin]
pub type Origin<T> = frame_system::RawOrigin<<T as frame_system::Config>::AccountId>;
// #[pallet::origin]
// pub type Origin<T> = frame_system::RawOrigin<<T as frame_system::Config>::AccountId>;

// first, we showcase all the possible storage types, with most of their details.

Expand Down Expand Up @@ -157,24 +165,23 @@ pub mod pallet {
pub bar: T::BlockNumber,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
unimplemented!()
Self { foo: 0, bar: Default::default() }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {

Foo::<T>::put(self.foo);
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
#[pallet::weight(T::WeightInfo::set_foo_benchmark())]
pub fn set_foo(
_: OriginFor<T>,
new_foo: u32,
Expand Down
2 changes: 2 additions & 0 deletions frame/examples/kitchensink/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ parameter_types! {

impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();

type Currency = Balances;
type InMetadata = InMetadata;

Expand Down
68 changes: 68 additions & 0 deletions frame/examples/kitchensink/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.