difftreelog
cargo fmt
in: master
2 files 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_u32_array<S: Get<u32>>() -> BoundedVec<u32, S> {22 vec![0; S::get() as usize].try_into().expect("size == S")23}2425fn create_basic_resource() -> RmrkBasicResource {26 RmrkBasicResource {27 src: Some(create_data()),28 metadata: Some(create_data()),29 license: Some(create_data()),30 thumb: Some(create_data()),31 }32}3334fn create_composable_resource() -> RmrkComposableResource {35 RmrkComposableResource {36 parts: create_u32_array(),37 base: 100,38 src: Some(create_data()),39 metadata: Some(create_data()),40 license: Some(create_data()),41 thumb: Some(create_data()),42 }43}4445fn create_slot_resource() -> RmrkSlotResource {46 RmrkSlotResource {47 base: 100,48 slot: 200,49 src: Some(create_data()),50 metadata: Some(create_data()),51 license: Some(create_data()),52 thumb: Some(create_data()),53 }54}5556fn create_max_resource_types_array<S: Get<u32>>(num: usize) -> BoundedVec<RmrkResourceTypes, S> {57 vec![RmrkResourceTypes::Composable(create_composable_resource()); num].try_into().expect("num <= S")58}5960fn create_max_collection<T: Config>(owner: &T::AccountId) -> DispatchResult {61 <T as pallet_common::Config>::Currency::deposit_creating(62 owner,63 T::CollectionCreationPrice::get(),64 );6566 let metadata = create_data();67 let max = None;68 let symbol = create_data();6970 <Pallet<T>>::create_collection(71 RawOrigin::Signed(owner.clone()).into(),72 metadata,73 max,74 symbol,75 )76}7778fn create_nft<T: Config>(79 owner: &T::AccountId,80 collection_id: RmrkCollectionId,81) -> DispatchResult {82 let royalty_recipient = Some(owner.clone());83 let royalty_amount = Some(Permill::from_percent(25));84 let metadata = create_data();85 let transferable = true;8687 <Pallet<T>>::mint_nft(88 RawOrigin::Signed(owner.clone()).into(),89 owner.clone(),90 collection_id,91 royalty_recipient,92 royalty_amount,93 metadata,94 transferable,95 None96 )97}9899struct NftBuilder {100 collection_id: RmrkCollectionId,101 current_nft_id: RmrkNftId,102}103104impl NftBuilder {105 fn new(collection_id: RmrkCollectionId) -> Self {106 Self {107 collection_id,108 current_nft_id: 0,109 }110 }111112 fn current_nft_id(&self) -> RmrkNftId {113 self.current_nft_id114 }115116 fn build<T: Config>(&mut self, owner: &T::AccountId) -> Result<RmrkNftId, DispatchError> {117 create_nft::<T>(owner, self.collection_id)?;118 self.current_nft_id += 1;119120 Ok(self.current_nft_id)121 }122123 fn build_tower<T: Config>(124 &mut self,125 owner: &T::AccountId,126 height: u32,127 ) -> Result<(RmrkNftId, RmrkNftId), DispatchError> {128 self.build::<T>(owner)?;129130 let root_nft_id = self.current_nft_id;131 let mut prev_nft_id = root_nft_id;132133 for _ in 0..height {134 self.build::<T>(owner)?;135136 let new_owner =137 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(138 self.collection_id,139 prev_nft_id,140 );141142 <Pallet<T>>::send(143 RawOrigin::Signed(owner.clone()).into(),144 self.collection_id,145 self.current_nft_id,146 new_owner,147 )?;148149 prev_nft_id = self.current_nft_id;150 }151152 let deepest_nft_id = self.current_nft_id;153154 Ok((root_nft_id, deepest_nft_id))155 }156157 fn build_wide_tree<T: Config>(158 &mut self,159 owner: &T::AccountId,160 width: u32,161 ) -> Result<RmrkNftId, DispatchError> {162 self.build::<T>(owner)?;163164 let root_nft_id = self.current_nft_id;165166 let root_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(167 self.collection_id,168 root_nft_id,169 );170171 for _ in 0..width {172 self.build::<T>(owner)?;173174 <Pallet<T>>::send(175 RawOrigin::Signed(owner.clone()).into(),176 self.collection_id,177 self.current_nft_id,178 root_owner.clone(),179 )?;180 }181182 Ok(root_nft_id)183 }184}185186benchmarks! {187 create_collection {188 let caller = account("caller", 0, SEED);189 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());190 let metadata = create_data();191 let max = None;192 let symbol = create_data();193 }: _(RawOrigin::Signed(caller), metadata, max, symbol)194195 destroy_collection {196 let caller = account("caller", 0, SEED);197198 create_max_collection::<T>(&caller)?;199 let collection_id = 0;200 }: _(RawOrigin::Signed(caller), collection_id)201202 change_collection_issuer {203 let caller: T::AccountId = account("caller", 0, SEED);204205 create_max_collection::<T>(&caller)?;206 let collection_id = 0;207208 let new_owner: T::AccountId = account("new_owner", 0, SEED);209210 let new_owner_source = T::Lookup::unlookup(new_owner);211 }: _(RawOrigin::Signed(caller), collection_id, new_owner_source)212213 lock_collection {214 let caller: T::AccountId = account("caller", 0, SEED);215216 create_max_collection::<T>(&caller)?;217 let collection_id = 0;218 }: _(RawOrigin::Signed(caller), collection_id)219220 mint_nft {221 let b in 0..100;222223 let caller: T::AccountId = account("caller", 0, SEED);224 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());225226 create_max_collection::<T>(&caller)?;227 let collection_id = 0;228 let owner = caller.clone();229230 let royalty_recipient = Some(caller.clone());231 let royalty_amount = Some(Permill::from_percent(25));232 let metadata = create_data();233 let transferable = true;234 }: _(235 RawOrigin::Signed(caller),236 owner,237 collection_id,238 royalty_recipient,239 royalty_amount,240 metadata,241 transferable,242 Some(create_max_resource_types_array(b as usize))243 )244245 burn_nft {246 let b in 0..200;247248 let caller: T::AccountId = account("caller", 0, SEED);249 create_max_collection::<T>(&caller)?;250 let collection_id = 0;251252 let mut nft_builder = NftBuilder::new(collection_id);253 let root_nft_id = nft_builder.build_wide_tree::<T>(&caller, b)?;254 let max_burns = b + 1;255 }: _(256 RawOrigin::Signed(caller),257 collection_id,258 root_nft_id,259 max_burns260 )261262 send {263 let caller: T::AccountId = account("caller", 0, SEED);264 create_max_collection::<T>(&caller)?;265 let collection_id = 0;266267 let mut nft_builder = NftBuilder::new(collection_id);268 let src_nft_id = nft_builder.build::<T>(&caller)?;269 let (_, target_nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 2)?;270 }: _(271 RawOrigin::Signed(caller),272 collection_id,273 src_nft_id,274 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)275 )276277 accept_nft {278 let caller: T::AccountId = account("caller", 0, SEED);279 let sender: T::AccountId = account("sender", 0, SEED);280281 create_max_collection::<T>(&sender)?;282 let src_collection_id = 0;283284 create_max_collection::<T>(&caller)?;285 let target_collection_id = 1;286287 let mut src_nft_builder = NftBuilder::new(src_collection_id);288 let src_nft_id = src_nft_builder.build::<T>(&sender)?;289290 let mut target_nft_builder = NftBuilder::new(target_collection_id);291 let fake_target_nft_id = target_nft_builder.build::<T>(&caller)?;292 let (_, target_nft_id) = target_nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;293294 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(295 target_collection_id,296 fake_target_nft_id297 );298299 let actual_new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(300 target_collection_id,301 target_nft_id302 );303304 <Pallet<T>>::send(305 RawOrigin::Signed(sender.clone()).into(),306 src_collection_id,307 src_nft_id,308 new_owner,309 )?;310 }: _(311 RawOrigin::Signed(caller),312 src_collection_id,313 src_nft_id,314 actual_new_owner315 )316317 reject_nft {318 let caller: T::AccountId = account("caller", 0, SEED);319 let sender: T::AccountId = account("sender", 0, SEED);320321 create_max_collection::<T>(&sender)?;322 let src_collection_id = 0;323324 create_max_collection::<T>(&caller)?;325 let target_collection_id = 1;326327 let mut src_nft_builder = NftBuilder::new(src_collection_id);328 let (src_root_nft_id, _) = src_nft_builder.build_tower::<T>(&sender, NESTING_BUDGET - 1)?;329330 let mut target_nft_builder = NftBuilder::new(target_collection_id);331 let target_nft_id = target_nft_builder.build::<T>(&caller)?;332333 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(334 target_collection_id,335 target_nft_id336 );337338 <Pallet<T>>::send(339 RawOrigin::Signed(sender.clone()).into(),340 src_collection_id,341 src_root_nft_id,342 new_owner,343 )?;344 }: _(345 RawOrigin::Signed(caller),346 src_collection_id,347 src_root_nft_id348 )349350 set_property {351 let caller: T::AccountId = account("caller", 0, SEED);352 create_max_collection::<T>(&caller)?;353 let collection_id = 0;354355 let mut nft_builder = NftBuilder::new(collection_id);356 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;357358 let key = create_data();359 let value = create_data();360 }: _(361 RawOrigin::Signed(caller),362 collection_id,363 Some(nft_id),364 key,365 value366 )367368 set_priority {369 let caller: T::AccountId = account("caller", 0, SEED);370 create_max_collection::<T>(&caller)?;371 let collection_id = 0;372373 let mut nft_builder = NftBuilder::new(collection_id);374 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;375 let priorities = create_u32_array();376 }: _(377 RawOrigin::Signed(caller),378 collection_id,379 nft_id,380 priorities381 )382383 add_basic_resource {384 let caller: T::AccountId = account("caller", 0, SEED);385 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());386387 create_max_collection::<T>(&caller)?;388 let collection_id = 0;389390 let mut nft_builder = NftBuilder::new(collection_id);391 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;392 let resource = create_basic_resource();393 }: _(394 RawOrigin::Signed(caller),395 collection_id,396 nft_id,397 resource398 )399400 add_composable_resource {401 let caller: T::AccountId = account("caller", 0, SEED);402 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());403404 create_max_collection::<T>(&caller)?;405 let collection_id = 0;406407 let mut nft_builder = NftBuilder::new(collection_id);408 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;409 let resource = create_composable_resource();410 }: _(411 RawOrigin::Signed(caller),412 collection_id,413 nft_id,414 resource415 )416417 add_slot_resource {418 let caller: T::AccountId = account("caller", 0, SEED);419 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());420421 create_max_collection::<T>(&caller)?;422 let collection_id = 0;423424 let mut nft_builder = NftBuilder::new(collection_id);425 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;426 let resource = create_slot_resource();427 }: _(428 RawOrigin::Signed(caller),429 collection_id,430 nft_id,431 resource432 )433434 remove_resource {435 let caller: T::AccountId = account("caller", 0, SEED);436 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());437438 create_max_collection::<T>(&caller)?;439 let collection_id = 0;440441 let mut nft_builder = NftBuilder::new(collection_id);442 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;443 let resource = create_basic_resource();444445 <Pallet<T>>::add_basic_resource(446 RawOrigin::Signed(caller.clone()).into(),447 collection_id,448 nft_id,449 resource450 )?;451452 let resource_id = 1;453 }: _(454 RawOrigin::Signed(caller),455 collection_id,456 nft_id,457 resource_id458 )459460 accept_resource {461 let caller: T::AccountId = account("caller", 0, SEED);462 let admin: T::AccountId = account("admin", 0, SEED);463464 <T as pallet_common::Config>::Currency::deposit_creating(&admin, T::CollectionCreationPrice::get());465466 create_max_collection::<T>(&admin)?;467 let collection_id = 0;468469 let mut nft_builder = NftBuilder::new(collection_id);470 let root_nft_id = 1;471 let (_, nested_nft_id) = nft_builder.build_tower::<T>(&admin, NESTING_BUDGET - 1)?;472 let resource = create_basic_resource();473474 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::AccountId(caller.clone());475476 <Pallet<T>>::send(477 RawOrigin::Signed(admin.clone()).into(),478 collection_id,479 root_nft_id,480 new_owner,481 )?;482483 <Pallet<T>>::add_basic_resource(484 RawOrigin::Signed(admin.clone()).into(),485 collection_id,486 nested_nft_id,487 resource488 )?;489490 let resource_id = 1;491 }: _(492 RawOrigin::Signed(caller),493 collection_id,494 nested_nft_id,495 resource_id496 )497498 accept_resource_removal {499 let caller: T::AccountId = account("caller", 0, SEED);500 let admin: T::AccountId = account("admin", 0, SEED);501502 <T as pallet_common::Config>::Currency::deposit_creating(&admin, T::CollectionCreationPrice::get());503504 create_max_collection::<T>(&admin)?;505 let collection_id = 0;506507 let mut nft_builder = NftBuilder::new(collection_id);508 let root_nft_id = 1;509 let (_, nested_nft_id) = nft_builder.build_tower::<T>(&admin, NESTING_BUDGET - 1)?;510 let resource = create_basic_resource();511512 <Pallet<T>>::add_basic_resource(513 RawOrigin::Signed(admin.clone()).into(),514 collection_id,515 nested_nft_id,516 resource517 )?;518519 let resource_id = 1;520521 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::AccountId(caller.clone());522523 <Pallet<T>>::send(524 RawOrigin::Signed(admin.clone()).into(),525 collection_id,526 root_nft_id,527 new_owner,528 )?;529530 <Pallet<T>>::remove_resource(531 RawOrigin::Signed(admin).into(),532 collection_id,533 nested_nft_id,534 resource_id535 )?;536 }: _(537 RawOrigin::Signed(caller),538 collection_id,539 nested_nft_id,540 resource_id541 )542}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_u32_array<S: Get<u32>>() -> BoundedVec<u32, S> {22 vec![0; S::get() as usize].try_into().expect("size == S")23}2425fn create_basic_resource() -> RmrkBasicResource {26 RmrkBasicResource {27 src: Some(create_data()),28 metadata: Some(create_data()),29 license: Some(create_data()),30 thumb: Some(create_data()),31 }32}3334fn create_composable_resource() -> RmrkComposableResource {35 RmrkComposableResource {36 parts: create_u32_array(),37 base: 100,38 src: Some(create_data()),39 metadata: Some(create_data()),40 license: Some(create_data()),41 thumb: Some(create_data()),42 }43}4445fn create_slot_resource() -> RmrkSlotResource {46 RmrkSlotResource {47 base: 100,48 slot: 200,49 src: Some(create_data()),50 metadata: Some(create_data()),51 license: Some(create_data()),52 thumb: Some(create_data()),53 }54}5556fn create_max_resource_types_array<S: Get<u32>>(num: usize) -> BoundedVec<RmrkResourceTypes, S> {57 vec![RmrkResourceTypes::Composable(create_composable_resource()); num]58 .try_into()59 .expect("num <= S")60}6162fn create_max_collection<T: Config>(owner: &T::AccountId) -> DispatchResult {63 <T as pallet_common::Config>::Currency::deposit_creating(64 owner,65 T::CollectionCreationPrice::get(),66 );6768 let metadata = create_data();69 let max = None;70 let symbol = create_data();7172 <Pallet<T>>::create_collection(73 RawOrigin::Signed(owner.clone()).into(),74 metadata,75 max,76 symbol,77 )78}7980fn create_nft<T: Config>(owner: &T::AccountId, collection_id: RmrkCollectionId) -> DispatchResult {81 let royalty_recipient = Some(owner.clone());82 let royalty_amount = Some(Permill::from_percent(25));83 let metadata = create_data();84 let transferable = true;8586 <Pallet<T>>::mint_nft(87 RawOrigin::Signed(owner.clone()).into(),88 owner.clone(),89 collection_id,90 royalty_recipient,91 royalty_amount,92 metadata,93 transferable,94 None,95 )96}9798struct NftBuilder {99 collection_id: RmrkCollectionId,100 current_nft_id: RmrkNftId,101}102103impl NftBuilder {104 fn new(collection_id: RmrkCollectionId) -> Self {105 Self {106 collection_id,107 current_nft_id: 0,108 }109 }110111 fn current_nft_id(&self) -> RmrkNftId {112 self.current_nft_id113 }114115 fn build<T: Config>(&mut self, owner: &T::AccountId) -> Result<RmrkNftId, DispatchError> {116 create_nft::<T>(owner, self.collection_id)?;117 self.current_nft_id += 1;118119 Ok(self.current_nft_id)120 }121122 fn build_tower<T: Config>(123 &mut self,124 owner: &T::AccountId,125 height: u32,126 ) -> Result<(RmrkNftId, RmrkNftId), DispatchError> {127 self.build::<T>(owner)?;128129 let root_nft_id = self.current_nft_id;130 let mut prev_nft_id = root_nft_id;131132 for _ in 0..height {133 self.build::<T>(owner)?;134135 let new_owner =136 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(137 self.collection_id,138 prev_nft_id,139 );140141 <Pallet<T>>::send(142 RawOrigin::Signed(owner.clone()).into(),143 self.collection_id,144 self.current_nft_id,145 new_owner,146 )?;147148 prev_nft_id = self.current_nft_id;149 }150151 let deepest_nft_id = self.current_nft_id;152153 Ok((root_nft_id, deepest_nft_id))154 }155156 fn build_wide_tree<T: Config>(157 &mut self,158 owner: &T::AccountId,159 width: u32,160 ) -> Result<RmrkNftId, DispatchError> {161 self.build::<T>(owner)?;162163 let root_nft_id = self.current_nft_id;164165 let root_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(166 self.collection_id,167 root_nft_id,168 );169170 for _ in 0..width {171 self.build::<T>(owner)?;172173 <Pallet<T>>::send(174 RawOrigin::Signed(owner.clone()).into(),175 self.collection_id,176 self.current_nft_id,177 root_owner.clone(),178 )?;179 }180181 Ok(root_nft_id)182 }183}184185benchmarks! {186 create_collection {187 let caller = account("caller", 0, SEED);188 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());189 let metadata = create_data();190 let max = None;191 let symbol = create_data();192 }: _(RawOrigin::Signed(caller), metadata, max, symbol)193194 destroy_collection {195 let caller = account("caller", 0, SEED);196197 create_max_collection::<T>(&caller)?;198 let collection_id = 0;199 }: _(RawOrigin::Signed(caller), collection_id)200201 change_collection_issuer {202 let caller: T::AccountId = account("caller", 0, SEED);203204 create_max_collection::<T>(&caller)?;205 let collection_id = 0;206207 let new_owner: T::AccountId = account("new_owner", 0, SEED);208209 let new_owner_source = T::Lookup::unlookup(new_owner);210 }: _(RawOrigin::Signed(caller), collection_id, new_owner_source)211212 lock_collection {213 let caller: T::AccountId = account("caller", 0, SEED);214215 create_max_collection::<T>(&caller)?;216 let collection_id = 0;217 }: _(RawOrigin::Signed(caller), collection_id)218219 mint_nft {220 let b in 0..100;221222 let caller: T::AccountId = account("caller", 0, SEED);223 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());224225 create_max_collection::<T>(&caller)?;226 let collection_id = 0;227 let owner = caller.clone();228229 let royalty_recipient = Some(caller.clone());230 let royalty_amount = Some(Permill::from_percent(25));231 let metadata = create_data();232 let transferable = true;233 }: _(234 RawOrigin::Signed(caller),235 owner,236 collection_id,237 royalty_recipient,238 royalty_amount,239 metadata,240 transferable,241 Some(create_max_resource_types_array(b as usize))242 )243244 burn_nft {245 let b in 0..200;246247 let caller: T::AccountId = account("caller", 0, SEED);248 create_max_collection::<T>(&caller)?;249 let collection_id = 0;250251 let mut nft_builder = NftBuilder::new(collection_id);252 let root_nft_id = nft_builder.build_wide_tree::<T>(&caller, b)?;253 let max_burns = b + 1;254 }: _(255 RawOrigin::Signed(caller),256 collection_id,257 root_nft_id,258 max_burns259 )260261 send {262 let caller: T::AccountId = account("caller", 0, SEED);263 create_max_collection::<T>(&caller)?;264 let collection_id = 0;265266 let mut nft_builder = NftBuilder::new(collection_id);267 let src_nft_id = nft_builder.build::<T>(&caller)?;268 let (_, target_nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 2)?;269 }: _(270 RawOrigin::Signed(caller),271 collection_id,272 src_nft_id,273 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)274 )275276 accept_nft {277 let caller: T::AccountId = account("caller", 0, SEED);278 let sender: T::AccountId = account("sender", 0, SEED);279280 create_max_collection::<T>(&sender)?;281 let src_collection_id = 0;282283 create_max_collection::<T>(&caller)?;284 let target_collection_id = 1;285286 let mut src_nft_builder = NftBuilder::new(src_collection_id);287 let src_nft_id = src_nft_builder.build::<T>(&sender)?;288289 let mut target_nft_builder = NftBuilder::new(target_collection_id);290 let fake_target_nft_id = target_nft_builder.build::<T>(&caller)?;291 let (_, target_nft_id) = target_nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;292293 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(294 target_collection_id,295 fake_target_nft_id296 );297298 let actual_new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(299 target_collection_id,300 target_nft_id301 );302303 <Pallet<T>>::send(304 RawOrigin::Signed(sender.clone()).into(),305 src_collection_id,306 src_nft_id,307 new_owner,308 )?;309 }: _(310 RawOrigin::Signed(caller),311 src_collection_id,312 src_nft_id,313 actual_new_owner314 )315316 reject_nft {317 let caller: T::AccountId = account("caller", 0, SEED);318 let sender: T::AccountId = account("sender", 0, SEED);319320 create_max_collection::<T>(&sender)?;321 let src_collection_id = 0;322323 create_max_collection::<T>(&caller)?;324 let target_collection_id = 1;325326 let mut src_nft_builder = NftBuilder::new(src_collection_id);327 let (src_root_nft_id, _) = src_nft_builder.build_tower::<T>(&sender, NESTING_BUDGET - 1)?;328329 let mut target_nft_builder = NftBuilder::new(target_collection_id);330 let target_nft_id = target_nft_builder.build::<T>(&caller)?;331332 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(333 target_collection_id,334 target_nft_id335 );336337 <Pallet<T>>::send(338 RawOrigin::Signed(sender.clone()).into(),339 src_collection_id,340 src_root_nft_id,341 new_owner,342 )?;343 }: _(344 RawOrigin::Signed(caller),345 src_collection_id,346 src_root_nft_id347 )348349 set_property {350 let caller: T::AccountId = account("caller", 0, SEED);351 create_max_collection::<T>(&caller)?;352 let collection_id = 0;353354 let mut nft_builder = NftBuilder::new(collection_id);355 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;356357 let key = create_data();358 let value = create_data();359 }: _(360 RawOrigin::Signed(caller),361 collection_id,362 Some(nft_id),363 key,364 value365 )366367 set_priority {368 let caller: T::AccountId = account("caller", 0, SEED);369 create_max_collection::<T>(&caller)?;370 let collection_id = 0;371372 let mut nft_builder = NftBuilder::new(collection_id);373 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;374 let priorities = create_u32_array();375 }: _(376 RawOrigin::Signed(caller),377 collection_id,378 nft_id,379 priorities380 )381382 add_basic_resource {383 let caller: T::AccountId = account("caller", 0, SEED);384 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());385386 create_max_collection::<T>(&caller)?;387 let collection_id = 0;388389 let mut nft_builder = NftBuilder::new(collection_id);390 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;391 let resource = create_basic_resource();392 }: _(393 RawOrigin::Signed(caller),394 collection_id,395 nft_id,396 resource397 )398399 add_composable_resource {400 let caller: T::AccountId = account("caller", 0, SEED);401 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());402403 create_max_collection::<T>(&caller)?;404 let collection_id = 0;405406 let mut nft_builder = NftBuilder::new(collection_id);407 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;408 let resource = create_composable_resource();409 }: _(410 RawOrigin::Signed(caller),411 collection_id,412 nft_id,413 resource414 )415416 add_slot_resource {417 let caller: T::AccountId = account("caller", 0, SEED);418 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());419420 create_max_collection::<T>(&caller)?;421 let collection_id = 0;422423 let mut nft_builder = NftBuilder::new(collection_id);424 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;425 let resource = create_slot_resource();426 }: _(427 RawOrigin::Signed(caller),428 collection_id,429 nft_id,430 resource431 )432433 remove_resource {434 let caller: T::AccountId = account("caller", 0, SEED);435 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());436437 create_max_collection::<T>(&caller)?;438 let collection_id = 0;439440 let mut nft_builder = NftBuilder::new(collection_id);441 let (_, nft_id) = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 1)?;442 let resource = create_basic_resource();443444 <Pallet<T>>::add_basic_resource(445 RawOrigin::Signed(caller.clone()).into(),446 collection_id,447 nft_id,448 resource449 )?;450451 let resource_id = 1;452 }: _(453 RawOrigin::Signed(caller),454 collection_id,455 nft_id,456 resource_id457 )458459 accept_resource {460 let caller: T::AccountId = account("caller", 0, SEED);461 let admin: T::AccountId = account("admin", 0, SEED);462463 <T as pallet_common::Config>::Currency::deposit_creating(&admin, T::CollectionCreationPrice::get());464465 create_max_collection::<T>(&admin)?;466 let collection_id = 0;467468 let mut nft_builder = NftBuilder::new(collection_id);469 let root_nft_id = 1;470 let (_, nested_nft_id) = nft_builder.build_tower::<T>(&admin, NESTING_BUDGET - 1)?;471 let resource = create_basic_resource();472473 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::AccountId(caller.clone());474475 <Pallet<T>>::send(476 RawOrigin::Signed(admin.clone()).into(),477 collection_id,478 root_nft_id,479 new_owner,480 )?;481482 <Pallet<T>>::add_basic_resource(483 RawOrigin::Signed(admin.clone()).into(),484 collection_id,485 nested_nft_id,486 resource487 )?;488489 let resource_id = 1;490 }: _(491 RawOrigin::Signed(caller),492 collection_id,493 nested_nft_id,494 resource_id495 )496497 accept_resource_removal {498 let caller: T::AccountId = account("caller", 0, SEED);499 let admin: T::AccountId = account("admin", 0, SEED);500501 <T as pallet_common::Config>::Currency::deposit_creating(&admin, T::CollectionCreationPrice::get());502503 create_max_collection::<T>(&admin)?;504 let collection_id = 0;505506 let mut nft_builder = NftBuilder::new(collection_id);507 let root_nft_id = 1;508 let (_, nested_nft_id) = nft_builder.build_tower::<T>(&admin, NESTING_BUDGET - 1)?;509 let resource = create_basic_resource();510511 <Pallet<T>>::add_basic_resource(512 RawOrigin::Signed(admin.clone()).into(),513 collection_id,514 nested_nft_id,515 resource516 )?;517518 let resource_id = 1;519520 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::AccountId(caller.clone());521522 <Pallet<T>>::send(523 RawOrigin::Signed(admin.clone()).into(),524 collection_id,525 root_nft_id,526 new_owner,527 )?;528529 <Pallet<T>>::remove_resource(530 RawOrigin::Signed(admin).into(),531 collection_id,532 nested_nft_id,533 resource_id534 )?;535 }: _(536 RawOrigin::Signed(caller),537 collection_id,538 nested_nft_id,539 resource_id540 )541}pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -353,7 +353,7 @@
royalty_amount: Option<Permill>,
metadata: RmrkString,
transferable: bool,
- resources: Option<BoundedVec<RmrkResourceTypes, MaxResourcesOnMint>>
+ resources: Option<BoundedVec<RmrkResourceTypes, MaxResourcesOnMint>>,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
let cross_sender = T::CrossAccountId::from_sub(sender.clone());
@@ -393,12 +393,7 @@
if let Some(resources) = resources {
for resource in resources {
- Self::resource_add(
- sender.clone(),
- collection.id,
- nft_id,
- resource
- )?;
+ Self::resource_add(sender.clone(), collection.id, nft_id, resource)?;
}
}
@@ -963,7 +958,7 @@
sender,
collection_id,
nft_id.into(),
- RmrkResourceTypes::Composable(resource)
+ RmrkResourceTypes::Composable(resource),
)?;
Self::deposit_event(Event::ResourceAdded {
@@ -1162,61 +1157,55 @@
sender: T::AccountId,
collection_id: CollectionId,
nft_id: TokenId,
- resource: RmrkResourceTypes
+ resource: RmrkResourceTypes,
) -> Result<RmrkResourceId, DispatchError> {
match resource {
- RmrkResourceTypes::Basic(resource) => {
- Self::resource_add_helper(
- sender,
- collection_id,
- nft_id,
- [
- Self::rmrk_property(TokenType, &NftType::Resource)?,
- Self::rmrk_property(ResourceType, &misc::ResourceType::Basic)?,
- Self::rmrk_property(Src, &resource.src)?,
- Self::rmrk_property(Metadata, &resource.metadata)?,
- Self::rmrk_property(License, &resource.license)?,
- Self::rmrk_property(Thumb, &resource.thumb)?,
- ]
- .into_iter(),
- )
- },
- RmrkResourceTypes::Composable(resource) => {
- Self::resource_add_helper(
- sender,
- collection_id,
- nft_id.into(),
- [
- Self::rmrk_property(TokenType, &NftType::Resource)?,
- Self::rmrk_property(ResourceType, &misc::ResourceType::Composable)?,
- Self::rmrk_property(Parts, &resource.parts)?,
- Self::rmrk_property(Base, &resource.base)?,
- Self::rmrk_property(Src, &resource.src)?,
- Self::rmrk_property(Metadata, &resource.metadata)?,
- Self::rmrk_property(License, &resource.license)?,
- Self::rmrk_property(Thumb, &resource.thumb)?,
- ]
- .into_iter(),
- )
- },
- RmrkResourceTypes::Slot(resource) => {
- Self::resource_add_helper(
- sender,
- collection_id,
- nft_id.into(),
- [
- Self::rmrk_property(TokenType, &NftType::Resource)?,
- Self::rmrk_property(ResourceType, &misc::ResourceType::Slot)?,
- Self::rmrk_property(Base, &resource.base)?,
- Self::rmrk_property(Src, &resource.src)?,
- Self::rmrk_property(Metadata, &resource.metadata)?,
- Self::rmrk_property(Slot, &resource.slot)?,
- Self::rmrk_property(License, &resource.license)?,
- Self::rmrk_property(Thumb, &resource.thumb)?,
- ]
- .into_iter(),
- )
- }
+ RmrkResourceTypes::Basic(resource) => Self::resource_add_helper(
+ sender,
+ collection_id,
+ nft_id,
+ [
+ Self::rmrk_property(TokenType, &NftType::Resource)?,
+ Self::rmrk_property(ResourceType, &misc::ResourceType::Basic)?,
+ Self::rmrk_property(Src, &resource.src)?,
+ Self::rmrk_property(Metadata, &resource.metadata)?,
+ Self::rmrk_property(License, &resource.license)?,
+ Self::rmrk_property(Thumb, &resource.thumb)?,
+ ]
+ .into_iter(),
+ ),
+ RmrkResourceTypes::Composable(resource) => Self::resource_add_helper(
+ sender,
+ collection_id,
+ nft_id.into(),
+ [
+ Self::rmrk_property(TokenType, &NftType::Resource)?,
+ Self::rmrk_property(ResourceType, &misc::ResourceType::Composable)?,
+ Self::rmrk_property(Parts, &resource.parts)?,
+ Self::rmrk_property(Base, &resource.base)?,
+ Self::rmrk_property(Src, &resource.src)?,
+ Self::rmrk_property(Metadata, &resource.metadata)?,
+ Self::rmrk_property(License, &resource.license)?,
+ Self::rmrk_property(Thumb, &resource.thumb)?,
+ ]
+ .into_iter(),
+ ),
+ RmrkResourceTypes::Slot(resource) => Self::resource_add_helper(
+ sender,
+ collection_id,
+ nft_id.into(),
+ [
+ Self::rmrk_property(TokenType, &NftType::Resource)?,
+ Self::rmrk_property(ResourceType, &misc::ResourceType::Slot)?,
+ Self::rmrk_property(Base, &resource.base)?,
+ Self::rmrk_property(Src, &resource.src)?,
+ Self::rmrk_property(Metadata, &resource.metadata)?,
+ Self::rmrk_property(Slot, &resource.slot)?,
+ Self::rmrk_property(License, &resource.license)?,
+ Self::rmrk_property(Thumb, &resource.thumb)?,
+ ]
+ .into_iter(),
+ ),
}
}