mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 07:37:57 +00:00
[FRAME] Parameters pallet (#2061)
Closes #169 Fork of the `orml-parameters-pallet` as introduced by https://github.com/open-web3-stack/open-runtime-module-library/pull/927 (cc @xlc) It greatly changes how the macros work, but keeps the pallet the same. The downside of my code is now that it does only support constant keys in the form of types, not value-bearing keys. I think this is an acceptable trade off, give that it can be used by *any* pallet without any changes. The pallet allows to dynamically set parameters that can be used in pallet configs while also restricting the updating on a per-key basis. The rust-docs contains a complete example. Changes: - Add `parameters-pallet` - Use in the kitchensink as demonstration - Add experimental attribute to define dynamic params in the runtime. - Adding a bunch of traits to `frame_support::traits::dynamic_params` that can be re-used by the ORML macros ## Example First to define the parameters in the runtime file. The syntax is very explicit about the codec index and errors if there is no. ```rust #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>))] pub mod dynamic_params { use super::*; #[dynamic_pallet_params] #[codec(index = 0)] pub mod storage { /// Configures the base deposit of storing some data. #[codec(index = 0)] pub static BaseDeposit: Balance = 1 * DOLLARS; /// Configures the per-byte deposit of storing some data. #[codec(index = 1)] pub static ByteDeposit: Balance = 1 * CENTS; } #[dynamic_pallet_params] #[codec(index = 1)] pub mod contracts { #[codec(index = 0)] pub static DepositPerItem: Balance = deposit(1, 0); #[codec(index = 1)] pub static DepositPerByte: Balance = deposit(0, 1); } } ``` Then the pallet is configured with the aggregate: ```rust impl pallet_parameters::Config for Runtime { type AggregratedKeyValue = RuntimeParameters; type AdminOrigin = EnsureRootWithSuccess<AccountId, ConstBool<true>>; ... } ``` And then the parameters can be used in a pallet config: ```rust impl pallet_preimage::Config for Runtime { type DepositBase = dynamic_params::storage::DepositBase; } ``` A custom origin an be defined like this: ```rust pub struct DynamicParametersManagerOrigin; impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for DynamicParametersManagerOrigin { type Success = (); fn try_origin( origin: RuntimeOrigin, key: &RuntimeParametersKey, ) -> Result<Self::Success, RuntimeOrigin> { match key { RuntimeParametersKey::Storage(_) => { frame_system::ensure_root(origin.clone()).map_err(|_| origin)?; return Ok(()) }, RuntimeParametersKey::Contract(_) => { frame_system::ensure_root(origin.clone()).map_err(|_| origin)?; return Ok(()) }, } } #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> { Ok(RuntimeOrigin::Root) } } ``` --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
aac07af03c
commit
e53ebd8cd4
@@ -0,0 +1,51 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Parameters pallet benchmarking.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use crate::Pallet as Parameters;
|
||||
|
||||
use frame_benchmarking::v2::*;
|
||||
|
||||
#[benchmarks(where T::RuntimeParameters: Default)]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn set_parameter() -> Result<(), BenchmarkError> {
|
||||
let kv = T::RuntimeParameters::default();
|
||||
let k = kv.clone().into_parts().0;
|
||||
|
||||
let origin =
|
||||
T::AdminOrigin::try_successful_origin(&k).map_err(|_| BenchmarkError::Weightless)?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, kv);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite! {
|
||||
Parameters,
|
||||
crate::tests::mock::new_test_ext(),
|
||||
crate::tests::mock::Runtime,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![deny(missing_docs)]
|
||||
// Need to enable this one since we document feature-gated stuff.
|
||||
#![allow(rustdoc::broken_intra_doc_links)]
|
||||
|
||||
//! # **⚠️ WARNING ⚠️**
|
||||
//!
|
||||
//! <br>
|
||||
//! <b>THIS CRATE IS NOT AUDITED AND SHOULD NOT BE USED IN PRODUCTION.</b>
|
||||
//! <br>
|
||||
//!
|
||||
//! # Parameters
|
||||
//!
|
||||
//! Allows to update configuration parameters at runtime.
|
||||
//!
|
||||
//! ## Pallet API
|
||||
//!
|
||||
//! This pallet exposes two APIs; one *inbound* side to update parameters, and one *outbound* side
|
||||
//! to access said parameters. Parameters themselves are defined in the runtime config and will be
|
||||
//! aggregated into an enum. Each parameter is addressed by a `key` and can have a default value.
|
||||
//! This is not done by the pallet but through the [`frame_support::dynamic_params::dynamic_params`]
|
||||
//! macro or alternatives.
|
||||
//!
|
||||
//! Note that this is incurring one storage read per access. This should not be a problem in most
|
||||
//! cases but must be considered in weight-restrained code.
|
||||
//!
|
||||
//! ### Inbound
|
||||
//!
|
||||
//! The inbound side solely consists of the [`Pallet::set_parameter`] extrinsic to update the value
|
||||
//! of a parameter. Each parameter can have their own admin origin as given by the
|
||||
//! [`Config::AdminOrigin`].
|
||||
//!
|
||||
//! ### Outbound
|
||||
//!
|
||||
//! The outbound side is runtime facing for the most part. More general, it provides a `Get`
|
||||
//! implementation and can be used in every spot where that is accepted. Two macros are in place:
|
||||
//! [`frame_support::dynamic_params::define_parameters` and
|
||||
//! [`frame_support::dynamic_params:dynamic_pallet_params`] to define and expose parameters in a
|
||||
//! typed manner.
|
||||
//!
|
||||
//! See the [`pallet`] module for more information about the interfaces this pallet exposes,
|
||||
//! including its configuration trait, dispatchables, storage items, events and errors.
|
||||
//!
|
||||
//! ## Overview
|
||||
//!
|
||||
//! This pallet is a good fit for updating parameters without a runtime upgrade. It is very handy to
|
||||
//! not require a runtime upgrade for a simple parameter change since runtime upgrades require a lot
|
||||
//! of diligence and always bear risks. It seems overkill to update the whole runtime for a simple
|
||||
//! parameter change. This pallet allows for fine-grained control over who can update what.
|
||||
//! The only down-side is that it trades off performance with convenience and should therefore only
|
||||
//! be used in places where that is proven to be uncritical. Values that are rarely accessed but
|
||||
//! change often would be a perfect fit.
|
||||
//!
|
||||
//! ### Example Configuration
|
||||
//!
|
||||
//! Here is an example of how to define some parameters, including their default values:
|
||||
#![doc = docify::embed!("src/tests/mock.rs", dynamic_params)]
|
||||
//!
|
||||
//! A permissioned origin can be define on a per-key basis like this:
|
||||
#![doc = docify::embed!("src/tests/mock.rs", custom_origin)]
|
||||
//!
|
||||
//! The pallet will also require a default value for benchmarking. Ideally this is the variant with
|
||||
//! the longest encoded length. Although in either case the PoV benchmarking will take the worst
|
||||
//! case over the whole enum.
|
||||
#![doc = docify::embed!("src/tests/mock.rs", benchmarking_default)]
|
||||
//!
|
||||
//! Now the aggregated parameter needs to be injected into the pallet config:
|
||||
#![doc = docify::embed!("src/tests/mock.rs", impl_config)]
|
||||
//!
|
||||
//! As last step, the parameters can now be used in other pallets 🙌
|
||||
#![doc = docify::embed!("src/tests/mock.rs", usage)]
|
||||
//!
|
||||
//! ### Examples Usage
|
||||
//!
|
||||
//! Now to demonstrate how the values can be updated:
|
||||
#![doc = docify::embed!("src/tests/unit.rs", set_parameters_example)]
|
||||
//!
|
||||
//! ## Low Level / Implementation Details
|
||||
//!
|
||||
//! The pallet stores the parameters in a storage map and implements the matching `Get<Value>` for
|
||||
//! each `Key` type. The `Get` then accesses the `Parameters` map to retrieve the value. An event is
|
||||
//! emitted every time that a value was updated. It is even emitted when the value is changed to the
|
||||
//! same.
|
||||
//!
|
||||
//! The key and value types themselves are defined by macros and aggregated into a runtime wide
|
||||
//! enum. This enum is then injected into the pallet. This allows it to be used without any changes
|
||||
//! to the pallet that the parameter will be utilized by.
|
||||
//!
|
||||
//! ### Design Goals
|
||||
//!
|
||||
//! 1. Easy to update without runtime upgrade.
|
||||
//! 2. Exposes metadata and docs for user convenience.
|
||||
//! 3. Can be permissioned on a per-key base.
|
||||
//!
|
||||
//! ### Design
|
||||
//!
|
||||
//! 1. Everything is done at runtime without the need for `const` values. `Get` allows for this -
|
||||
//! which is coincidentally an upside and a downside. 2. The types are defined through macros, which
|
||||
//! allows to expose metadata and docs. 3. Access control is done through the `EnsureOriginWithArg`
|
||||
//! trait, that allows to pass data along to the origin check. It gets passed in the key. The
|
||||
//! implementor can then match on the key and the origin to decide whether the origin is
|
||||
//! permissioned to set the value.
|
||||
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
use frame_support::traits::{
|
||||
dynamic_params::{AggregratedKeyValue, IntoKey, Key, RuntimeParameterStore, TryIntoKey},
|
||||
EnsureOriginWithArg,
|
||||
};
|
||||
|
||||
mod benchmarking;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod weights;
|
||||
|
||||
pub use pallet::*;
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
/// The key type of a parameter.
|
||||
type KeyOf<T> = <<T as Config>::RuntimeParameters as AggregratedKeyValue>::Key;
|
||||
|
||||
/// The value type of a parameter.
|
||||
type ValueOf<T> = <<T as Config>::RuntimeParameters as AggregratedKeyValue>::Value;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config(with_default)]
|
||||
pub trait Config: frame_system::Config {
|
||||
/// The overarching event type.
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The overarching KV type of the parameters.
|
||||
///
|
||||
/// Usually created by [`frame_support::dynamic_params`] or equivalent.
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeParameters: AggregratedKeyValue;
|
||||
|
||||
/// The origin which may update a parameter.
|
||||
///
|
||||
/// The key of the parameter is passed in as second argument to allow for fine grained
|
||||
/// control.
|
||||
#[pallet::no_default_bounds]
|
||||
type AdminOrigin: EnsureOriginWithArg<Self::RuntimeOrigin, KeyOf<Self>>;
|
||||
|
||||
/// Weight information for extrinsics in this module.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A Parameter was set.
|
||||
///
|
||||
/// Is also emitted when the value was not changed.
|
||||
Updated {
|
||||
/// The key that was updated.
|
||||
key: <T::RuntimeParameters as AggregratedKeyValue>::Key,
|
||||
/// The old value before this call.
|
||||
old_value: Option<<T::RuntimeParameters as AggregratedKeyValue>::Value>,
|
||||
/// The new value after this call.
|
||||
new_value: Option<<T::RuntimeParameters as AggregratedKeyValue>::Value>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Stored parameters.
|
||||
#[pallet::storage]
|
||||
pub type Parameters<T: Config> =
|
||||
StorageMap<_, Blake2_128Concat, KeyOf<T>, ValueOf<T>, OptionQuery>;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Set the value of a parameter.
|
||||
///
|
||||
/// The dispatch origin of this call must be `AdminOrigin` for the given `key`. Values be
|
||||
/// deleted by setting them to `None`.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(T::WeightInfo::set_parameter())]
|
||||
pub fn set_parameter(
|
||||
origin: OriginFor<T>,
|
||||
key_value: T::RuntimeParameters,
|
||||
) -> DispatchResult {
|
||||
let (key, new) = key_value.into_parts();
|
||||
T::AdminOrigin::ensure_origin(origin, &key)?;
|
||||
|
||||
let mut old = None;
|
||||
Parameters::<T>::mutate(&key, |v| {
|
||||
old = v.clone();
|
||||
*v = new.clone();
|
||||
});
|
||||
|
||||
Self::deposit_event(Event::Updated { key, old_value: old, new_value: new });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
|
||||
pub mod config_preludes {
|
||||
use super::*;
|
||||
use frame_support::derive_impl;
|
||||
|
||||
/// A configuration for testing.
|
||||
pub struct TestDefaultConfig;
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
|
||||
impl frame_system::DefaultConfig for TestDefaultConfig {}
|
||||
|
||||
#[frame_support::register_default_impl(TestDefaultConfig)]
|
||||
impl DefaultConfig for TestDefaultConfig {
|
||||
#[inject_runtime_type]
|
||||
type RuntimeEvent = ();
|
||||
#[inject_runtime_type]
|
||||
type RuntimeParameters = ();
|
||||
|
||||
type AdminOrigin = frame_support::traits::AsEnsureOriginWithArg<
|
||||
frame_system::EnsureRoot<Self::AccountId>,
|
||||
>;
|
||||
|
||||
type WeightInfo = ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> RuntimeParameterStore for Pallet<T> {
|
||||
type AggregratedKeyValue = T::RuntimeParameters;
|
||||
|
||||
fn get<KV, K>(key: K) -> Option<K::Value>
|
||||
where
|
||||
KV: AggregratedKeyValue,
|
||||
K: Key + Into<<KV as AggregratedKeyValue>::Key>,
|
||||
<KV as AggregratedKeyValue>::Key: IntoKey<
|
||||
<<Self as RuntimeParameterStore>::AggregratedKeyValue as AggregratedKeyValue>::Key,
|
||||
>,
|
||||
<<Self as RuntimeParameterStore>::AggregratedKeyValue as AggregratedKeyValue>::Value:
|
||||
TryIntoKey<<KV as AggregratedKeyValue>::Value>,
|
||||
<KV as AggregratedKeyValue>::Value: TryInto<K::WrappedValue>,
|
||||
{
|
||||
let key: <KV as AggregratedKeyValue>::Key = key.into();
|
||||
let val = Parameters::<T>::get(key.into_key());
|
||||
val.and_then(|v| {
|
||||
let val: <KV as AggregratedKeyValue>::Value = v.try_into_key().ok()?;
|
||||
let val: K::WrappedValue = val.try_into().ok()?;
|
||||
let val = val.into();
|
||||
Some(val)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![cfg(any(test, feature = "runtime-benchmarks"))]
|
||||
|
||||
//! Mock runtime that configures the `pallet_example_basic` to use dynamic params for testing.
|
||||
|
||||
use frame_support::{
|
||||
construct_runtime, derive_impl,
|
||||
dynamic_params::{dynamic_pallet_params, dynamic_params},
|
||||
traits::EnsureOriginWithArg,
|
||||
};
|
||||
|
||||
use crate as pallet_parameters;
|
||||
use crate::*;
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
type Block = frame_system::mocking::MockBlock<Runtime>;
|
||||
type AccountData = pallet_balances::AccountData<<Self as pallet_balances::Config>::Balance>;
|
||||
}
|
||||
|
||||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
|
||||
impl pallet_balances::Config for Runtime {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
|
||||
pub mod dynamic_params {
|
||||
use super::*;
|
||||
|
||||
#[dynamic_pallet_params]
|
||||
#[codec(index = 3)]
|
||||
pub mod pallet1 {
|
||||
#[codec(index = 0)]
|
||||
pub static Key1: u64 = 0;
|
||||
#[codec(index = 1)]
|
||||
pub static Key2: u32 = 1;
|
||||
#[codec(index = 2)]
|
||||
pub static Key3: u128 = 2;
|
||||
}
|
||||
|
||||
#[dynamic_pallet_params]
|
||||
#[codec(index = 1)]
|
||||
pub mod pallet2 {
|
||||
#[codec(index = 2)]
|
||||
pub static Key1: u64 = 0;
|
||||
#[codec(index = 1)]
|
||||
pub static Key2: u32 = 2;
|
||||
#[codec(index = 0)]
|
||||
pub static Key3: u128 = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(benchmarking_default)]
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl Default for RuntimeParameters {
|
||||
fn default() -> Self {
|
||||
RuntimeParameters::Pallet1(dynamic_params::pallet1::Parameters::Key1(
|
||||
dynamic_params::pallet1::Key1,
|
||||
Some(123),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
mod custom_origin {
|
||||
use super::*;
|
||||
pub struct ParamsManager;
|
||||
|
||||
impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for ParamsManager {
|
||||
type Success = ();
|
||||
|
||||
fn try_origin(
|
||||
origin: RuntimeOrigin,
|
||||
key: &RuntimeParametersKey,
|
||||
) -> Result<Self::Success, RuntimeOrigin> {
|
||||
// Account 123 is allowed to set parameters in benchmarking only:
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
if ensure_signed(origin.clone()).map_or(false, |acc| acc == 123) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match key {
|
||||
RuntimeParametersKey::Pallet1(_) => ensure_root(origin.clone()),
|
||||
RuntimeParametersKey::Pallet2(_) => ensure_signed(origin.clone()).map(|_| ()),
|
||||
}
|
||||
.map_err(|_| origin)
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> {
|
||||
Ok(RuntimeOrigin::signed(123))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[docify::export(impl_config)]
|
||||
#[derive_impl(pallet_parameters::config_preludes::TestDefaultConfig as pallet_parameters::DefaultConfig)]
|
||||
impl Config for Runtime {
|
||||
type AdminOrigin = custom_origin::ParamsManager;
|
||||
// RuntimeParameters is injected by the `derive_impl` macro.
|
||||
// RuntimeEvent is injected by the `derive_impl` macro.
|
||||
// WeightInfo is injected by the `derive_impl` macro.
|
||||
}
|
||||
|
||||
#[docify::export(usage)]
|
||||
impl pallet_example_basic::Config for Runtime {
|
||||
// Use the dynamic key in the pallet config:
|
||||
type MagicNumber = dynamic_params::pallet1::Key1;
|
||||
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Runtime {
|
||||
System: frame_system,
|
||||
PalletParameters: crate,
|
||||
Example: pallet_example_basic,
|
||||
Balances: pallet_balances,
|
||||
}
|
||||
);
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext = sp_io::TestExternalities::new(Default::default());
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
pub(crate) fn assert_last_event(generic_event: RuntimeEvent) {
|
||||
let events = frame_system::Pallet::<Runtime>::events();
|
||||
// compare to the last event record
|
||||
let frame_system::EventRecord { event, .. } = &events.last().expect("Event expected");
|
||||
assert_eq!(event, &generic_event);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub(crate) mod mock;
|
||||
mod test_renamed;
|
||||
mod unit;
|
||||
@@ -0,0 +1,168 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![cfg(any(test, feature = "runtime-benchmarks"))]
|
||||
|
||||
//! Tests that the runtime params can be renamed.
|
||||
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, construct_runtime, derive_impl,
|
||||
dynamic_params::{dynamic_pallet_params, dynamic_params},
|
||||
traits::AsEnsureOriginWithArg,
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
|
||||
use crate as pallet_parameters;
|
||||
use crate::*;
|
||||
use dynamic_params::*;
|
||||
use RuntimeParametersRenamed::*;
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
type Block = frame_system::mocking::MockBlock<Runtime>;
|
||||
type AccountData = pallet_balances::AccountData<<Self as pallet_balances::Config>::Balance>;
|
||||
}
|
||||
|
||||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)]
|
||||
impl pallet_balances::Config for Runtime {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
#[dynamic_params(RuntimeParametersRenamed, pallet_parameters::Parameters::<Runtime>)]
|
||||
pub mod dynamic_params {
|
||||
use super::*;
|
||||
|
||||
#[dynamic_pallet_params]
|
||||
#[codec(index = 3)]
|
||||
pub mod pallet1 {
|
||||
#[codec(index = 0)]
|
||||
pub static Key1: u64 = 0;
|
||||
#[codec(index = 1)]
|
||||
pub static Key2: u32 = 1;
|
||||
#[codec(index = 2)]
|
||||
pub static Key3: u128 = 2;
|
||||
}
|
||||
|
||||
#[dynamic_pallet_params]
|
||||
#[codec(index = 1)]
|
||||
pub mod pallet2 {
|
||||
#[codec(index = 2)]
|
||||
pub static Key1: u64 = 0;
|
||||
#[codec(index = 1)]
|
||||
pub static Key2: u32 = 2;
|
||||
#[codec(index = 0)]
|
||||
pub static Key3: u128 = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl Default for RuntimeParametersRenamed {
|
||||
fn default() -> Self {
|
||||
RuntimeParametersRenamed::Pallet1(dynamic_params::pallet1::Parameters::Key1(
|
||||
dynamic_params::pallet1::Key1,
|
||||
Some(123),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive_impl(pallet_parameters::config_preludes::TestDefaultConfig as pallet_parameters::DefaultConfig)]
|
||||
impl Config for Runtime {
|
||||
type AdminOrigin = AsEnsureOriginWithArg<EnsureRoot<Self::AccountId>>;
|
||||
type RuntimeParameters = RuntimeParametersRenamed;
|
||||
// RuntimeEvent is injected by the `derive_impl` macro.
|
||||
// WeightInfo is injected by the `derive_impl` macro.
|
||||
}
|
||||
|
||||
impl pallet_example_basic::Config for Runtime {
|
||||
// Use the dynamic key in the pallet config:
|
||||
type MagicNumber = dynamic_params::pallet1::Key1;
|
||||
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Runtime {
|
||||
System: frame_system,
|
||||
PalletParameters: crate,
|
||||
Example: pallet_example_basic,
|
||||
Balances: pallet_balances,
|
||||
}
|
||||
);
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext = sp_io::TestExternalities::new(Default::default());
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
pub(crate) fn assert_last_event(generic_event: RuntimeEvent) {
|
||||
let events = frame_system::Pallet::<Runtime>::events();
|
||||
// compare to the last event record
|
||||
let frame_system::EventRecord { event, .. } = &events.last().expect("Event expected");
|
||||
assert_eq!(event, &generic_event);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_parameters_example() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(pallet1::Key3::get(), 2, "Default works");
|
||||
|
||||
// This gets rejected since the origin is not root.
|
||||
assert_noop!(
|
||||
PalletParameters::set_parameter(
|
||||
RuntimeOrigin::signed(1),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
RuntimeOrigin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_eq!(pallet1::Key3::get(), 123, "Update works");
|
||||
assert_last_event(
|
||||
crate::Event::Updated {
|
||||
key: RuntimeParametersRenamedKey::Pallet1(pallet1::ParametersKey::Key3(
|
||||
pallet1::Key3,
|
||||
)),
|
||||
old_value: None,
|
||||
new_value: Some(RuntimeParametersRenamedValue::Pallet1(
|
||||
pallet1::ParametersValue::Key3(123),
|
||||
)),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_through_external_pallet_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(<Runtime as pallet_example_basic::Config>::MagicNumber::get(), 0);
|
||||
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
RuntimeOrigin::root(),
|
||||
Pallet1(pallet1::Parameters::Key1(pallet1::Key1, Some(123))),
|
||||
));
|
||||
|
||||
assert_eq!(<Runtime as pallet_example_basic::Config>::MagicNumber::get(), 123);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Unit tests for the parameters pallet.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::tests::mock::{
|
||||
assert_last_event, dynamic_params::*, new_test_ext, PalletParameters, Runtime,
|
||||
RuntimeOrigin as Origin, RuntimeParameters, RuntimeParameters::*, RuntimeParametersKey,
|
||||
RuntimeParametersValue,
|
||||
};
|
||||
use codec::Encode;
|
||||
use frame_support::{assert_noop, assert_ok, traits::dynamic_params::AggregratedKeyValue};
|
||||
use sp_core::Get;
|
||||
use sp_runtime::DispatchError;
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn set_parameters_example() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(pallet1::Key3::get(), 2, "Default works");
|
||||
|
||||
// This gets rejected since the origin is not root.
|
||||
assert_noop!(
|
||||
PalletParameters::set_parameter(
|
||||
Origin::signed(1),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_eq!(pallet1::Key3::get(), 123, "Update works");
|
||||
assert_last_event(
|
||||
crate::Event::Updated {
|
||||
key: RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key3(pallet1::Key3)),
|
||||
old_value: None,
|
||||
new_value: Some(RuntimeParametersValue::Pallet1(pallet1::ParametersValue::Key3(
|
||||
123,
|
||||
))),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_parameters_same_is_noop() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_eq!(pallet1::Key3::get(), 123, "Update works");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_parameters_twice_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(432))),
|
||||
));
|
||||
|
||||
assert_eq!(pallet1::Key3::get(), 432, "Update works");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_parameters_removing_restores_default_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_eq!(pallet1::Key3::get(), 123, "Update works");
|
||||
assert!(
|
||||
crate::Parameters::<Runtime>::contains_key(RuntimeParametersKey::Pallet1(
|
||||
pallet1::ParametersKey::Key3(pallet1::Key3)
|
||||
)),
|
||||
"Key inserted"
|
||||
);
|
||||
|
||||
// Removing the value restores the default.
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, None)),
|
||||
));
|
||||
|
||||
assert_eq!(pallet1::Key3::get(), 2, "Default restored");
|
||||
assert!(
|
||||
!crate::Parameters::<Runtime>::contains_key(RuntimeParametersKey::Pallet1(
|
||||
pallet1::ParametersKey::Key3(pallet1::Key3)
|
||||
)),
|
||||
"Key removed"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_parameters_to_default_emits_events_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(pallet1::Key3::get(), 2);
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(2))),
|
||||
));
|
||||
assert_eq!(pallet1::Key3::get(), 2);
|
||||
|
||||
assert!(
|
||||
crate::Parameters::<Runtime>::contains_key(RuntimeParametersKey::Pallet1(
|
||||
pallet1::ParametersKey::Key3(pallet1::Key3)
|
||||
)),
|
||||
"Key inserted"
|
||||
);
|
||||
assert_last_event(
|
||||
crate::Event::Updated {
|
||||
key: RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key3(pallet1::Key3)),
|
||||
old_value: None,
|
||||
new_value: Some(RuntimeParametersValue::Pallet1(pallet1::ParametersValue::Key3(2))),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
||||
// It will also emit a second event:
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(2))),
|
||||
));
|
||||
assert_eq!(frame_system::Pallet::<Runtime>::events().len(), 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_parameters_wrong_origin_errors() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Pallet1 is root origin only:
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
PalletParameters::set_parameter(
|
||||
Origin::signed(1),
|
||||
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(432))),
|
||||
),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
|
||||
// Pallet2 is signed origin only:
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::signed(1),
|
||||
Pallet2(pallet2::Parameters::Key3(pallet2::Key3, Some(123))),
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet2(pallet2::Parameters::Key3(pallet2::Key3, Some(432))),
|
||||
),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_through_external_pallet_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(<Runtime as pallet_example_basic::Config>::MagicNumber::get(), 0);
|
||||
|
||||
assert_ok!(PalletParameters::set_parameter(
|
||||
Origin::root(),
|
||||
Pallet1(pallet1::Parameters::Key1(pallet1::Key1, Some(123))),
|
||||
));
|
||||
|
||||
assert_eq!(<Runtime as pallet_example_basic::Config>::MagicNumber::get(), 123);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_define_parameters_key_convert() {
|
||||
let key1 = pallet1::Key1;
|
||||
let parameter_key: pallet1::ParametersKey = key1.clone().into();
|
||||
let key1_2: pallet1::Key1 = parameter_key.clone().try_into().unwrap();
|
||||
|
||||
assert_eq!(key1, key1_2);
|
||||
assert_eq!(parameter_key, pallet1::ParametersKey::Key1(key1));
|
||||
|
||||
let key2 = pallet1::Key2;
|
||||
let parameter_key: pallet1::ParametersKey = key2.clone().into();
|
||||
let key2_2: pallet1::Key2 = parameter_key.clone().try_into().unwrap();
|
||||
|
||||
assert_eq!(key2, key2_2);
|
||||
assert_eq!(parameter_key, pallet1::ParametersKey::Key2(key2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_define_parameters_value_convert() {
|
||||
let value1 = pallet1::Key1Value(1);
|
||||
let parameter_value: pallet1::ParametersValue = value1.clone().into();
|
||||
let value1_2: pallet1::Key1Value = parameter_value.clone().try_into().unwrap();
|
||||
|
||||
assert_eq!(value1, value1_2);
|
||||
assert_eq!(parameter_value, pallet1::ParametersValue::Key1(1));
|
||||
|
||||
let value2 = pallet1::Key2Value(2);
|
||||
let parameter_value: pallet1::ParametersValue = value2.clone().into();
|
||||
let value2_2: pallet1::Key2Value = parameter_value.clone().try_into().unwrap();
|
||||
|
||||
assert_eq!(value2, value2_2);
|
||||
assert_eq!(parameter_value, pallet1::ParametersValue::Key2(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_define_parameters_aggregrated_key_value() {
|
||||
let kv1 = pallet1::Parameters::Key1(pallet1::Key1, None);
|
||||
let (key1, value1) = kv1.clone().into_parts();
|
||||
|
||||
assert_eq!(key1, pallet1::ParametersKey::Key1(pallet1::Key1));
|
||||
assert_eq!(value1, None);
|
||||
|
||||
let kv2 = pallet1::Parameters::Key2(pallet1::Key2, Some(2));
|
||||
let (key2, value2) = kv2.clone().into_parts();
|
||||
|
||||
assert_eq!(key2, pallet1::ParametersKey::Key2(pallet1::Key2));
|
||||
assert_eq!(value2, Some(pallet1::ParametersValue::Key2(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_define_aggregrated_parameters_key_convert() {
|
||||
use codec::Encode;
|
||||
|
||||
let key1 = pallet1::Key1;
|
||||
let parameter_key: pallet1::ParametersKey = key1.clone().into();
|
||||
let runtime_key: RuntimeParametersKey = parameter_key.clone().into();
|
||||
|
||||
assert_eq!(runtime_key, RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key1(key1)));
|
||||
assert_eq!(runtime_key.encode(), vec![3, 0]);
|
||||
|
||||
let key2 = pallet2::Key2;
|
||||
let parameter_key: pallet2::ParametersKey = key2.clone().into();
|
||||
let runtime_key: RuntimeParametersKey = parameter_key.clone().into();
|
||||
|
||||
assert_eq!(runtime_key, RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key2(key2)));
|
||||
assert_eq!(runtime_key.encode(), vec![1, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_define_aggregrated_parameters_aggregrated_key_value() {
|
||||
let kv1 = RuntimeParameters::Pallet1(pallet1::Parameters::Key1(pallet1::Key1, None));
|
||||
let (key1, value1) = kv1.clone().into_parts();
|
||||
|
||||
assert_eq!(key1, RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key1(pallet1::Key1)));
|
||||
assert_eq!(value1, None);
|
||||
|
||||
let kv2 = RuntimeParameters::Pallet2(pallet2::Parameters::Key2(pallet2::Key2, Some(2)));
|
||||
let (key2, value2) = kv2.clone().into_parts();
|
||||
|
||||
assert_eq!(key2, RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key2(pallet2::Key2)));
|
||||
assert_eq!(value2, Some(RuntimeParametersValue::Pallet2(pallet2::ParametersValue::Key2(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codec_index_works() {
|
||||
let enc = RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key1(pallet1::Key1)).encode();
|
||||
assert_eq!(enc, vec![3, 0]);
|
||||
let enc = RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key2(pallet1::Key2)).encode();
|
||||
assert_eq!(enc, vec![3, 1]);
|
||||
let enc = RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key3(pallet1::Key3)).encode();
|
||||
assert_eq!(enc, vec![3, 2]);
|
||||
|
||||
let enc = RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key1(pallet2::Key1)).encode();
|
||||
assert_eq!(enc, vec![1, 2]);
|
||||
let enc = RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key2(pallet2::Key2)).encode();
|
||||
assert_eq!(enc, vec![1, 1]);
|
||||
let enc = RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key3(pallet2::Key3)).encode();
|
||||
assert_eq!(enc, vec![1, 0]);
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Autogenerated weights for `pallet_parameters`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
|
||||
//! DATE: 2024-02-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `runner-bn-ce5rx-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
|
||||
|
||||
// Executed Command:
|
||||
// target/production/substrate-node
|
||||
// benchmark
|
||||
// pallet
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --extrinsic=*
|
||||
// --wasm-execution=compiled
|
||||
// --heap-pages=4096
|
||||
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
|
||||
// --pallet=pallet_parameters
|
||||
// --chain=dev
|
||||
// --header=./substrate/HEADER-APACHE2
|
||||
// --output=./substrate/frame/parameters/src/weights.rs
|
||||
// --template=./substrate/.maintain/frame-weight-template.hbs
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for `pallet_parameters`.
|
||||
pub trait WeightInfo {
|
||||
fn set_parameter() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for `pallet_parameters` using the Substrate node and recommended hardware.
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
fn set_parameter() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 0_000 picoseconds.
|
||||
Weight::from_parts(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests.
|
||||
impl WeightInfo for () {
|
||||
fn set_parameter() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 0_000 picoseconds.
|
||||
Weight::from_parts(0, 0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user