difftreelog
feat(rmrk) benchmark set_priority
in: master
1 file changed
pallets/proxy-rmrk-core/src/benchmarking.rsdiffbeforeafterboth1use sp_std::vec;23use frame_benchmarking::{benchmarks, account};4use frame_system::RawOrigin;5use frame_support::{6 traits::{Currency, Get},7 BoundedVec,8};9use sp_runtime::Permill;1011use up_data_structs::*;1213use super::*;1415const SEED: u32 = 1;1617fn create_data<S: Get<u32>>() -> BoundedVec<u8, S> {18 vec![b'A'; S::get() as usize].try_into().expect("size == S")19}2021fn create_max_collection<T: Config>(owner: &T::AccountId) -> DispatchResult {22 <T as pallet_common::Config>::Currency::deposit_creating(owner, T::CollectionCreationPrice::get());2324 let metadata = create_data();25 let max = None;26 let symbol = create_data();2728 <Pallet<T>>::create_collection(RawOrigin::Signed(owner.clone()).into(), metadata, max, symbol)29}3031fn create_max_nft<T: Config>(owner: &T::AccountId, collection_id: RmrkCollectionId) -> DispatchResult {32 let royalty_recipient = Some(owner.clone());33 let royalty_amount = Some(Permill::from_percent(25));34 let metadata = create_data();35 let transferable = true;3637 <Pallet<T>>::mint_nft(38 RawOrigin::Signed(owner.clone()).into(),39 owner.clone(),40 collection_id,41 royalty_recipient,42 royalty_amount,43 metadata,44 transferable45 )46}4748struct NftBuilder {49 collection_id: RmrkCollectionId,50 current_nft_id: RmrkNftId51}5253impl NftBuilder {54 fn new(collection_id: RmrkCollectionId) -> Self {55 Self {56 collection_id,57 current_nft_id: 058 }59 }6061 fn build<T: Config>(&mut self, owner: &T::AccountId) -> Result<RmrkNftId, DispatchError> {62 create_max_nft::<T>(owner, self.collection_id)?;63 self.current_nft_id += 1;6465 Ok(self.current_nft_id)66 }6768 fn build_tower<T: Config>(&mut self, owner: &T::AccountId, height: u32) -> Result<RmrkNftId, DispatchError> {69 self.build::<T>(owner)?;7071 let mut prev_nft_id = self.current_nft_id;7273 for _ in 0..height {74 self.build::<T>(owner)?;75 76 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(77 self.collection_id,78 prev_nft_id79 );8081 <Pallet<T>>::send(82 RawOrigin::Signed(owner.clone()).into(),83 self.collection_id,84 self.current_nft_id,85 new_owner,86 )?;8788 prev_nft_id = self.current_nft_id;89 }9091 let deepest_nft_id = self.current_nft_id;9293 Ok(deepest_nft_id)94 }95}9697benchmarks! {98 create_collection {99 let caller = account("caller", 0, SEED);100 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());101 let metadata = create_data();102 let max = None;103 let symbol = create_data();104 }: _(RawOrigin::Signed(caller), metadata, max, symbol)105106 destroy_collection {107 let caller = account("caller", 0, SEED);108 109 create_max_collection::<T>(&caller)?;110 let collection_id = 0;111 }: _(RawOrigin::Signed(caller), collection_id)112113 change_collection_issuer {114 let caller: T::AccountId = account("caller", 0, SEED);115116 create_max_collection::<T>(&caller)?;117 let collection_id = 0;118119 let new_owner: T::AccountId = account("new_owner", 0, SEED);120121 let new_owner_source = T::Lookup::unlookup(new_owner);122 }: _(RawOrigin::Signed(caller), collection_id, new_owner_source)123124 lock_collection {125 let caller: T::AccountId = account("caller", 0, SEED);126127 create_max_collection::<T>(&caller)?;128 let collection_id = 0;129 }: _(RawOrigin::Signed(caller), collection_id)130131 mint_nft {132 let caller: T::AccountId = account("caller", 0, SEED);133134 create_max_collection::<T>(&caller)?;135 let collection_id = 0;136 let owner = caller.clone();137 138 let royalty_recipient = Some(caller.clone());139 let royalty_amount = Some(Permill::from_percent(25));140 let metadata = create_data();141 let transferable = true;142 }: _(143 RawOrigin::Signed(caller),144 owner,145 collection_id,146 royalty_recipient,147 royalty_amount,148 metadata,149 transferable150 )151152 send {153 let caller: T::AccountId = account("caller", 0, SEED);154 create_max_collection::<T>(&caller)?;155 let collection_id = 0;156157 let mut nft_builder = NftBuilder::new(collection_id);158 let src_nft_id = nft_builder.build::<T>(&caller)?;159 let target_nft_id = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 2)?;160 }: _(161 RawOrigin::Signed(caller),162 collection_id,163 src_nft_id,164 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)165 )166167 accept_nft {168 let caller: T::AccountId = account("caller", 0, SEED);169 let sender: T::AccountId = account("sender", 0, SEED);170171 create_max_collection::<T>(&sender)?;172 let src_collection_id = 0;173174 create_max_collection::<T>(&caller)?;175 let target_collection_id = 1;176177 let mut src_nft_builder = NftBuilder::new(src_collection_id);178 let src_nft_id = src_nft_builder.build::<T>(&sender)?;179180 let mut target_nft_builder = NftBuilder::new(target_collection_id);181 let fake_target_nft_id = target_nft_builder.build::<T>(&caller)?;182 let target_nft_id = target_nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;183184 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(185 target_collection_id,186 fake_target_nft_id187 );188189 let actual_new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(190 target_collection_id,191 target_nft_id192 );193194 <Pallet<T>>::send(195 RawOrigin::Signed(sender.clone()).into(),196 src_collection_id,197 src_nft_id,198 new_owner,199 )?;200 }: _(201 RawOrigin::Signed(caller),202 src_collection_id,203 src_nft_id,204 actual_new_owner205 )206207 set_property {208 let caller: T::AccountId = account("caller", 0, SEED);209 create_max_collection::<T>(&caller)?;210 let collection_id = 0;211212 let mut nft_builder = NftBuilder::new(collection_id);213 let nft_id = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;214215 let key = create_data();216 let value = create_data();217 }: _(218 RawOrigin::Signed(caller),219 collection_id,220 Some(nft_id),221 key,222 value223 )224}1use sp_std::vec;23use frame_benchmarking::{benchmarks, account};4use frame_system::RawOrigin;5use frame_support::{6 traits::{Currency, Get},7 BoundedVec,8};9use sp_runtime::Permill;1011use up_data_structs::*;1213use super::*;1415const SEED: u32 = 1;1617fn create_data<S: Get<u32>>() -> BoundedVec<u8, S> {18 vec![b'A'; S::get() as usize].try_into().expect("size == S")19}2021fn create_priorities<S: Get<u32>>() -> BoundedVec<RmrkResourceId, S> {22 vec![0; S::get() as usize].try_into().expect("size == S")23}2425fn create_max_collection<T: Config>(owner: &T::AccountId) -> DispatchResult {26 <T as pallet_common::Config>::Currency::deposit_creating(owner, T::CollectionCreationPrice::get());2728 let metadata = create_data();29 let max = None;30 let symbol = create_data();3132 <Pallet<T>>::create_collection(RawOrigin::Signed(owner.clone()).into(), metadata, max, symbol)33}3435fn create_max_nft<T: Config>(owner: &T::AccountId, collection_id: RmrkCollectionId) -> DispatchResult {36 let royalty_recipient = Some(owner.clone());37 let royalty_amount = Some(Permill::from_percent(25));38 let metadata = create_data();39 let transferable = true;4041 <Pallet<T>>::mint_nft(42 RawOrigin::Signed(owner.clone()).into(),43 owner.clone(),44 collection_id,45 royalty_recipient,46 royalty_amount,47 metadata,48 transferable49 )50}5152struct NftBuilder {53 collection_id: RmrkCollectionId,54 current_nft_id: RmrkNftId55}5657impl NftBuilder {58 fn new(collection_id: RmrkCollectionId) -> Self {59 Self {60 collection_id,61 current_nft_id: 062 }63 }6465 fn build<T: Config>(&mut self, owner: &T::AccountId) -> Result<RmrkNftId, DispatchError> {66 create_max_nft::<T>(owner, self.collection_id)?;67 self.current_nft_id += 1;6869 Ok(self.current_nft_id)70 }7172 fn build_tower<T: Config>(&mut self, owner: &T::AccountId, height: u32) -> Result<RmrkNftId, DispatchError> {73 self.build::<T>(owner)?;7475 let mut prev_nft_id = self.current_nft_id;7677 for _ in 0..height {78 self.build::<T>(owner)?;79 80 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(81 self.collection_id,82 prev_nft_id83 );8485 <Pallet<T>>::send(86 RawOrigin::Signed(owner.clone()).into(),87 self.collection_id,88 self.current_nft_id,89 new_owner,90 )?;9192 prev_nft_id = self.current_nft_id;93 }9495 let deepest_nft_id = self.current_nft_id;9697 Ok(deepest_nft_id)98 }99}100101benchmarks! {102 create_collection {103 let caller = account("caller", 0, SEED);104 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());105 let metadata = create_data();106 let max = None;107 let symbol = create_data();108 }: _(RawOrigin::Signed(caller), metadata, max, symbol)109110 destroy_collection {111 let caller = account("caller", 0, SEED);112 113 create_max_collection::<T>(&caller)?;114 let collection_id = 0;115 }: _(RawOrigin::Signed(caller), collection_id)116117 change_collection_issuer {118 let caller: T::AccountId = account("caller", 0, SEED);119120 create_max_collection::<T>(&caller)?;121 let collection_id = 0;122123 let new_owner: T::AccountId = account("new_owner", 0, SEED);124125 let new_owner_source = T::Lookup::unlookup(new_owner);126 }: _(RawOrigin::Signed(caller), collection_id, new_owner_source)127128 lock_collection {129 let caller: T::AccountId = account("caller", 0, SEED);130131 create_max_collection::<T>(&caller)?;132 let collection_id = 0;133 }: _(RawOrigin::Signed(caller), collection_id)134135 mint_nft {136 let caller: T::AccountId = account("caller", 0, SEED);137138 create_max_collection::<T>(&caller)?;139 let collection_id = 0;140 let owner = caller.clone();141 142 let royalty_recipient = Some(caller.clone());143 let royalty_amount = Some(Permill::from_percent(25));144 let metadata = create_data();145 let transferable = true;146 }: _(147 RawOrigin::Signed(caller),148 owner,149 collection_id,150 royalty_recipient,151 royalty_amount,152 metadata,153 transferable154 )155156 send {157 let caller: T::AccountId = account("caller", 0, SEED);158 create_max_collection::<T>(&caller)?;159 let collection_id = 0;160161 let mut nft_builder = NftBuilder::new(collection_id);162 let src_nft_id = nft_builder.build::<T>(&caller)?;163 let target_nft_id = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 2)?;164 }: _(165 RawOrigin::Signed(caller),166 collection_id,167 src_nft_id,168 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)169 )170171 accept_nft {172 let caller: T::AccountId = account("caller", 0, SEED);173 let sender: T::AccountId = account("sender", 0, SEED);174175 create_max_collection::<T>(&sender)?;176 let src_collection_id = 0;177178 create_max_collection::<T>(&caller)?;179 let target_collection_id = 1;180181 let mut src_nft_builder = NftBuilder::new(src_collection_id);182 let src_nft_id = src_nft_builder.build::<T>(&sender)?;183184 let mut target_nft_builder = NftBuilder::new(target_collection_id);185 let fake_target_nft_id = target_nft_builder.build::<T>(&caller)?;186 let target_nft_id = target_nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;187188 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(189 target_collection_id,190 fake_target_nft_id191 );192193 let actual_new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(194 target_collection_id,195 target_nft_id196 );197198 <Pallet<T>>::send(199 RawOrigin::Signed(sender.clone()).into(),200 src_collection_id,201 src_nft_id,202 new_owner,203 )?;204 }: _(205 RawOrigin::Signed(caller),206 src_collection_id,207 src_nft_id,208 actual_new_owner209 )210211 set_property {212 let caller: T::AccountId = account("caller", 0, SEED);213 create_max_collection::<T>(&caller)?;214 let collection_id = 0;215216 let mut nft_builder = NftBuilder::new(collection_id);217 let nft_id = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;218219 let key = create_data();220 let value = create_data();221 }: _(222 RawOrigin::Signed(caller),223 collection_id,224 Some(nft_id),225 key,226 value227 )228229 set_priority {230 let caller: T::AccountId = account("caller", 0, SEED);231 create_max_collection::<T>(&caller)?;232 let collection_id = 0;233234 let mut nft_builder = NftBuilder::new(collection_id);235 let nft_id = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;236 let priorities = create_priorities();237 }: _(238 RawOrigin::Signed(caller),239 collection_id,240 nft_id,241 priorities242 )243}