--- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -604,7 +604,7 @@ // ========= - >::unnest_if_nested(from, collection.id, token); + >::unnest_if_nested(&token_data.owner, collection.id, token); >::insert( (collection.id, token), --- a/pallets/structure/src/lib.rs +++ b/pallets/structure/src/lib.rs @@ -191,8 +191,8 @@ token_id: TokenId, nesting_budget: &dyn Budget, ) -> DispatchResult { - Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| { - d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget) + Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| { + collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget) }) } @@ -203,10 +203,10 @@ token_id: TokenId, nesting_budget: &dyn Budget, ) -> DispatchResult { - Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| { - d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?; + Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| { + collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?; - d.nest(parent_id, (collection_id, token_id)); + collection.nest(parent_id, (collection_id, token_id)); Ok(()) }) @@ -217,8 +217,8 @@ collection_id: CollectionId, token_id: TokenId, ) { - Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| { - d.nest(parent_id, (collection_id, token_id)) + Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| { + collection.nest(parent_id, (collection_id, token_id)) }); } @@ -227,8 +227,8 @@ collection_id: CollectionId, token_id: TokenId, ) { - Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| { - d.unnest(parent_id, (collection_id, token_id)) + Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| { + collection.unnest(parent_id, (collection_id, token_id)) }); } @@ -236,8 +236,8 @@ account: &T::CrossAccountId, action: impl FnOnce(&dyn CommonCollectionOperations, TokenId), ) { - Self::try_exec_if_owner_is_valid_nft(account, |d, id| { - action(d, id); + Self::try_exec_if_owner_is_valid_nft(account, |collection, id| { + action(collection, id); Ok(()) }) .unwrap(); --- a/tests/src/nesting/nest.test.ts +++ b/tests/src/nesting/nest.test.ts @@ -78,8 +78,8 @@ api, alice, api.tx.unique.transferFrom( - normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), - normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), + normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), + normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), collection, tokenC, 1, @@ -120,13 +120,13 @@ ], 'Children contents check at nesting #2'); // Move token B to a different user outside the nesting tree - await transferFromExpectSuccess(collectionA, tokenB, alice, targetAddress, bob); + await transferExpectSuccess(collectionA, tokenB, alice, bob); children = await getTokenChildren(api, collectionA, targetToken); expect(children.length).to.be.equal(1, 'Children length check at unnesting'); expect(children).to.be.have.deep.members([ {token: tokenA, collection: collectionA}, ], 'Children contents check at unnesting'); - + // Create a fungible token in another collection and then nest const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible'); await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible'); @@ -287,20 +287,6 @@ await usingApi(async () => { alice = privateKey('//Alice'); bob = privateKey('//Bob'); - }); - }); - - // TODO delete if this is actually wrong - // TODO remake all other nesting tests if this is right - it('Affirms that transfer is disallowed to transfer nested tokens', async () => { - await usingApi(async () => { - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'}); - - const tokenA = await createItemExpectSuccess(alice, collection, 'NFT'); - const tokenB = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)}); - - await transferExpectFailure(collection, tokenB, alice, bob); }); });