From 11b8b84704b7d99c59b9fdc32b9578c4d61c2585 Mon Sep 17 00:00:00 2001 From: Otavio Migliavacca Madalosso Date: Sat, 30 Nov 2024 14:45:11 -0300 Subject: [PATCH 1/5] refactor tests: use macro runtime --- pallets/template/src/tests.rs | 40 ++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/pallets/template/src/tests.rs b/pallets/template/src/tests.rs index 2e47a35..aec4489 100644 --- a/pallets/template/src/tests.rs +++ b/pallets/template/src/tests.rs @@ -13,6 +13,7 @@ use crate::*; use crate::{self as pallet_kitties}; +use frame::deps::frame_support::runtime; use frame::deps::sp_io; use frame::runtime::prelude::*; use frame::testing_prelude::*; @@ -34,16 +35,35 @@ const DEFAULT_KITTY: Kitty = Kitty { price: None, }; -// Our blockchain tests only need 3 Pallets: -// 1. System: Which is included with every FRAME runtime. -// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot) -// 3. PalletKitties: The pallet you are building in this tutorial! -construct_runtime! { - pub struct TestRuntime { - System: frame_system, - PalletBalances: pallet_balances, - PalletKitties: pallet_kitties, - } +#[runtime] +mod runtime { + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeTask, + RuntimeFreezeReason, + RuntimeHoldReason + )] + #[runtime::runtime] + /// The "test runtime" that represents the state transition function for our blockchain. + /// + /// The runtime is composed of individual modules called "pallets", which you find see below. + /// Each pallet has its own logic and storage, all of which can be combined together. + pub struct TestRuntime; + + /// System: Mandatory system pallet that should always be included in a FRAME runtime. + #[runtime::pallet_index(0)] + pub type System = frame_system::Pallet; + + /// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot) + #[runtime::pallet_index(1)] + pub type PalletBalances = pallet_balances::Pallet; + + /// PalletKitties: The pallet you are building in this tutorial! + #[runtime::pallet_index(2)] + pub type PalletKitties = pallet_kitties::Pallet; } // Normally `System` would have many more configurations, but you can see that we use some macro From 3fe9d209261233d99455333e6d213d00b1e9d823 Mon Sep 17 00:00:00 2001 From: Otavio Migliavacca Madalosso Date: Sat, 30 Nov 2024 15:48:19 -0300 Subject: [PATCH 2/5] fix on tests to use PalletBalances force_set_balance instead of mint --- pallets/template/src/mock.rs | 88 +++++++++++++++++-------- pallets/template/src/tests.rs | 117 ++++++++++++---------------------- 2 files changed, 101 insertions(+), 104 deletions(-) diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs index cf1f2e3..d9d79ff 100644 --- a/pallets/template/src/mock.rs +++ b/pallets/template/src/mock.rs @@ -1,41 +1,75 @@ -use crate as pallet_template; -use frame_support::derive_impl; -use sp_runtime::BuildStorage; - -type Block = frame_system::mocking::MockBlock; - -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - Balances: pallet_balances, // added - TemplateModule: pallet_template, - } -); +#![cfg(test)] -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] -impl pallet_balances::Config for Test { - type AccountStore = System; +use crate::*; +use crate::{self as pallet_kitties}; +use frame::deps::frame_support::runtime; +use frame::deps::sp_io; +use frame::runtime::prelude::*; +use frame::testing_prelude::*; + +type Balance = u64; +type Block = frame_system::mocking::MockBlock; + +#[runtime] +mod runtime { + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeTask, + RuntimeFreezeReason, + RuntimeHoldReason + )] + #[runtime::runtime] + /// The "test runtime" that represents the state transition function for our blockchain. + /// + /// The runtime is composed of individual modules called "pallets", which you find see below. + /// Each pallet has its own logic and storage, all of which can be combined together. + pub struct TestRuntime; + + /// System: Mandatory system pallet that should always be included in a FRAME runtime. + #[runtime::pallet_index(0)] + pub type System = frame_system::Pallet; + + /// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot) + #[runtime::pallet_index(1)] + pub type PalletBalances = pallet_balances::Pallet; + + /// PalletKitties: The pallet you are building in this tutorial! + #[runtime::pallet_index(2)] + pub type PalletKitties = pallet_kitties::Pallet; } +// Normally `System` would have many more configurations, but you can see that we use some macro +// magic to automatically configure most of the pallet for a "default test configuration". #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Test { +impl frame_system::Config for TestRuntime { type Block = Block; - type AccountData = pallet_balances::AccountData; - // type OnNewAccount = (); - // type OnKilledAccount = (); - // type SystemWeightInfo = (); + type AccountData = pallet_balances::AccountData; +} + +// Normally `pallet_balances` would have many more configurations, but you can see that we use some +// macro magic to automatically configure most of the pallet for a "default test configuration". +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] +impl pallet_balances::Config for TestRuntime { + type AccountStore = System; + type Balance = Balance; } -impl pallet_template::Config for Test { +// This is the configuration of our Pallet! If you make changes to the pallet's `trait Config`, you +// will also need to update this configuration to represent that. +impl pallet_kitties::Config for TestRuntime { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); + type WeightInfo = (); // TODO: investigate why this works } -// Build genesis storage according to the mock runtime. +// We need to run most of our tests using this function: `new_test_ext().execute_with(|| { ... });` +// It simulates the blockchain database backend for our tests. +// If you forget to include this and try to access your Pallet storage, you will get an error like: +// "`get_version_1` called outside of an Externalities-provided environment." pub fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::::default() + frame_system::GenesisConfig::::default() .build_storage() .unwrap() .into() diff --git a/pallets/template/src/tests.rs b/pallets/template/src/tests.rs index aec4489..f70fe94 100644 --- a/pallets/template/src/tests.rs +++ b/pallets/template/src/tests.rs @@ -11,13 +11,14 @@ // This flag tells rust to only run this file when running `cargo test`. #![cfg(test)] +use crate::mock::{new_test_ext, RuntimeEvent, RuntimeOrigin, TestRuntime}; use crate::*; -use crate::{self as pallet_kitties}; -use frame::deps::frame_support::runtime; -use frame::deps::sp_io; -use frame::runtime::prelude::*; +// use frame::deps::frame_support::runtime; +// use frame::deps::sp_io; +// use frame::runtime::prelude::*; use frame::testing_prelude::*; -use frame::traits::fungible::*; +use mock::{PalletBalances, PalletKitties, System}; +// use frame::traits::fungible::*; type Balance = u64; type Block = frame_system::mocking::MockBlock; @@ -35,71 +36,6 @@ const DEFAULT_KITTY: Kitty = Kitty { price: None, }; -#[runtime] -mod runtime { - #[runtime::derive( - RuntimeCall, - RuntimeEvent, - RuntimeError, - RuntimeOrigin, - RuntimeTask, - RuntimeFreezeReason, - RuntimeHoldReason - )] - #[runtime::runtime] - /// The "test runtime" that represents the state transition function for our blockchain. - /// - /// The runtime is composed of individual modules called "pallets", which you find see below. - /// Each pallet has its own logic and storage, all of which can be combined together. - pub struct TestRuntime; - - /// System: Mandatory system pallet that should always be included in a FRAME runtime. - #[runtime::pallet_index(0)] - pub type System = frame_system::Pallet; - - /// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot) - #[runtime::pallet_index(1)] - pub type PalletBalances = pallet_balances::Pallet; - - /// PalletKitties: The pallet you are building in this tutorial! - #[runtime::pallet_index(2)] - pub type PalletKitties = pallet_kitties::Pallet; -} - -// Normally `System` would have many more configurations, but you can see that we use some macro -// magic to automatically configure most of the pallet for a "default test configuration". -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for TestRuntime { - type Block = Block; - type AccountData = pallet_balances::AccountData; -} - -// Normally `pallet_balances` would have many more configurations, but you can see that we use some -// macro magic to automatically configure most of the pallet for a "default test configuration". -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] -impl pallet_balances::Config for TestRuntime { - type AccountStore = System; - type Balance = Balance; -} - -// This is the configuration of our Pallet! If you make changes to the pallet's `trait Config`, you -// will also need to update this configuration to represent that. -impl pallet_kitties::Config for TestRuntime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); // TODO: investigate why this works -} - -// We need to run most of our tests using this function: `new_test_ext().execute_with(|| { ... });` -// It simulates the blockchain database backend for our tests. -// If you forget to include this and try to access your Pallet storage, you will get an error like: -// "`get_version_1` called outside of an Externalities-provided environment." -pub fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::::default() - .build_storage() - .unwrap() - .into() -} - #[test] fn starting_template_is_sane() { new_test_ext().execute_with(|| { @@ -121,8 +57,18 @@ fn system_and_balances_work() { // We often need to set `System` to block 1 so that we can see events. System::set_block_number(1); // We often need to add some balance to a user to test features which needs tokens. - assert_ok!(PalletBalances::mint_into(&ALICE, 100)); - assert_ok!(PalletBalances::mint_into(&BOB, 100)); + assert_ok!(PalletBalances::force_set_balance( + RuntimeOrigin::root(), + ALICE, + 100 + )); + assert_ok!(PalletBalances::force_set_balance( + RuntimeOrigin::root(), + BOB, + 100 + )); + // assert_ok!(PalletBalances::mint_into(&ALICE, 100)); + // assert_ok!(PalletBalances::mint_into(&BOB, 100)); }); } @@ -438,7 +384,13 @@ fn do_buy_kitty_emits_event() { kitty_id, Some(1337) )); - assert_ok!(PalletBalances::mint_into(&BOB, 100_000)); + // assert_ok!(PalletBalances::mint_into(&BOB, 100_000)); + + assert_ok!(PalletBalances::force_set_balance( + RuntimeOrigin::root(), + BOB, + 100_000 + )); assert_ok!(PalletKitties::buy_kitty( RuntimeOrigin::signed(BOB), kitty_id, @@ -490,13 +442,24 @@ fn do_buy_kitty_logic_works() { frame::arithmetic::ArithmeticError::Underflow ); // Cannot buy kitty if it would kill your account (i.e. set your balance to 0). - assert_ok!(PalletBalances::mint_into(&BOB, 1337)); + // assert_ok!(PalletBalances::mint_into(&BOB, 1337)); + + assert_ok!(PalletBalances::force_set_balance( + RuntimeOrigin::root(), + BOB, + 1337 + )); assert!( PalletKitties::buy_kitty(RuntimeOrigin::signed(BOB), kitty_id, 1337).is_err(), // TODO: assert_noop on DispatchError::Token(TokenError::NotExpendable) ); // When everything is right, it works. - assert_ok!(PalletBalances::mint_into(&BOB, 100_000)); + // assert_ok!(PalletBalances::mint_into(&BOB, 100_000)); + assert_ok!(PalletBalances::force_set_balance( + RuntimeOrigin::root(), + BOB, + 101_337 + )); assert_ok!(PalletKitties::buy_kitty( RuntimeOrigin::signed(BOB), kitty_id, @@ -509,7 +472,7 @@ fn do_buy_kitty_logic_works() { // Price is reset to `None`. assert_eq!(kitty.price, None); // BOB transferred funds to ALICE. - assert_eq!(PalletBalances::balance(&ALICE), 1337); - assert_eq!(PalletBalances::balance(&BOB), 100_000); + assert_eq!(PalletBalances::free_balance(&ALICE), 1337); + assert_eq!(PalletBalances::free_balance(&BOB), 100_000); }) } From 0e92d6f6b0abc018c0e84a09e498fb1ccba323e4 Mon Sep 17 00:00:00 2001 From: Otavio Migliavacca Madalosso Date: Mon, 2 Dec 2024 09:40:14 -0300 Subject: [PATCH 3/5] pallet build with runtimefeatures working via: cargo build -p pallet-template --features=runtime-benchmarks --- Cargo.lock | 34 ----------- pallets/template/Cargo.toml | 8 +-- pallets/template/src/benchmarking.rs | 87 ++++++++++++++++++++++++---- pallets/template/src/impls.rs | 22 ++++--- pallets/template/src/lib.rs | 53 ++++++++++------- pallets/template/src/mock.rs | 54 ++++------------- pallets/template/src/tests.rs | 11 ++-- runtime/src/configs/mod.rs | 5 +- 8 files changed, 141 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3496417..34f450e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5225,7 +5225,6 @@ dependencies = [ "frame-system", "pallet-balances", "parity-scale-codec", - "polkadot-sdk-frame", "scale-info", "sp-core", "sp-io", @@ -5576,39 +5575,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" -[[package]] -name = "polkadot-sdk-frame" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdeb15ce08142082461afe1a62c15f7ce10a731d91b203ad6a8dc8d2e4a6a54" -dependencies = [ - "docify", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "log", - "parity-scale-codec", - "scale-info", - "sp-api", - "sp-arithmetic", - "sp-block-builder", - "sp-consensus-aura", - "sp-consensus-grandpa", - "sp-core", - "sp-inherents", - "sp-io", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-storage", - "sp-transaction-pool", - "sp-version", -] - [[package]] name = "polkavm" version = "0.9.3" diff --git a/pallets/template/Cargo.toml b/pallets/template/Cargo.toml index bfbe5ea..cf69a71 100644 --- a/pallets/template/Cargo.toml +++ b/pallets/template/Cargo.toml @@ -19,22 +19,20 @@ codec = { features = [ scale-info = { features = [ "derive", ], workspace = true } -pallet-balances.workspace = true -frame = { version = "0.7.0", package = "polkadot-sdk-frame", default-features = false, features = ["experimental", "runtime"] } frame-benchmarking = { optional = true, workspace = true } frame-support.workspace = true frame-system.workspace = true +sp-io = { workspace = true } +sp-runtime = { workspace = true } [dev-dependencies] sp-core = { default-features = true, workspace = true } -sp-io = { default-features = true, workspace = true } -sp-runtime = { default-features = true, workspace = true } +pallet-balances = { default-features = true, workspace = true } [features] default = ["std"] std = [ "codec/std", - "frame/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", diff --git a/pallets/template/src/benchmarking.rs b/pallets/template/src/benchmarking.rs index c1a5357..c53e194 100644 --- a/pallets/template/src/benchmarking.rs +++ b/pallets/template/src/benchmarking.rs @@ -3,8 +3,10 @@ use super::*; #[allow(unused)] -use crate::Pallet as Template; +use crate::Pallet as Collectables; use frame_benchmarking::v2::*; +use frame_support::traits::fungible::Inspect; +use frame_support::traits::fungible::Mutate; use frame_system::RawOrigin; #[benchmarks] @@ -12,24 +14,89 @@ mod benchmarks { use super::*; #[benchmark] - fn do_something() { - let value = 100u32; + fn create_kitty() { let caller: T::AccountId = whitelisted_caller(); + #[extrinsic_call] - do_something(RawOrigin::Signed(caller), value); + create_kitty(RawOrigin::Signed(caller.clone())); + + let count = CountForKitties::::get(); + assert_eq!(count, 1); + + let owned = KittiesOwned::::get(caller); + assert_eq!(owned.len(), 1); + } + + #[benchmark] + fn transfer() { + let caller: T::AccountId = whitelisted_caller(); + let recipient: T::AccountId = account("bob", 0, 0); + + Pallet::::create_kitty(RawOrigin::Signed(caller.clone()).into()).unwrap(); + let kitty_id = KittiesOwned::::get(caller.clone())[0]; + + #[extrinsic_call] + transfer( + RawOrigin::Signed(caller.clone()), + recipient.clone(), + kitty_id, + ); + + let recipient_owned = KittiesOwned::::get(recipient.clone()); + assert_eq!(recipient_owned.len(), 1); + assert_eq!(recipient_owned[0], kitty_id); - assert_eq!(Something::::get(), Some(value)); + let caller_owned = KittiesOwned::::get(caller.clone()); + assert_eq!(caller_owned.len(), 0); } #[benchmark] - fn cause_error() { - Something::::put(100u32); + fn set_price() { let caller: T::AccountId = whitelisted_caller(); + let price: BalanceOf = 100u32.into(); + + Pallet::::create_kitty(RawOrigin::Signed(caller.clone()).into()).unwrap(); + let kitty_id = KittiesOwned::::get(caller.clone())[0]; + assert_eq!(Kitties::::get(kitty_id).unwrap().price, None); + #[extrinsic_call] - cause_error(RawOrigin::Signed(caller)); + set_price(RawOrigin::Signed(caller.clone()), kitty_id, Some(price)); + assert_eq!(Kitties::::get(kitty_id).unwrap().price, Some(price)); + } + + #[benchmark] + fn buy_kitty() -> Result<(), BenchmarkError> { + let seller: T::AccountId = whitelisted_caller(); + let buyer: T::AccountId = account("bob", 0, 0); + + let ed = T::NativeCurrency::minimum_balance(); + let price: BalanceOf = 100u32.into(); + let balance: BalanceOf = ed + price * 2u32.into(); + + T::NativeCurrency::mint_into(&buyer, balance)?; + T::NativeCurrency::mint_into(&seller, ed)?; + + Pallet::::create_kitty(RawOrigin::Signed(seller.clone()).into())?; + let kitty_id = KittiesOwned::::get(seller.clone())[0]; + Pallet::::set_price( + RawOrigin::Signed(seller.clone()).into(), + kitty_id, + Some(price), + )?; + + #[extrinsic_call] + buy_kitty(RawOrigin::Signed(buyer.clone()), kitty_id, price); + + let kitty = Kitties::::get(kitty_id).unwrap(); + assert_eq!(kitty.owner, buyer); + assert_eq!(kitty.price, None); - assert_eq!(Something::::get(), Some(101u32)); + Ok(()) } - impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); + impl_benchmark_test_suite!( + Template, + crate::tests::new_test_ext(), + crate::tests::TestRuntime + ); } diff --git a/pallets/template/src/impls.rs b/pallets/template/src/impls.rs index 065fdb6..510c2ac 100644 --- a/pallets/template/src/impls.rs +++ b/pallets/template/src/impls.rs @@ -1,6 +1,9 @@ use super::*; -use frame::primitives::BlakeTwo256; -use frame::traits::{Currency, ExistenceRequirement::KeepAlive, Hash}; +use codec::Encode; +use frame_support::pallet_prelude::*; +use frame_support::traits::fungible::Mutate; +use frame_support::traits::tokens::Preservation; +use sp_io::hashing::blake2_256; impl Pallet { pub fn gen_dna() -> [u8; 32] { @@ -10,8 +13,8 @@ impl Pallet { frame_system::Pallet::::extrinsic_index(), CountForKitties::::get(), ); - let hash: [u8; 32] = BlakeTwo256::hash_of(&unique_payload).into(); - return hash; + let serialized_payload = unique_payload.encode(); + blake2_256(&serialized_payload) } pub fn do_transfer(from: T::AccountId, to: T::AccountId, dna: [u8; 32]) -> DispatchResult { @@ -133,7 +136,7 @@ impl Pallet { pub fn do_set_price( from: T::AccountId, kitty_id: [u8; 32], - price: Option, + price: Option>, ) -> DispatchResult { let mut kitty = Kitties::::get(kitty_id).ok_or(Error::::NoKitty)?; ensure!(kitty.owner == from, Error::::NotOwner); @@ -153,7 +156,7 @@ impl Pallet { pub fn do_buy_kitty( buyer: T::AccountId, kitty_id: [u8; 32], - max_price: T::Balance, + max_price: BalanceOf, ) -> DispatchResult { let buyer_address = buyer.clone(); // Question: Really necessary to check the existence of kitty_id if calling do_transfer (which already do that?) @@ -170,12 +173,7 @@ impl Pallet { None => return Err(Error::::NotForSale.into()), }; - // - // TODO:inspect pallet, look for transfer function - // let saldo = pallet_balances::Pallet::::free_balance(&buyer); - // pallet_balances::Pallet::::transfer( - pallet_balances::Pallet::::transfer(&buyer, &kitty.owner, price, KeepAlive)?; - // T::NativeBalance::transfer(&buyer, &kitty.owner, price, Preservation::Preserve)?; + T::NativeCurrency::transfer(&buyer, &kitty.owner, price, Preservation::Preserve)?; // maybe refactor to accept &mut buyer? ownership move cause `buyer_address` Self::do_transfer(kitty.owner, buyer.clone(), kitty_id)?; diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs index 92b495b..74bb1c9 100644 --- a/pallets/template/src/lib.rs +++ b/pallets/template/src/lib.rs @@ -1,20 +1,20 @@ #![cfg_attr(not(feature = "std"), no_std)] -// Re-export pallet items so that they can be accessed from the crate namespace. -use frame::prelude::*; -pub use pallet::*; - -// FRAME pallets require their own "mock runtimes" to be able to run unit tests. This module -// contains a mock runtime specific for testing this pallet's functionality. -#[cfg(test)] -mod mock; - // This module contains the unit tests for this pallet. // Learn about pallet unit testing here: https://docs.substrate.io/test/unit-testing/ // #[cfg(test)] mod impls; + +// FRAME pallets require their own "mock runtimes" to be able to run unit tests. This module +// contains a mock runtime specific for testing this pallet's functionality. +mod mock; +#[cfg(test)] mod tests; +// Re-export pallet items so that they can be accessed from the crate namespace. +// use frame::prelude::*; +pub use pallet::*; + // Every callable function or "dispatchable" a pallet exposes must have weight values that correctly // estimate a dispatchable's execution time. The benchmarking module is used to calculate weights // for each dispatchable and generates this pallet's weight.rs file. Learn more about benchmarking here: https://docs.substrate.io/test/benchmark/ @@ -24,11 +24,19 @@ pub mod weights; pub use weights::*; // All pallet logic is defined in its own module and must be annotated by the `pallet` attribute. -// #[frame_support::pallet] -#[frame::pallet(dev_mode)] +#[frame_support::pallet] pub mod pallet { // Import various useful types required by all FRAME pallets. use super::*; + use frame_support::{ + pallet_prelude::*, + traits::fungible::{Inspect, Mutate}, + Blake2_128Concat, + }; + use frame_system::pallet_prelude::*; + + pub type BalanceOf = + <::NativeCurrency as Inspect<::AccountId>>::Balance; // The `Pallet` struct serves as a placeholder to implement traits, methods and dispatchables // (`Call`s) in this pallet. @@ -42,10 +50,11 @@ pub mod pallet { /// These types are defined generically and made concrete when the pallet is declared in the /// `runtime/src/lib.rs` file of your chain. #[pallet::config] - pub trait Config: frame_system::Config + pallet_balances::Config { + pub trait Config: frame_system::Config { /// The overarching runtime event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; type WeightInfo: WeightInfo; + type NativeCurrency: Inspect + Mutate; } #[derive(Encode, Decode, TypeInfo, MaxEncodedLen)] @@ -53,7 +62,7 @@ pub mod pallet { pub struct Kitty { pub dna: [u8; 32], pub owner: T::AccountId, - pub price: Option, + pub price: Option>, } /// A storage item for this pallet. /// @@ -66,13 +75,15 @@ pub mod pallet { pub(super) type CountForKitties = StorageValue; #[pallet::storage] - pub(super) type Kitties = StorageMap>; + pub(super) type Kitties = StorageMap<_, Blake2_128Concat, [u8; 32], Kitty>; #[pallet::storage] pub(super) type KittiesOwned = StorageMap< - Key = T::AccountId, - Value = BoundedVec<[u8; 32], ConstU32<100>>, - QueryKind = ValueQuery, + _, + Blake2_128Concat, + T::AccountId, + BoundedVec<[u8; 32], ConstU32<100>>, + ValueQuery, >; /// Events that functions in this pallet can emit. @@ -107,12 +118,12 @@ pub mod pallet { PriceSet { owner: T::AccountId, kitty_id: [u8; 32], - new_price: Option, + new_price: Option>, }, Sold { buyer: T::AccountId, kitty_id: [u8; 32], - price: T::Balance, + price: BalanceOf, }, } @@ -233,7 +244,7 @@ pub mod pallet { pub fn set_price( origin: OriginFor, kitty_id: [u8; 32], - price: Option, + price: Option>, ) -> DispatchResult { let from = ensure_signed(origin)?; @@ -246,7 +257,7 @@ pub mod pallet { pub fn buy_kitty( origin: OriginFor, kitty_id: [u8; 32], - max_price: T::Balance, + max_price: BalanceOf, ) -> DispatchResult { let from = ensure_signed(origin)?; Self::do_buy_kitty(from, kitty_id, max_price)?; diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs index d9d79ff..06652c0 100644 --- a/pallets/template/src/mock.rs +++ b/pallets/template/src/mock.rs @@ -1,67 +1,35 @@ #![cfg(test)] -use crate::*; -use crate::{self as pallet_kitties}; -use frame::deps::frame_support::runtime; -use frame::deps::sp_io; -use frame::runtime::prelude::*; -use frame::testing_prelude::*; +use crate as pallet_kitties; +use frame_support::{construct_runtime, derive_impl}; +use sp_runtime::BuildStorage; type Balance = u64; type Block = frame_system::mocking::MockBlock; -#[runtime] -mod runtime { - #[runtime::derive( - RuntimeCall, - RuntimeEvent, - RuntimeError, - RuntimeOrigin, - RuntimeTask, - RuntimeFreezeReason, - RuntimeHoldReason - )] - #[runtime::runtime] - /// The "test runtime" that represents the state transition function for our blockchain. - /// - /// The runtime is composed of individual modules called "pallets", which you find see below. - /// Each pallet has its own logic and storage, all of which can be combined together. - pub struct TestRuntime; - - /// System: Mandatory system pallet that should always be included in a FRAME runtime. - #[runtime::pallet_index(0)] - pub type System = frame_system::Pallet; - - /// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot) - #[runtime::pallet_index(1)] - pub type PalletBalances = pallet_balances::Pallet; - - /// PalletKitties: The pallet you are building in this tutorial! - #[runtime::pallet_index(2)] - pub type PalletKitties = pallet_kitties::Pallet; +construct_runtime! { + pub struct TestRuntime { + System: frame_system, + PalletBalances: pallet_balances, + PalletKitties: pallet_kitties, + } } - -// Normally `System` would have many more configurations, but you can see that we use some macro -// magic to automatically configure most of the pallet for a "default test configuration". #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for TestRuntime { type Block = Block; type AccountData = pallet_balances::AccountData; } -// Normally `pallet_balances` would have many more configurations, but you can see that we use some -// macro magic to automatically configure most of the pallet for a "default test configuration". #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] impl pallet_balances::Config for TestRuntime { type AccountStore = System; type Balance = Balance; } -// This is the configuration of our Pallet! If you make changes to the pallet's `trait Config`, you -// will also need to update this configuration to represent that. impl pallet_kitties::Config for TestRuntime { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); // TODO: investigate why this works + type NativeCurrency = PalletBalances; + type WeightInfo = (); } // We need to run most of our tests using this function: `new_test_ext().execute_with(|| { ... });` diff --git a/pallets/template/src/tests.rs b/pallets/template/src/tests.rs index f70fe94..5a00bc5 100644 --- a/pallets/template/src/tests.rs +++ b/pallets/template/src/tests.rs @@ -13,12 +13,11 @@ use crate::mock::{new_test_ext, RuntimeEvent, RuntimeOrigin, TestRuntime}; use crate::*; -// use frame::deps::frame_support::runtime; -// use frame::deps::sp_io; -// use frame::runtime::prelude::*; -use frame::testing_prelude::*; +use codec::{Decode, Encode, MaxEncodedLen}; +use frame_support::{assert_noop, assert_ok}; use mock::{PalletBalances, PalletKitties, System}; -// use frame::traits::fungible::*; +use scale_info::TypeInfo; +use sp_runtime::{ArithmeticError, DispatchError}; type Balance = u64; type Block = frame_system::mocking::MockBlock; @@ -439,7 +438,7 @@ fn do_buy_kitty_logic_works() { // Cannot buy kitty if you don't have the funds. assert_noop!( PalletKitties::buy_kitty(RuntimeOrigin::signed(BOB), kitty_id, 1337), - frame::arithmetic::ArithmeticError::Underflow + ArithmeticError::Underflow ); // Cannot buy kitty if it would kill your account (i.e. set your balance to 0). // assert_ok!(PalletBalances::mint_into(&BOB, 1337)); diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index d2a03a7..fb71571 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -26,7 +26,7 @@ // Substrate and Polkadot dependencies use frame_support::{ derive_impl, parameter_types, - traits::{fungible, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, VariantCountOf}, + traits::{ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, VariantCountOf}, weights::{ constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND}, IdentityFee, Weight, @@ -158,5 +158,6 @@ impl pallet_sudo::Config for Runtime { /// Configure the pallet-template in pallets/template. impl pallet_template::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); + type NativeCurrency = pallet_balances::Pallet; + type WeightInfo = pallet_template::weights::SubstrateWeight; } From 3291b19b4d3a55cf59840cf607dc395a3a26e780 Mon Sep 17 00:00:00 2001 From: Otavio Migliavacca Madalosso Date: Mon, 2 Dec 2024 09:48:11 -0300 Subject: [PATCH 4/5] at last, benchmark execution and weights generation --- pallets/template/src/weights.rs | 168 ++++++++++++++++++++++---------- 1 file changed, 118 insertions(+), 50 deletions(-) diff --git a/pallets/template/src/weights.rs b/pallets/template/src/weights.rs index 7c42936..b9757ee 100644 --- a/pallets/template/src/weights.rs +++ b/pallets/template/src/weights.rs @@ -1,90 +1,158 @@ -//! Autogenerated weights for pallet_template +//! Autogenerated weights for `pallet_template` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 +//! DATE: 2024-12-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Alexs-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `madalosso`, CPU: `12th Gen Intel(R) Core(TM) i5-12400` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ../../target/release/node-template +// ./target/debug/solochain-template-node // benchmark // pallet -// --chain -// dev // --pallet // pallet_template -// --extrinsic -// * -// --steps=50 -// --repeat=20 -// --wasm-execution=compiled +// --extrinsic=* +// --chain=dev // --output // pallets/template/src/weights.rs // --template -// ../../.maintain/frame-weight-template.hbs +// .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_template. +/// Weight functions needed for `pallet_template`. pub trait WeightInfo { - fn do_something() -> Weight; - fn cause_error() -> Weight; + fn create_kitty() -> Weight; + fn transfer() -> Weight; + fn set_price() -> Weight; + fn buy_kitty() -> Weight; } -/// Weights for pallet_template using the Substrate node and recommended hardware. +/// Weights for `pallet_template` using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn do_something() -> Weight { + /// Storage: `System::ParentHash` (r:1 w:0) + /// Proof: `System::ParentHash` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::CountForKitties` (r:1 w:1) + /// Proof: `TemplateModule::CountForKitties` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::KittiesOwned` (r:1 w:1) + /// Proof: `TemplateModule::KittiesOwned` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + fn create_kitty() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `6` + // Estimated: `6715` + // Minimum execution time: 341_959_000 picoseconds. + Weight::from_parts(347_033_000, 6715) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::KittiesOwned` (r:2 w:2) + /// Proof: `TemplateModule::KittiesOwned` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + fn transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `276` + // Estimated: `12440` + // Minimum execution time: 415_390_000 picoseconds. + Weight::from_parts(421_422_000, 12440) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn cause_error() -> Weight { + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + fn set_price() -> Weight { // Proof Size summary in bytes: - // Measured: `32` - // Estimated: `1489` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_000_000, 1489) + // Measured: `204` + // Estimated: `3594` + // Minimum execution time: 232_735_000 picoseconds. + Weight::from_parts(245_175_000, 3594) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::KittiesOwned` (r:2 w:2) + /// Proof: `TemplateModule::KittiesOwned` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + fn buy_kitty() -> Weight { + // Proof Size summary in bytes: + // Measured: `395` + // Estimated: `12440` + // Minimum execution time: 1_287_200_000 picoseconds. + Weight::from_parts(1_315_892_000, 12440) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } } -// For backwards compatibility and tests +// For backwards compatibility and tests. impl WeightInfo for () { - /// Storage: TemplateModule Something (r:0 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn do_something() -> Weight { + /// Storage: `System::ParentHash` (r:1 w:0) + /// Proof: `System::ParentHash` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::CountForKitties` (r:1 w:1) + /// Proof: `TemplateModule::CountForKitties` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::KittiesOwned` (r:1 w:1) + /// Proof: `TemplateModule::KittiesOwned` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + fn create_kitty() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 8_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Measured: `6` + // Estimated: `6715` + // Minimum execution time: 341_959_000 picoseconds. + Weight::from_parts(347_033_000, 6715) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } - /// Storage: TemplateModule Something (r:1 w:1) - /// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn cause_error() -> Weight { + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::KittiesOwned` (r:2 w:2) + /// Proof: `TemplateModule::KittiesOwned` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + fn transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `32` - // Estimated: `1489` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_000_000, 1489) + // Measured: `276` + // Estimated: `12440` + // Minimum execution time: 415_390_000 picoseconds. + Weight::from_parts(421_422_000, 12440) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + fn set_price() -> Weight { + // Proof Size summary in bytes: + // Measured: `204` + // Estimated: `3594` + // Minimum execution time: 232_735_000 picoseconds. + Weight::from_parts(245_175_000, 3594) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} + /// Storage: `TemplateModule::Kitties` (r:1 w:1) + /// Proof: `TemplateModule::Kitties` (`max_values`: None, `max_size`: Some(129), added: 2604, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `TemplateModule::KittiesOwned` (r:2 w:2) + /// Proof: `TemplateModule::KittiesOwned` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + fn buy_kitty() -> Weight { + // Proof Size summary in bytes: + // Measured: `395` + // Estimated: `12440` + // Minimum execution time: 1_287_200_000 picoseconds. + Weight::from_parts(1_315_892_000, 12440) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } +} \ No newline at end of file From 4c9995e5ff07b27a3a5e6fe3a3b0cc2793031b52 Mon Sep 17 00:00:00 2001 From: Otavio Migliavacca Madalosso Date: Mon, 2 Dec 2024 16:27:49 -0300 Subject: [PATCH 5/5] generate benchmark -> Weights --- pallets/template/src/lib.rs | 59 +++------------------------------ pallets/template/src/weights.rs | 34 +++++++++---------- 2 files changed, 21 insertions(+), 72 deletions(-) diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs index 74bb1c9..d06332c 100644 --- a/pallets/template/src/lib.rs +++ b/pallets/template/src/lib.rs @@ -167,59 +167,8 @@ pub mod pallet { impl Pallet { /// An example dispatchable that takes a single u32 value as a parameter, writes the value /// to storage and emits an event. - /// - /// It checks that the _origin_ for this call is _Signed_ and returns a dispatch - /// error if it isn't. Learn more about origins here: - // #[pallet::call_index(0)] - // #[pallet::weight(::WeightInfo::do_something())] - // pub fn do_somethingsometihng(origin: OriginFor, something: u32) -> DispatchResult { - // // Check that the extrinsic was signed and get the signer. - // let who = ensure_signed(origin)?; - - // // Update storage. - // Something::::put(something); - - // // Emit an event. - // Self::deposit_event(Event::SomethingStored { something, who }); - - // // Return a successful `DispatchResult` - // Ok(()) - // } - - /// An example dispatchable that may throw a custom error. - /// - /// It checks that the caller is a signed origin and reads the current value from the - /// `Something` storage item. If a current value exists, it is incremented by 1 and then - /// written back to storage. - /// - /// ## Errors - /// - /// The function will return an error under the following conditions: - /// - /// - If no value has been set ([`Error::NoneValue`]) - /// - If incrementing the value in storage causes an arithmetic overflow - /// ([`Error::StorageOverflow`]) - // #[pallet::call_index(1)] - // // #[pallet::weight(T::WeightInfo::do_something())] - // pub fn cause_error(origin: OriginFor) -> DispatchResult { - // let _who = ensure_signed(origin)?; - - // // Read a value from storage. - // match Something::::get() { - // // Return an error if the value has not been set. - // None => Err(Error::::NoneValue.into()), - // Some(old) => { - // // Increment the value read from storage. This will cause an error in the event - // // of overflow. - // let new = old.checked_add(1).ok_or(Error::::StorageOverflow)?; - // // Update the value in storage with the incremented result. - // Something::::put(new); - // Ok(()) - // } - // } - // } #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::do_something())] + #[pallet::weight(::WeightInfo::create_kitty())] pub fn create_kitty(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; let dna = Self::gen_dna(); @@ -228,7 +177,7 @@ pub mod pallet { } #[pallet::call_index(1)] - #[pallet::weight(::WeightInfo::do_something())] + #[pallet::weight(::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, to: T::AccountId, @@ -240,7 +189,7 @@ pub mod pallet { } #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::do_something())] + #[pallet::weight(::WeightInfo::set_price())] pub fn set_price( origin: OriginFor, kitty_id: [u8; 32], @@ -253,7 +202,7 @@ pub mod pallet { } #[pallet::call_index(3)] - #[pallet::weight(::WeightInfo::do_something())] + #[pallet::weight(::WeightInfo::buy_kitty())] pub fn buy_kitty( origin: OriginFor, kitty_id: [u8; 32], diff --git a/pallets/template/src/weights.rs b/pallets/template/src/weights.rs index b9757ee..8266b96 100644 --- a/pallets/template/src/weights.rs +++ b/pallets/template/src/weights.rs @@ -8,7 +8,7 @@ //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ./target/debug/solochain-template-node +// ./target/release/solochain-template-node // benchmark // pallet // --pallet @@ -51,8 +51,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6` // Estimated: `6715` - // Minimum execution time: 341_959_000 picoseconds. - Weight::from_parts(347_033_000, 6715) + // Minimum execution time: 30_456_000 picoseconds. + Weight::from_parts(35_149_000, 6715) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -64,8 +64,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `276` // Estimated: `12440` - // Minimum execution time: 415_390_000 picoseconds. - Weight::from_parts(421_422_000, 12440) + // Minimum execution time: 39_397_000 picoseconds. + Weight::from_parts(43_902_000, 12440) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -75,8 +75,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `204` // Estimated: `3594` - // Minimum execution time: 232_735_000 picoseconds. - Weight::from_parts(245_175_000, 3594) + // Minimum execution time: 23_713_000 picoseconds. + Weight::from_parts(25_505_000, 3594) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -90,8 +90,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `395` // Estimated: `12440` - // Minimum execution time: 1_287_200_000 picoseconds. - Weight::from_parts(1_315_892_000, 12440) + // Minimum execution time: 97_203_000 picoseconds. + Weight::from_parts(121_916_000, 12440) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -111,8 +111,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6` // Estimated: `6715` - // Minimum execution time: 341_959_000 picoseconds. - Weight::from_parts(347_033_000, 6715) + // Minimum execution time: 30_456_000 picoseconds. + Weight::from_parts(35_149_000, 6715) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -124,8 +124,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `276` // Estimated: `12440` - // Minimum execution time: 415_390_000 picoseconds. - Weight::from_parts(421_422_000, 12440) + // Minimum execution time: 39_397_000 picoseconds. + Weight::from_parts(43_902_000, 12440) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -135,8 +135,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `204` // Estimated: `3594` - // Minimum execution time: 232_735_000 picoseconds. - Weight::from_parts(245_175_000, 3594) + // Minimum execution time: 23_713_000 picoseconds. + Weight::from_parts(25_505_000, 3594) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -150,8 +150,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `395` // Estimated: `12440` - // Minimum execution time: 1_287_200_000 picoseconds. - Weight::from_parts(1_315_892_000, 12440) + // Minimum execution time: 97_203_000 picoseconds. + Weight::from_parts(121_916_000, 12440) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) }