git.delta.rocks / unique-network / refs/commits / 004643cad6df

difftreelog

fix unnest NFT from parent

Daniel Shiposha2022-06-03parent: #4d135e3.patch.diff
in: master

3 files changed

modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
604604
605 // =========605 // =========
606606
607 <PalletStructure<T>>::unnest_if_nested(from, collection.id, token);607 <PalletStructure<T>>::unnest_if_nested(&token_data.owner, collection.id, token);
608608
609 <TokenData<T>>::insert(609 <TokenData<T>>::insert(
610 (collection.id, token),610 (collection.id, token),
modifiedpallets/structure/src/lib.rsdiffbeforeafterboth
191 token_id: TokenId,191 token_id: TokenId,
192 nesting_budget: &dyn Budget,192 nesting_budget: &dyn Budget,
193 ) -> DispatchResult {193 ) -> DispatchResult {
194 Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {194 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {
195 d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)195 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)
196 })196 })
197 }197 }
198198
203 token_id: TokenId,203 token_id: TokenId,
204 nesting_budget: &dyn Budget,204 nesting_budget: &dyn Budget,
205 ) -> DispatchResult {205 ) -> DispatchResult {
206 Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {206 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {
207 d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;207 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;
208208
209 d.nest(parent_id, (collection_id, token_id));209 collection.nest(parent_id, (collection_id, token_id));
210210
211 Ok(())211 Ok(())
212 })212 })
217 collection_id: CollectionId,217 collection_id: CollectionId,
218 token_id: TokenId,218 token_id: TokenId,
219 ) {219 ) {
220 Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {220 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {
221 d.nest(parent_id, (collection_id, token_id))221 collection.nest(parent_id, (collection_id, token_id))
222 });222 });
223 }223 }
224224
227 collection_id: CollectionId,227 collection_id: CollectionId,
228 token_id: TokenId,228 token_id: TokenId,
229 ) {229 ) {
230 Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {230 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {
231 d.unnest(parent_id, (collection_id, token_id))231 collection.unnest(parent_id, (collection_id, token_id))
232 });232 });
233 }233 }
234234
235 fn exec_if_owner_is_valid_nft(235 fn exec_if_owner_is_valid_nft(
236 account: &T::CrossAccountId,236 account: &T::CrossAccountId,
237 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),237 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),
238 ) {238 ) {
239 Self::try_exec_if_owner_is_valid_nft(account, |d, id| {239 Self::try_exec_if_owner_is_valid_nft(account, |collection, id| {
240 action(d, id);240 action(collection, id);
241 Ok(())241 Ok(())
242 })242 })
243 .unwrap();243 .unwrap();
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
120 ], 'Children contents check at nesting #2');120 ], 'Children contents check at nesting #2');
121121
122 // Move token B to a different user outside the nesting tree122 // Move token B to a different user outside the nesting tree
123 await transferFromExpectSuccess(collectionA, tokenB, alice, targetAddress, bob);123 await transferExpectSuccess(collectionA, tokenB, alice, bob);
124 children = await getTokenChildren(api, collectionA, targetToken);124 children = await getTokenChildren(api, collectionA, targetToken);
125 expect(children.length).to.be.equal(1, 'Children length check at unnesting');125 expect(children.length).to.be.equal(1, 'Children length check at unnesting');
126 expect(children).to.be.have.deep.members([126 expect(children).to.be.have.deep.members([
290 });290 });
291 });291 });
292
293 // TODO delete if this is actually wrong
294 // TODO remake all other nesting tests if this is right
295 it('Affirms that transfer is disallowed to transfer nested tokens', async () => {
296 await usingApi(async () => {
297 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
298 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
299
300 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');
301 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});
302
303 await transferExpectFailure(collection, tokenB, alice, bob);
304 });
305 });
306292
307 it('Disallows excessive token nesting', async () => {293 it('Disallows excessive token nesting', async () => {
308 await usingApi(async api => {294 await usingApi(async api => {