From d4fac3e08a685bb09b0b5ad3f9db353474fe3c71 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 09 Jun 2022 22:24:53 +0000 Subject: [PATCH] feat(rmrk): benchmark accept_nft --- --- a/pallets/proxy-rmrk-core/src/benchmarking.rs +++ b/pallets/proxy-rmrk-core/src/benchmarking.rs @@ -45,12 +45,12 @@ ) } -struct NftTowerBuilder { +struct NftBuilder { collection_id: RmrkCollectionId, current_nft_id: RmrkNftId } -impl NftTowerBuilder { +impl NftBuilder { fn new(collection_id: RmrkCollectionId) -> Self { Self { collection_id, @@ -58,15 +58,20 @@ } } - fn build(&mut self, owner: &T::AccountId, height: u32) -> Result { + fn build(&mut self, owner: &T::AccountId) -> Result { create_max_nft::(owner, self.collection_id)?; self.current_nft_id += 1; + Ok(self.current_nft_id) + } + + fn build_tower(&mut self, owner: &T::AccountId, height: u32) -> Result { + self.build::(owner)?; + 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; + self.build::(owner)?; let new_owner = >::CollectionAndNftTuple( self.collection_id, @@ -149,13 +154,53 @@ 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)?; + let mut nft_builder = NftBuilder::new(collection_id); + let src_nft_id = nft_builder.build::(&caller)?; + let target_nft_id = nft_builder.build_tower::(&caller, NESTING_BUDGET - 2)?; }: _( RawOrigin::Signed(caller), collection_id, src_nft_id, >::CollectionAndNftTuple(collection_id, target_nft_id) ) + + accept_nft { + let caller: T::AccountId = account("caller", 0, SEED); + let sender: T::AccountId = account("sender", 0, SEED); + + create_max_collection::(&sender)?; + let src_collection_id = 0; + + create_max_collection::(&caller)?; + let target_collection_id = 1; + + let mut src_nft_builder = NftBuilder::new(src_collection_id); + let src_nft_id = src_nft_builder.build::(&sender)?; + + let mut target_nft_builder = NftBuilder::new(target_collection_id); + let fake_target_nft_id = target_nft_builder.build::(&caller)?; + let target_nft_id = target_nft_builder.build_tower::(&caller, NESTING_BUDGET - 1)?; + + let new_owner = >::CollectionAndNftTuple( + target_collection_id, + fake_target_nft_id + ); + + let actual_new_owner = >::CollectionAndNftTuple( + target_collection_id, + target_nft_id + ); + + >::send( + RawOrigin::Signed(sender.clone()).into(), + src_collection_id, + src_nft_id, + new_owner, + )?; + }: _( + RawOrigin::Signed(caller), + src_collection_id, + src_nft_id, + actual_new_owner + ) } -- gitstuff