difftreelog
feat(common) benchmarking
in: master
3 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -1 +1,91 @@
-#![cfg(feature = "runtime-benchmarking")]
+use sp_std::vec::Vec;
+use crate::{Config, CollectionHandle};
+use nft_data_structs::{
+ CollectionMode, Collection, CollectionId, MAX_COLLECTION_NAME_LENGTH,
+ MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, OFFCHAIN_SCHEMA_LIMIT,
+ VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,
+};
+use frame_support::traits::{Currency, Get};
+use core::convert::TryInto;
+use sp_runtime::DispatchError;
+
+pub fn create_data(size: usize) -> Vec<u8> {
+ (0..size).map(|v| (v & 0xff) as u8).collect()
+}
+pub fn create_u16_data(size: usize) -> Vec<u16> {
+ (0..size).map(|v| (v & 0xffff) as u16).collect()
+}
+
+pub fn create_collection_raw<T: Config, R>(
+ owner: T::AccountId,
+ mode: CollectionMode,
+ handler: impl FnOnce(Collection<T>) -> Result<CollectionId, DispatchError>,
+ cast: impl FnOnce(CollectionHandle<T>) -> R,
+) -> Result<R, DispatchError> {
+ T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
+ let name = create_u16_data(MAX_COLLECTION_NAME_LENGTH)
+ .try_into()
+ .unwrap();
+ let description = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH)
+ .try_into()
+ .unwrap();
+ let token_prefix = create_data(MAX_TOKEN_PREFIX_LENGTH).try_into().unwrap();
+ let offchain_schema = create_data(OFFCHAIN_SCHEMA_LIMIT as usize)
+ .try_into()
+ .unwrap();
+ let variable_on_chain_schema = create_data(VARIABLE_ON_CHAIN_SCHEMA_LIMIT as usize)
+ .try_into()
+ .unwrap();
+ let const_on_chain_schema = create_data(CONST_ON_CHAIN_SCHEMA_LIMIT as usize)
+ .try_into()
+ .unwrap();
+ handler(Collection {
+ owner,
+ mode,
+ access: Default::default(),
+ name,
+ description,
+ token_prefix,
+ mint_mode: true,
+ offchain_schema,
+ schema_version: Default::default(),
+ sponsorship: Default::default(),
+ limits: Default::default(),
+ variable_on_chain_schema,
+ const_on_chain_schema,
+ meta_update_permission: Default::default(),
+ transfers_enabled: true,
+ })
+ .and_then(CollectionHandle::try_get)
+ .map(cast)
+}
+
+#[macro_export]
+macro_rules! bench_init {
+ ($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {
+ let $name: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);
+ bench_init!($($rest)*);
+ };
+ ($name:ident: collection($owner:ident); $($rest:tt)*) => {
+ let $name = create_collection::<T>($owner.clone())?;
+ bench_init!($($rest)*);
+ };
+ ($name:ident: cross; $($rest:tt)*) => {
+ let $name = T::CrossAccountId::from_sub($name);
+ bench_init!($($rest)*);
+ };
+ ($name:ident: cross_sub $(($id:expr))?; $($rest:tt)*) => {
+ let account: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);
+ let $name = T::CrossAccountId::from_sub(account);
+ bench_init!($($rest)*);
+ };
+ ($name:ident: cross_from_sub; $($rest:tt)*) => {
+ let $name = T::CrossAccountId::from_sub($name);
+ bench_init!($($rest)*);
+ };
+ ($name:ident: cross_from_sub($from:ident); $($rest:tt)*) => {
+ let $name = T::CrossAccountId::from_sub($from);
+ bench_init!($($rest)*);
+ };
+ () => {}
+}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -17,6 +17,7 @@
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
pub mod account;
+#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod erc;
pub mod eth;
pallets/nft/Cargo.tomldiffbeforeafterboth1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Substrate node nft'7edition = '2018'8homepage = 'https://unique.network'9license = 'All Rights Reserved'10name = 'pallet-nft'11repository = 'https://github.com/usetech-llc/nft_private/'12version = '3.0.0'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = ['frame-benchmarking']20std = [21 'codec/std',22 'serde/std',23 'frame-support/std',24 'frame-system/std',25 'pallet-balances/std',26 'pallet-evm/std',27 'pallet-timestamp/std',28 'pallet-randomness-collective-flip/std',29 'pallet-transaction-payment/std',30 'pallet-common/std',31 'pallet-fungible/std',32 'pallet-nonfungible/std',33 'pallet-refungible/std',34 'fp-evm/std',35 'nft-data-structs/std',36 'up-sponsorship/std',37 'sp-std/std',38 'sp-api/std',39 'sp-runtime/std',40 'frame-benchmarking/std',41 'ethereum/std',42 'rlp/std',4344 'primitive-types/std',45 'evm-coder/std',46 'pallet-evm-coder-substrate/std',47]48limit-testing = ["nft-data-structs/limit-testing"]4950################################################################################51# Substrate Dependencies5253[dependencies.codec]54default-features = false55features = ['derive']56package = 'parity-scale-codec'57version = '2.3.0'5859[dependencies.frame-benchmarking]60default-features = false61optional = true62git = 'https://github.com/paritytech/substrate.git'63branch = 'polkadot-v0.9.10'64version = '4.0.0-dev'6566[dependencies.frame-support]67default-features = false68git = 'https://github.com/paritytech/substrate.git'69branch = 'polkadot-v0.9.10'70version = '4.0.0-dev'7172[dependencies.frame-system]73default-features = false74git = 'https://github.com/paritytech/substrate.git'75branch = 'polkadot-v0.9.10'76version = '4.0.0-dev'7778[dependencies.pallet-balances]79default-features = false80git = 'https://github.com/paritytech/substrate.git'81branch = 'polkadot-v0.9.10'82version = '4.0.0-dev'8384[dependencies.pallet-timestamp]85default-features = false86git = 'https://github.com/paritytech/substrate.git'87branch = 'polkadot-v0.9.10'88version = '4.0.0-dev'8990[dependencies.pallet-randomness-collective-flip]91default-features = false92git = 'https://github.com/paritytech/substrate.git'93branch = 'polkadot-v0.9.10'94version = '4.0.0-dev'9596[dependencies.sp-std]97default-features = false98git = 'https://github.com/paritytech/substrate.git'99branch = 'polkadot-v0.9.10'100version = '4.0.0-dev'101102[dependencies.pallet-transaction-payment]103default-features = false104git = 'https://github.com/paritytech/substrate.git'105branch = 'polkadot-v0.9.10'106version = '4.0.0-dev'107108[dependencies.serde]109default-features = false110features = ['derive']111version = '1.0.130'112113[dependencies.sp-runtime]114default-features = false115git = 'https://github.com/paritytech/substrate.git'116branch = 'polkadot-v0.9.10'117version = '4.0.0-dev'118119[dependencies.sp-core]120default-features = false121git = 'https://github.com/paritytech/substrate.git'122branch = 'polkadot-v0.9.10'123version = '4.0.0-dev'124125[dependencies.sp-io]126default-features = false127git = 'https://github.com/paritytech/substrate.git'128branch = 'polkadot-v0.9.10'129version = '4.0.0-dev'130131132################################################################################133# Local Dependencies134135[dependencies.nft-data-structs]136default-features = false137path = '../../primitives/nft'138version = '0.9.0'139140[dependencies.up-sponsorship]141default-features = false142path = '../../primitives/sponsorship'143version = '0.1.0'144145146[dependencies]147ethereum = { default-features = false, version = "0.9.0" }148rlp = { default-features = false, version = "0.5.0" }149sp-api = { default-features = false, version = '4.0.0-dev', git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.10" }150151evm-coder = { default-features = false, path = "../../crates/evm-coder" }152pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }153primitive-types = { version = "0.10.1", default-features = false, features = [154 "serde_no_std",155] }156157pallet-evm = { default-features = false, version = "6.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }158pallet-ethereum = { default-features = false, version = "4.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }159fp-evm = { default-features = false, version = '3.0.0-dev', git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }160hex-literal = "0.3.3"161162pallet-common = { default-features = false, path = "../common" }163pallet-fungible = { default-features = false, path = "../fungible" }164pallet-nonfungible = { default-features = false, path = "../nonfungible" }165pallet-refungible = { default-features = false, path = "../refungible" }1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Substrate node nft'7edition = '2018'8homepage = 'https://unique.network'9license = 'All Rights Reserved'10name = 'pallet-nft'11repository = 'https://github.com/usetech-llc/nft_private/'12version = '3.0.0'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = [20 'frame-benchmarking',21 'pallet-common/runtime-benchmarks',22]23std = [24 'codec/std',25 'serde/std',26 'frame-support/std',27 'frame-system/std',28 'pallet-balances/std',29 'pallet-evm/std',30 'pallet-timestamp/std',31 'pallet-randomness-collective-flip/std',32 'pallet-transaction-payment/std',33 'pallet-common/std',34 'pallet-fungible/std',35 'pallet-nonfungible/std',36 'pallet-refungible/std',37 'fp-evm/std',38 'nft-data-structs/std',39 'up-sponsorship/std',40 'sp-std/std',41 'sp-api/std',42 'sp-runtime/std',43 'frame-benchmarking/std',44 'ethereum/std',45 'rlp/std',4647 'primitive-types/std',48 'evm-coder/std',49 'pallet-evm-coder-substrate/std',50]51limit-testing = ["nft-data-structs/limit-testing"]5253################################################################################54# Substrate Dependencies5556[dependencies.codec]57default-features = false58features = ['derive']59package = 'parity-scale-codec'60version = '2.3.0'6162[dependencies.frame-benchmarking]63default-features = false64optional = true65git = 'https://github.com/paritytech/substrate.git'66branch = 'polkadot-v0.9.10'67version = '4.0.0-dev'6869[dependencies.frame-support]70default-features = false71git = 'https://github.com/paritytech/substrate.git'72branch = 'polkadot-v0.9.10'73version = '4.0.0-dev'7475[dependencies.frame-system]76default-features = false77git = 'https://github.com/paritytech/substrate.git'78branch = 'polkadot-v0.9.10'79version = '4.0.0-dev'8081[dependencies.pallet-balances]82default-features = false83git = 'https://github.com/paritytech/substrate.git'84branch = 'polkadot-v0.9.10'85version = '4.0.0-dev'8687[dependencies.pallet-timestamp]88default-features = false89git = 'https://github.com/paritytech/substrate.git'90branch = 'polkadot-v0.9.10'91version = '4.0.0-dev'9293[dependencies.pallet-randomness-collective-flip]94default-features = false95git = 'https://github.com/paritytech/substrate.git'96branch = 'polkadot-v0.9.10'97version = '4.0.0-dev'9899[dependencies.sp-std]100default-features = false101git = 'https://github.com/paritytech/substrate.git'102branch = 'polkadot-v0.9.10'103version = '4.0.0-dev'104105[dependencies.pallet-transaction-payment]106default-features = false107git = 'https://github.com/paritytech/substrate.git'108branch = 'polkadot-v0.9.10'109version = '4.0.0-dev'110111[dependencies.serde]112default-features = false113features = ['derive']114version = '1.0.130'115116[dependencies.sp-runtime]117default-features = false118git = 'https://github.com/paritytech/substrate.git'119branch = 'polkadot-v0.9.10'120version = '4.0.0-dev'121122[dependencies.sp-core]123default-features = false124git = 'https://github.com/paritytech/substrate.git'125branch = 'polkadot-v0.9.10'126version = '4.0.0-dev'127128[dependencies.sp-io]129default-features = false130git = 'https://github.com/paritytech/substrate.git'131branch = 'polkadot-v0.9.10'132version = '4.0.0-dev'133134135################################################################################136# Local Dependencies137138[dependencies.nft-data-structs]139default-features = false140path = '../../primitives/nft'141version = '0.9.0'142143[dependencies.up-sponsorship]144default-features = false145path = '../../primitives/sponsorship'146version = '0.1.0'147148149[dependencies]150ethereum = { default-features = false, version = "0.9.0" }151rlp = { default-features = false, version = "0.5.0" }152sp-api = { default-features = false, version = '4.0.0-dev', git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.10" }153154evm-coder = { default-features = false, path = "../../crates/evm-coder" }155pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }156primitive-types = { version = "0.10.1", default-features = false, features = [157 "serde_no_std",158] }159160pallet-evm = { default-features = false, version = "6.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }161pallet-ethereum = { default-features = false, version = "4.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }162fp-evm = { default-features = false, version = '3.0.0-dev', git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }163hex-literal = "0.3.3"164165pallet-common = { default-features = false, path = "../common" }166pallet-fungible = { default-features = false, path = "../fungible" }167pallet-nonfungible = { default-features = false, path = "../nonfungible" }168pallet-refungible = { default-features = false, path = "../refungible" }