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.tomldiffbeforeafterboth--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -42,7 +42,7 @@
branch = 'v2.0.0_release'
version = '2.0.0'
-[dev-dependencies.sp-runtime]
+[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/usetech-llc/substrate.git'
branch = 'v2.0.0_release'
@@ -66,6 +66,13 @@
branch = 'v2.0.0_release'
version = '2.0.0'
+[dependencies.frame-benchmarking]
+version = "2.0.0"
+default-features = false
+git = 'https://github.com/usetech-llc/substrate.git'
+branch = 'v2.0.0_release'
+optional = true
+
[features]
default = ['std']
std = [
@@ -74,4 +81,7 @@
'frame-support/std',
'frame-system/std',
'sp-std/std',
+ 'sp-runtime/std',
+ 'frame-benchmarking/std',
]
+runtime-benchmarks = ["frame-benchmarking"]
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.tomldiffbeforeafterboth1[package]2authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']3edition = '2018'4homepage = 'https://substrate.io'5license = 'Unlicense'6name = 'nft-runtime'7repository = 'https://github.com/usetech-llc/nft_parachain/'8version = '2.0.0'910[package.metadata.docs.rs]11targets = ['x86_64-unknown-linux-gnu']1213[build-dependencies]14wasm-builder-runner = { package = 'substrate-wasm-builder-runner', version = '1.0.5' }1516# alias "parity-scale-code" to "codec"17[dependencies.codec]18default-features = false19features = ['derive']20package = 'parity-scale-codec'21version = '1.3.4'2223[dependencies]24hex-literal = { optional = true, version = '0.3.1' }25serde = { features = ['derive'], optional = true, version = '1.0.101' }2627# local dependencies28pallet-nft = { path = '../pallets/nft', default-features = false, version = '2.0.0' }2930# Substrate dependencies31frame-benchmarking = { default-features = false, optional = true, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }32frame-executive = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }33frame-support = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }34frame-system = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }35frame-system-benchmarking = { default-features = false, optional = true, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }36frame-system-rpc-runtime-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }37pallet-aura = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }38pallet-balances = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }39pallet-contracts = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }40pallet-contracts-primitives = { default-features = false, version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }41pallet-contracts-rpc-runtime-api = { default-features = false, version = '0.8.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }42pallet-grandpa = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }43pallet-randomness-collective-flip = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }44pallet-sudo = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }45pallet-timestamp = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }46pallet-transaction-payment = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }47pallet-transaction-payment-rpc-runtime-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }48sp-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }49sp-block-builder = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }50sp-consensus-aura = { default-features = false, version = '0.8.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }51sp-core = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }52sp-inherents = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }53sp-offchain = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }54sp-runtime = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }55sp-session = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }56sp-std = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }57sp-transaction-pool = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }58sp-version = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }5960[features]61default = ['std']62runtime-benchmarks = [63 'hex-literal',64 'frame-benchmarking',65 'frame-support/runtime-benchmarks',66 'frame-system-benchmarking',67 'frame-system/runtime-benchmarks',68 'pallet-balances/runtime-benchmarks',69 'pallet-timestamp/runtime-benchmarks',70 'sp-runtime/runtime-benchmarks',71]72std = [73 'codec/std',74 'serde',75 'frame-executive/std',76 'frame-support/std',77 'frame-system/std',78 'frame-system-rpc-runtime-api/std',79 'pallet-aura/std',80 'pallet-balances/std',81 'pallet-contracts/std',82 'pallet-contracts-primitives/std',83 'pallet-contracts-rpc-runtime-api/std',84 'pallet-grandpa/std',85 'pallet-randomness-collective-flip/std',86 'pallet-sudo/std',87 'pallet-timestamp/std',88 'pallet-transaction-payment/std',89 'pallet-transaction-payment-rpc-runtime-api/std',90 'pallet-nft/std',91 'sp-api/std',92 'sp-block-builder/std',93 'sp-consensus-aura/std',94 'sp-core/std',95 'sp-inherents/std',96 'sp-offchain/std',97 'sp-runtime/std',98 'sp-session/std',99 'sp-std/std',100 'sp-transaction-pool/std',101 'sp-version/std',102]1[package]2authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']3edition = '2018'4homepage = 'https://substrate.io'5license = 'Unlicense'6name = 'nft-runtime'7repository = 'https://github.com/usetech-llc/nft_parachain/'8version = '2.0.0'910[package.metadata.docs.rs]11targets = ['x86_64-unknown-linux-gnu']1213[build-dependencies]14wasm-builder-runner = { package = 'substrate-wasm-builder-runner', version = '1.0.5' }1516# alias "parity-scale-code" to "codec"17[dependencies.codec]18default-features = false19features = ['derive']20package = 'parity-scale-codec'21version = '1.3.4'2223[dependencies]24hex-literal = { optional = true, version = '0.3.1' }25serde = { features = ['derive'], optional = true, version = '1.0.101' }2627# local dependencies28pallet-nft = { path = '../pallets/nft', default-features = false, version = '2.0.0' }2930# Substrate dependencies31frame-benchmarking = { default-features = false, optional = true, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }32frame-executive = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }33frame-support = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }34frame-system = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }35frame-system-benchmarking = { default-features = false, optional = true, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }36frame-system-rpc-runtime-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }37pallet-aura = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }38pallet-balances = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }39pallet-contracts = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }40pallet-contracts-primitives = { default-features = false, version = '2.0.0', git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }41pallet-contracts-rpc-runtime-api = { default-features = false, version = '0.8.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }42pallet-grandpa = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }43pallet-randomness-collective-flip = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }44pallet-sudo = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }45pallet-timestamp = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }46pallet-transaction-payment = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }47pallet-transaction-payment-rpc-runtime-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }48sp-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }49sp-block-builder = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }50sp-consensus-aura = { default-features = false, version = '0.8.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }51sp-core = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }52sp-inherents = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }53sp-offchain = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }54sp-runtime = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }55sp-session = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }56sp-std = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }57sp-transaction-pool = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }58sp-version = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }5960[features]61default = ['std']62runtime-benchmarks = [63 'hex-literal',64 'frame-benchmarking',65 'frame-support/runtime-benchmarks',66 'frame-system-benchmarking',67 'frame-system/runtime-benchmarks',68 'pallet-balances/runtime-benchmarks',69 'pallet-timestamp/runtime-benchmarks',70 'pallet-nft/runtime-benchmarks',71 'sp-runtime/runtime-benchmarks',72]73std = [74 'codec/std',75 'serde',76 'frame-executive/std',77 'frame-support/std',78 'frame-system/std',79 'frame-system-rpc-runtime-api/std',80 'pallet-aura/std',81 'pallet-balances/std',82 'pallet-contracts/std',83 'pallet-contracts-primitives/std',84 'pallet-contracts-rpc-runtime-api/std',85 'pallet-grandpa/std',86 'pallet-randomness-collective-flip/std',87 'pallet-sudo/std',88 'pallet-timestamp/std',89 'pallet-transaction-payment/std',90 'pallet-transaction-payment-rpc-runtime-api/std',91 'pallet-nft/std',92 'sp-api/std',93 'sp-block-builder/std',94 'sp-consensus-aura/std',95 'sp-core/std',96 'sp-inherents/std',97 'sp-offchain/std',98 'sp-runtime/std',99 'sp-session/std',100 'sp-std/std',101 'sp-transaction-pool/std',102 'sp-version/std',103]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)