git.delta.rocks / unique-network / refs/commits / d4fac3e08a68

difftreelog

feat(rmrk) benchmark accept_nft

Daniel Shiposha2022-06-09parent: #5f417e8.patch.diff
in: master

1 file changed

modifiedpallets/proxy-rmrk-core/src/benchmarking.rsdiffbeforeafterboth
45 )45 )
46}46}
4747
48struct NftTowerBuilder {48struct NftBuilder {
49 collection_id: RmrkCollectionId,49 collection_id: RmrkCollectionId,
50 current_nft_id: RmrkNftId50 current_nft_id: RmrkNftId
51}51}
5252
53impl NftTowerBuilder {53impl NftBuilder {
54 fn new(collection_id: RmrkCollectionId) -> Self {54 fn new(collection_id: RmrkCollectionId) -> Self {
55 Self {55 Self {
56 collection_id,56 collection_id,
57 current_nft_id: 057 current_nft_id: 0
58 }58 }
59 }59 }
6060
61 fn build<T: Config>(&mut self, owner: &T::AccountId, height: u32) -> Result<RmrkNftId, DispatchError> {61 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;
64
65 Ok(self.current_nft_id)
66 }
67
68 fn build_tower<T: Config>(&mut self, owner: &T::AccountId, height: u32) -> Result<RmrkNftId, DispatchError> {
62 create_max_nft::<T>(owner, self.collection_id)?;69 self.build::<T>(owner)?;
63 self.current_nft_id += 1;
6470
65 let mut prev_nft_id = self.current_nft_id;71 let mut prev_nft_id = self.current_nft_id;
6672
67 for _ in 0..height {73 for _ in 0..height {
68 create_max_nft::<T>(owner, self.collection_id)?;74 self.build::<T>(owner)?;
69 self.current_nft_id += 1;75
70
71 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(76 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(
72 self.collection_id,77 self.collection_id,
149 create_max_collection::<T>(&caller)?;154 create_max_collection::<T>(&caller)?;
150 let collection_id = 0;155 let collection_id = 0;
151156
152 let mut nft_tower_builder = NftTowerBuilder::new(collection_id);157 let mut nft_builder = NftBuilder::new(collection_id);
153 let src_nft_id = nft_tower_builder.build::<T>(&caller, 0)?;158 let src_nft_id = nft_builder.build::<T>(&caller)?;
154 let target_nft_id = nft_tower_builder.build::<T>(&caller, NESTING_BUDGET - 2)?;159 let target_nft_id = nft_builder.build_tower::<T>(&caller, NESTING_BUDGET - 2)?;
155 }: _(160 }: _(
156 RawOrigin::Signed(caller),161 RawOrigin::Signed(caller),
157 collection_id,162 collection_id,
158 src_nft_id,163 src_nft_id,
159 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)164 <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(collection_id, target_nft_id)
160 )165 )
166
167 accept_nft {
168 let caller: T::AccountId = account("caller", 0, SEED);
169 let sender: T::AccountId = account("sender", 0, SEED);
170
171 create_max_collection::<T>(&sender)?;
172 let src_collection_id = 0;
173
174 create_max_collection::<T>(&caller)?;
175 let target_collection_id = 1;
176
177 let mut src_nft_builder = NftBuilder::new(src_collection_id);
178 let src_nft_id = src_nft_builder.build::<T>(&sender)?;
179
180 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)?;
183
184 let new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(
185 target_collection_id,
186 fake_target_nft_id
187 );
188
189 let actual_new_owner = <RmrkAccountIdOrCollectionNftTuple<T::AccountId>>::CollectionAndNftTuple(
190 target_collection_id,
191 target_nft_id
192 );
193
194 <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_owner
205 )
161}206}
162207