git.delta.rocks / unique-network / refs/commits / 278f1b9c8b83

difftreelog

feat(common) benchmarking

Yaroslav Bolyukin2021-10-22parent: #c8da6d5.patch.diff
in: master

3 files changed

modifiedpallets/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)*);
+	};
+	() => {}
+}
modifiedpallets/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;
modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
before · pallets/nft/Cargo.toml
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 = ['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" }