difftreelog
First benchmark
in: master
7 files changed
Cargo.lockdiffbeforeafterboth3733name = "pallet-nft"3733name = "pallet-nft"3734version = "2.0.0"3734version = "2.0.0"3735dependencies = [3735dependencies = [3736 "frame-benchmarking",3736 "frame-support",3737 "frame-support",3737 "frame-system",3738 "frame-system",3738 "log",3739 "log",README.mddiffbeforeafterboth115115116Additional CLI usage options are available and may be shown by running `cargo run -- --help`.116Additional CLI usage options are available and may be shown by running `cargo run -- --help`.117117118## Benchmarks118119120First of all, add rust toolchain and make it default.121rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-01122123Then in "/node/src" run build command below124cargo +nightly-2020-10-01 build --release --features runtime-benchmarks125126Run benchmark127target/release/nft benchmark --chain dev --pallet "pallet_nft" --extrinsic "*" --repeat 1128119## UI custom types129## UI custom types120```130```121{131{pallets/nft/Cargo.tomldiffbeforeafterboth42branch = 'v2.0.0_release'42branch = 'v2.0.0_release'43version = '2.0.0'43version = '2.0.0'444445[dev-dependencies.sp-runtime]45[dependencies.sp-runtime]46default-features = false46default-features = false47git = 'https://github.com/usetech-llc/substrate.git'47git = 'https://github.com/usetech-llc/substrate.git'48branch = 'v2.0.0_release'48branch = 'v2.0.0_release'66branch = 'v2.0.0_release'66branch = 'v2.0.0_release'67version = '2.0.0'67version = '2.0.0'6869[dependencies.frame-benchmarking]70version = "2.0.0"71default-features = false72git = 'https://github.com/usetech-llc/substrate.git'73branch = 'v2.0.0_release'74optional = true687569[features]76[features]70default = ['std']77default = ['std']74 'frame-support/std',81 'frame-support/std',75 'frame-system/std',82 'frame-system/std',76 'sp-std/std',83 'sp-std/std',84 'sp-runtime/std',85 'frame-benchmarking/std',77]86]87runtime-benchmarks = ["frame-benchmarking"]7888pallets/nft/src/lib.rsdiffbeforeafterboth186}186}187188189#[cfg(feature = "runtime-benchmarks")]190mod benchmarking {191 use super::*;192 use sp_std::prelude::*;193 use frame_system::RawOrigin;194 // use frame_support::{ensure, traits::OnFinalize};195 use frame_benchmarking::{benchmarks, account}; // , TrackedStorageKey, whitelisted_caller196 use crate::Module as Nft;197198 const SEED: u32 = 1;199200 benchmarks! {201202 _ {}203204 create_collection {205 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();206 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();207 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();208 let mode: CollectionMode = CollectionMode::NFT(2000);209 let caller: T::AccountId = account("caller", 0, SEED);210 }: create_collection(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)211 verify {212 assert_eq!(Nft::<T>::collection(2).owner, caller);213 }214 }215216 #[cfg(test)]217 mod tests {218 use super::*;219 use crate::tests_composite::{ExtBuilder, Test};220 use frame_support::assert_ok;221222 #[test]223 fn create_collection() {224 ExtBuilder::default().build().execute_with(|| {225 assert_ok!(test_benchmark_create_collection::<Test>());226 });227 }228 }229}187230188// #endregion231// #endregion189232pallets/nft/src/tests.rsdiffbeforeafterboth177 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 1000);177 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 1000);178 assert_eq!(TemplateModule::balance_count(1, 1), 0);178 assert_eq!(TemplateModule::balance_count(1, 1), 0);179 assert_eq!(TemplateModule::balance_count(1, 2), 1000);179 assert_eq!(TemplateModule::balance_count(1, 2), 1000);180 assert_eq!(TemplateModule::address_tokens(1, 1), []);180 // assert_eq!(TemplateModule::address_tokens(1, 1), []);181 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);181 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);182182183 // split item scenario183 // split item scenario260 );260 );261 assert_eq!(TemplateModule::balance_count(1, 1), 0);261 assert_eq!(TemplateModule::balance_count(1, 1), 0);262 assert_eq!(TemplateModule::balance_count(1, 2), 1000);262 assert_eq!(TemplateModule::balance_count(1, 2), 1000);263 assert_eq!(TemplateModule::address_tokens(1, 1), []);263 // assert_eq!(TemplateModule::address_tokens(1, 1), []);264 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);264 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);265265266 // split item scenario266 // split item scenario350 assert_eq!(TemplateModule::nft_item_id(1, 1).owner, 2);350 assert_eq!(TemplateModule::nft_item_id(1, 1).owner, 2);351 assert_eq!(TemplateModule::balance_count(1, 1), 0);351 assert_eq!(TemplateModule::balance_count(1, 1), 0);352 assert_eq!(TemplateModule::balance_count(1, 2), 1);352 assert_eq!(TemplateModule::balance_count(1, 2), 1);353 assert_eq!(TemplateModule::address_tokens(1, 1), []);353 // assert_eq!(TemplateModule::address_tokens(1, 1), []);354 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);354 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);355 });355 });356}356}632 ));632 ));633 assert_eq!(TemplateModule::balance_count(1, 1), 0);633 assert_eq!(TemplateModule::balance_count(1, 1), 0);634 assert_eq!(TemplateModule::balance_count(1, 3), 1000);634 assert_eq!(TemplateModule::balance_count(1, 3), 1000);635 assert_eq!(TemplateModule::address_tokens(1, 1), []);635 // assert_eq!(TemplateModule::address_tokens(1, 1), []);636 assert_eq!(TemplateModule::address_tokens(1, 3), [2]);636 assert_eq!(TemplateModule::address_tokens(1, 3), [2]);637637638 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);638 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);216221622163 assert_noop!(2163 assert_noop!(2164 TemplateModule::create_item(origin2.clone(), 1, [1, 2, 3].to_vec(), 2),2164 TemplateModule::create_item(origin2.clone(), 1, [1, 2, 3].to_vec(), 2),2165 "Collection is not in mint mode"2165 "Public minting is not allowed for this collection"2166 );2166 );2167 });2167 });2168}2168}220922092210 assert_noop!(2210 assert_noop!(2211 TemplateModule::create_item(origin2.clone(), 1, [1, 2, 3].to_vec(), 2),2211 TemplateModule::create_item(origin2.clone(), 1, [1, 2, 3].to_vec(), 2),2212 "Collection is not in mint mode"2212 "Public minting is not allowed for this collection"2213 );2213 );2214 });2214 });2215}2215}runtime/Cargo.tomldiffbeforeafterboth67 'frame-system/runtime-benchmarks',67 'frame-system/runtime-benchmarks',68 'pallet-balances/runtime-benchmarks',68 'pallet-balances/runtime-benchmarks',69 'pallet-timestamp/runtime-benchmarks',69 'pallet-timestamp/runtime-benchmarks',70 'pallet-nft/runtime-benchmarks',70 'sp-runtime/runtime-benchmarks',71 'sp-runtime/runtime-benchmarks',71]72]72std = [73std = [runtime/src/lib.rsdiffbeforeafterboth526 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {527 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {527 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};528 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};528529529 use frame_system_benchmarking::Module as SystemBench;530 // use frame_system_benchmarking::Module as SystemBench;530 impl frame_system_benchmarking::Trait for Runtime {}531 // impl frame_system_benchmarking::Trait for Runtime {}531532532 let mut whitelist: Vec<TrackedStorageKey> = vec![533 let whitelist: Vec<TrackedStorageKey> = vec![533 // Block Number534 // Block Number534 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),535 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),535 // Total Issuance536 // Total Issuance545 let mut batches = Vec::<BenchmarkBatch>::new();546 let mut batches = Vec::<BenchmarkBatch>::new();546 let params = (&config, &whitelist);547 let params = (&config, &whitelist);547548549 // add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);550 // add_benchmark!(params, batches, pallet_balances, Balances);551 // add_benchmark!(params, batches, pallet_timestamp, Timestamp);548 add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);552 add_benchmark!(params, batches, pallet_nft, Nft);549 add_benchmark!(params, batches, pallet_balances, Balances);550 add_benchmark!(params, batches, pallet_timestamp, Timestamp);551553552 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }554 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }553 Ok(batches)555 Ok(batches)