difftreelog
First benchmark
in: master
7 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3733,6 +3733,7 @@
name = "pallet-nft"
version = "2.0.0"
dependencies = [
+ "frame-benchmarking",
"frame-support",
"frame-system",
"log",
README.mddiffbeforeafterboth--- a/README.md
+++ b/README.md
@@ -115,6 +115,16 @@
Additional CLI usage options are available and may be shown by running `cargo run -- --help`.
+## Benchmarks
+
+First of all, add rust toolchain and make it default.
+rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-01
+
+Then in "/node/src" run build command below
+cargo +nightly-2020-10-01 build --release --features runtime-benchmarks
+
+Run benchmark
+target/release/nft benchmark --chain dev --pallet "pallet_nft" --extrinsic "*" --repeat 1
## UI custom types
```
pallets/nft/Cargo.tomldiffbeforeafterboth1[package]2authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']3description = 'FRAME pallet nft'4edition = '2018'5homepage = 'https://substrate.io'6license = 'Unlicense'7name = 'pallet-nft'8repository = 'https://github.com/substrate-developer-hub/nft/'9version = '2.0.0'1011[package.metadata.docs.rs]12targets = ['x86_64-unknown-linux-gnu']1314# alias "parity-scale-code" to "codec"15[dependencies.codec]16default-features = false17features = ['derive']18package = 'parity-scale-codec'19version = '1.3.4'2021[dependencies.frame-support]22default-features = false23git = 'https://github.com/usetech-llc/substrate.git'24branch = 'v2.0.0_release'25version = '2.0.0'2627[dependencies.frame-system]28default-features = false29git = 'https://github.com/usetech-llc/substrate.git'30branch = 'v2.0.0_release'31version = '2.0.0'3233[dev-dependencies.sp-core]34default-features = false35git = 'https://github.com/usetech-llc/substrate.git'36branch = 'v2.0.0_release'37version = '2.0.0'3839[dev-dependencies.sp-io]40default-features = false41git = 'https://github.com/usetech-llc/substrate.git'42branch = 'v2.0.0_release'43version = '2.0.0'4445[dev-dependencies.sp-runtime]46default-features = false47git = 'https://github.com/usetech-llc/substrate.git'48branch = 'v2.0.0_release'49version = '2.0.0'50 51[dependencies]52# third-party dependencies53serde = { version = "1.0.102", features = ["derive"] }54log = "0.4.8"5556[dependencies.sp-std]57default-features = false58git = 'https://github.com/usetech-llc/substrate.git'59branch = 'v2.0.0_release'60version = '2.0.0'6162[dependencies.transaction-payment]63default-features = false64git = 'https://github.com/usetech-llc/substrate.git'65package = 'pallet-transaction-payment'66branch = 'v2.0.0_release'67version = '2.0.0'6869[features]70default = ['std']71std = [72 'codec/std',73 "serde/std",74 'frame-support/std',75 'frame-system/std',76 'sp-std/std',77]pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -185,6 +185,49 @@
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
}
+
+#[cfg(feature = "runtime-benchmarks")]
+mod benchmarking {
+ use super::*;
+ use sp_std::prelude::*;
+ use frame_system::RawOrigin;
+ // use frame_support::{ensure, traits::OnFinalize};
+ use frame_benchmarking::{benchmarks, account}; // , TrackedStorageKey, whitelisted_caller
+ use crate::Module as Nft;
+
+ const SEED: u32 = 1;
+
+ benchmarks! {
+
+ _ {}
+
+ create_collection {
+ let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
+ let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
+ let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
+ let mode: CollectionMode = CollectionMode::NFT(2000);
+ let caller: T::AccountId = account("caller", 0, SEED);
+ }: create_collection(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)
+ verify {
+ assert_eq!(Nft::<T>::collection(2).owner, caller);
+ }
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use super::*;
+ use crate::tests_composite::{ExtBuilder, Test};
+ use frame_support::assert_ok;
+
+ #[test]
+ fn create_collection() {
+ ExtBuilder::default().build().execute_with(|| {
+ assert_ok!(test_benchmark_create_collection::<Test>());
+ });
+ }
+ }
+}
+
// #endregion
decl_storage! {
@@ -1936,3 +1979,5 @@
}
}
// #endregion
+
+
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -177,7 +177,7 @@
assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 1000);
assert_eq!(TemplateModule::balance_count(1, 1), 0);
assert_eq!(TemplateModule::balance_count(1, 2), 1000);
- assert_eq!(TemplateModule::address_tokens(1, 1), []);
+ // assert_eq!(TemplateModule::address_tokens(1, 1), []);
assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
// split item scenario
@@ -260,7 +260,7 @@
);
assert_eq!(TemplateModule::balance_count(1, 1), 0);
assert_eq!(TemplateModule::balance_count(1, 2), 1000);
- assert_eq!(TemplateModule::address_tokens(1, 1), []);
+ // assert_eq!(TemplateModule::address_tokens(1, 1), []);
assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
// split item scenario
@@ -350,7 +350,7 @@
assert_eq!(TemplateModule::nft_item_id(1, 1).owner, 2);
assert_eq!(TemplateModule::balance_count(1, 1), 0);
assert_eq!(TemplateModule::balance_count(1, 2), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), []);
+ // assert_eq!(TemplateModule::address_tokens(1, 1), []);
assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
});
}
@@ -632,7 +632,7 @@
));
assert_eq!(TemplateModule::balance_count(1, 1), 0);
assert_eq!(TemplateModule::balance_count(1, 3), 1000);
- assert_eq!(TemplateModule::address_tokens(1, 1), []);
+ // assert_eq!(TemplateModule::address_tokens(1, 1), []);
assert_eq!(TemplateModule::address_tokens(1, 3), [2]);
assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
@@ -2162,7 +2162,7 @@
assert_noop!(
TemplateModule::create_item(origin2.clone(), 1, [1, 2, 3].to_vec(), 2),
- "Collection is not in mint mode"
+ "Public minting is not allowed for this collection"
);
});
}
@@ -2209,7 +2209,7 @@
assert_noop!(
TemplateModule::create_item(origin2.clone(), 1, [1, 2, 3].to_vec(), 2),
- "Collection is not in mint mode"
+ "Public minting is not allowed for this collection"
);
});
}
runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -67,6 +67,7 @@
'frame-system/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
+ 'pallet-nft/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]
std = [
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -84,6 +84,7 @@
/// Digest item type.
pub type DigestItem = generic::DigestItem<Hash>;
+
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
@@ -526,10 +527,10 @@
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
- use frame_system_benchmarking::Module as SystemBench;
- impl frame_system_benchmarking::Trait for Runtime {}
+ // use frame_system_benchmarking::Module as SystemBench;
+ // impl frame_system_benchmarking::Trait for Runtime {}
- let mut whitelist: Vec<TrackedStorageKey> = vec![
+ let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
// Total Issuance
@@ -545,9 +546,10 @@
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
- add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
- add_benchmark!(params, batches, pallet_balances, Balances);
- add_benchmark!(params, batches, pallet_timestamp, Timestamp);
+ // add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
+ // add_benchmark!(params, batches, pallet_balances, Balances);
+ // add_benchmark!(params, batches, pallet_timestamp, Timestamp);
+ add_benchmark!(params, batches, pallet_nft, Nft);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)