From 2c6fa32b7608611edeea955d7f6f29e388d1669c Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Tue, 23 May 2023 09:12:13 +0000 Subject: [PATCH] fix: remove native ft from childrens --- --- a/pallets/balances-adapter/src/common.rs +++ b/pallets/balances-adapter/src/common.rs @@ -85,7 +85,7 @@ } } -/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete +/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallet /// methods and adds weight info. impl CommonCollectionOperations for NativeFungibleHandle { fn create_item( --- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -1347,37 +1347,18 @@ } fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool { - let address = T::CrossTokenAddressMapping::token_to_address(collection_id, token_id); - let balance = >::free_balance(address.as_sub()); - - balance > T::Balance::default() - || >::iter_prefix((collection_id, token_id)) - .next() - .is_some() + >::iter_prefix((collection_id, token_id)) + .next() + .is_some() } pub fn token_children_ids(collection_id: CollectionId, token_id: TokenId) -> Vec { - let mut tokens: Vec<_> = vec![]; - - let address = T::CrossTokenAddressMapping::token_to_address(collection_id, token_id); - let balance = >::free_balance(address.as_sub()); - if balance > T::Balance::default() { - tokens.push(TokenChild { - token: TokenId(0), - collection: pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID, + >::iter_prefix((collection_id, token_id)) + .map(|((child_collection_id, child_id), _)| TokenChild { + collection: child_collection_id, + token: child_id, }) - } - - tokens.extend( - >::iter_prefix((collection_id, token_id)).map( - |((child_collection_id, child_id), _)| TokenChild { - collection: child_collection_id, - token: child_id, - }, - ), - ); - - tokens + .collect() } /// Mint single NFT token. --- a/tests/src/sub/nesting/common.test.ts +++ b/tests/src/sub/nesting/common.test.ts @@ -109,7 +109,8 @@ // Bob can nest Native FT into their NFT: await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n); expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n); - expect(await targetTokenBob.getChildren()).to.be.deep.equal([{collectionId: 0, tokenId: 0}]); + // Native FT should't be visible in NFT children: + expect(await targetTokenBob.getChildren()).to.be.deep.equal([]); }); }); @@ -134,7 +135,7 @@ expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n); expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n); - expect(await tokenA.getChildren()).to.be.length(4); + expect(await tokenA.getChildren()).to.be.length(3); expect(await tokenB.getChildren()).to.be.length(0); // Transfer the nested token to another token @@ -155,9 +156,9 @@ expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n); expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n); - // RFT, FT, and native FT - expect(await tokenA.getChildren()).to.be.length(3); - // NFT, RFT, FT, and native FT - expect(await tokenB.getChildren()).to.be.length(4); + // RFT, FT, and without native FT + expect(await tokenA.getChildren()).to.be.length(2); + // NFT, RFT, FT, and without native FT + expect(await tokenB.getChildren()).to.be.length(3); }); }); --- a/tests/src/sub/nesting/e2e.test.ts +++ b/tests/src/sub/nesting/e2e.test.ts @@ -80,25 +80,22 @@ {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId}, {tokenId: 0, collectionId: collectionB.collectionId}, {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId}, - {tokenId: 0, collectionId: collectionNative.collectionId}, - ]).and.has.length(4); + ]).and.has.length(3); // Burn all nested pieces await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n); expect(await targetToken.getChildren()).to.have.deep.members([ {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId}, {tokenId: 0, collectionId: collectionB.collectionId}, - {tokenId: 0, collectionId: collectionNative.collectionId}, ]) - .and.has.length(3); + .and.has.length(2); // Move part of the fungible token inside token A deeper in the nesting tree await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n); expect(await targetToken.getChildren()).to.be.have.deep.members([ {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId}, {tokenId: 0, collectionId: collectionB.collectionId}, - {tokenId: 0, collectionId: collectionNative.collectionId}, - ]).and.has.length(3); + ]).and.has.length(2); // Nested token also has children now: expect(await tokenA.getChildren()).to.have.deep.members([ {tokenId: 0, collectionId: collectionB.collectionId}, @@ -108,8 +105,7 @@ await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n); expect(await targetToken.getChildren()).to.have.deep.members([ {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId}, - {tokenId: 0, collectionId: collectionNative.collectionId}, - ]).and.has.length(2); + ]).and.has.length(1); expect(await tokenA.getChildren()).to.have.deep.members([ {tokenId: 0, collectionId: collectionB.collectionId}, ]).and.has.length(1); -- gitstuff