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
--- 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
 ```
modifiedpallets/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"]
modifiedpallets/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
+
+
modifiedpallets/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"
         );
     });
 }
modifiedruntime/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 = [
modifiedruntime/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)