From 5f417e832e489f8ecf99512c2adbce5e23201301 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 09 Jun 2022 21:55:22 +0000 Subject: [PATCH] feat(rmrk): benchmark send --- --- a/pallets/proxy-rmrk-core/src/benchmarking.rs +++ b/pallets/proxy-rmrk-core/src/benchmarking.rs @@ -18,18 +18,77 @@ vec![0; S::get() as usize].try_into().expect("size == S") } -fn create_max_collection(owner: &T::AccountId) -> Result { +fn create_max_collection(owner: &T::AccountId) -> DispatchResult { ::Currency::deposit_creating(owner, T::CollectionCreationPrice::get()); let metadata = create_data(); let max = None; let symbol = create_data(); - >::create_collection(RawOrigin::Signed(owner.clone()).into(), metadata, max, symbol)?; + >::create_collection(RawOrigin::Signed(owner.clone()).into(), metadata, max, symbol) +} - Ok(>::get() - 1) +fn create_max_nft(owner: &T::AccountId, collection_id: RmrkCollectionId) -> DispatchResult { + let royalty_recipient = Some(owner.clone()); + let royalty_amount = Some(Permill::from_percent(25)); + let metadata = create_data(); + let transferable = true; + + >::mint_nft( + RawOrigin::Signed(owner.clone()).into(), + owner.clone(), + collection_id, + royalty_recipient, + royalty_amount, + metadata, + transferable + ) } +struct NftTowerBuilder { + collection_id: RmrkCollectionId, + current_nft_id: RmrkNftId +} + +impl NftTowerBuilder { + fn new(collection_id: RmrkCollectionId) -> Self { + Self { + collection_id, + current_nft_id: 0 + } + } + + fn build(&mut self, owner: &T::AccountId, height: u32) -> Result { + create_max_nft::(owner, self.collection_id)?; + self.current_nft_id += 1; + + let mut prev_nft_id = self.current_nft_id; + + for _ in 0..height { + create_max_nft::(owner, self.collection_id)?; + self.current_nft_id += 1; + + let new_owner = >::CollectionAndNftTuple( + self.collection_id, + prev_nft_id + ); + + >::send( + RawOrigin::Signed(owner.clone()).into(), + self.collection_id, + self.current_nft_id, + new_owner, + )?; + + prev_nft_id = self.current_nft_id; + } + + let deepest_nft_id = self.current_nft_id; + + Ok(deepest_nft_id) + } +} + benchmarks! { create_collection { let caller = account("caller", 0, SEED); @@ -41,12 +100,17 @@ destroy_collection { let caller = account("caller", 0, SEED); - let collection_id = create_max_collection::(&caller)?; + + create_max_collection::(&caller)?; + let collection_id = 0; }: _(RawOrigin::Signed(caller), collection_id) change_collection_issuer { let caller: T::AccountId = account("caller", 0, SEED); - let collection_id = create_max_collection::(&caller)?; + + create_max_collection::(&caller)?; + let collection_id = 0; + let new_owner: T::AccountId = account("new_owner", 0, SEED); let new_owner_source = T::Lookup::unlookup(new_owner); @@ -54,12 +118,16 @@ lock_collection { let caller: T::AccountId = account("caller", 0, SEED); - let collection_id = create_max_collection::(&caller)?; + + create_max_collection::(&caller)?; + let collection_id = 0; }: _(RawOrigin::Signed(caller), collection_id) mint_nft { let caller: T::AccountId = account("caller", 0, SEED); - let collection_id = create_max_collection::(&caller)?; + + create_max_collection::(&caller)?; + let collection_id = 0; let owner = caller.clone(); let royalty_recipient = Some(caller.clone()); @@ -75,4 +143,19 @@ metadata, transferable ) + + send { + let caller: T::AccountId = account("caller", 0, SEED); + create_max_collection::(&caller)?; + let collection_id = 0; + + let mut nft_tower_builder = NftTowerBuilder::new(collection_id); + let src_nft_id = nft_tower_builder.build::(&caller, 0)?; + let target_nft_id = nft_tower_builder.build::(&caller, NESTING_BUDGET - 2)?; + }: _( + RawOrigin::Signed(caller), + collection_id, + src_nft_id, + >::CollectionAndNftTuple(collection_id, target_nft_id) + ) } --- a/pallets/proxy-rmrk-core/src/lib.rs +++ b/pallets/proxy-rmrk-core/src/lib.rs @@ -45,7 +45,7 @@ use RmrkProperty::*; -const NESTING_BUDGET: u32 = 5; +pub const NESTING_BUDGET: u32 = 5; #[frame_support::pallet] pub mod pallet { -- gitstuff