git.delta.rocks / unique-network / refs/commits / 8e8f09e20e76

difftreelog

First benchmark

str-mv2020-10-21parent: #0cdaf2e.patch.diff
in: master

7 files changed

modifiedCargo.lockdiffbeforeafterboth
3733name = "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",
modifiedREADME.mddiffbeforeafterboth
115115
116Additional 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`.
117117
118## Benchmarks
118119
120First of all, add rust toolchain and make it default.
121rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-01
122
123Then in "/node/src" run build command below
124cargo +nightly-2020-10-01 build --release --features runtime-benchmarks
125
126Run benchmark
127target/release/nft benchmark --chain dev --pallet "pallet_nft" --extrinsic "*" --repeat 1
128
119## UI custom types129## UI custom types
120```130```
121{131{
modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
42branch = 'v2.0.0_release'42branch = 'v2.0.0_release'
43version = '2.0.0'43version = '2.0.0'
4444
45[dev-dependencies.sp-runtime]45[dependencies.sp-runtime]
46default-features = false46default-features = false
47git = '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'
68
69[dependencies.frame-benchmarking]
70version = "2.0.0"
71default-features = false
72git = 'https://github.com/usetech-llc/substrate.git'
73branch = 'v2.0.0_release'
74optional = true
6875
69[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"]
7888
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
186}186}
187
188
189#[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_caller
196 use crate::Module as Nft;
197
198 const SEED: u32 = 1;
199
200 benchmarks! {
201
202 _ {}
203
204 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 }
215
216 #[cfg(test)]
217 mod tests {
218 use super::*;
219 use crate::tests_composite::{ExtBuilder, Test};
220 use frame_support::assert_ok;
221
222 #[test]
223 fn create_collection() {
224 ExtBuilder::default().build().execute_with(|| {
225 assert_ok!(test_benchmark_create_collection::<Test>());
226 });
227 }
228 }
229}
187230
188// #endregion231// #endregion
189232
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
177 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]);
182182
183 // split item scenario183 // split item scenario
260 );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]);
265265
266 // split item scenario266 // split item scenario
350 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]);
637637
638 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);638 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
21622162
2163 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}
22092209
2210 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}
modifiedruntime/Cargo.tomldiffbeforeafterboth
67 '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 = [
modifiedruntime/src/lib.rsdiffbeforeafterboth
526 ) -> 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};
528529
529 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 {}
531532
532 let mut whitelist: Vec<TrackedStorageKey> = vec![533 let whitelist: Vec<TrackedStorageKey> = vec![
533 // Block Number534 // Block Number
534 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),535 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
535 // Total Issuance536 // Total Issuance
545 let mut batches = Vec::<BenchmarkBatch>::new();546 let mut batches = Vec::<BenchmarkBatch>::new();
546 let params = (&config, &whitelist);547 let params = (&config, &whitelist);
547548
549 // 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);
551553
552 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)