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.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.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)