difftreelog
fix remove native ft from childrens
in: master
4 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- 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<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {
fn create_item(
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- 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 = <pallet_balances::Pallet<T>>::free_balance(address.as_sub());
-
- balance > T::Balance::default()
- || <TokenChildren<T>>::iter_prefix((collection_id, token_id))
- .next()
- .is_some()
+ <TokenChildren<T>>::iter_prefix((collection_id, token_id))
+ .next()
+ .is_some()
}
pub fn token_children_ids(collection_id: CollectionId, token_id: TokenId) -> Vec<TokenChild> {
- let mut tokens: Vec<_> = vec![];
-
- let address = T::CrossTokenAddressMapping::token_to_address(collection_id, token_id);
- let balance = <pallet_balances::Pallet<T>>::free_balance(address.as_sub());
- if balance > T::Balance::default() {
- tokens.push(TokenChild {
- token: TokenId(0),
- collection: pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID,
+ <TokenChildren<T>>::iter_prefix((collection_id, token_id))
+ .map(|((child_collection_id, child_id), _)| TokenChild {
+ collection: child_collection_id,
+ token: child_id,
})
- }
-
- tokens.extend(
- <TokenChildren<T>>::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.
tests/src/sub/nesting/common.test.tsdiffbeforeafterboth--- 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);
});
});
tests/src/sub/nesting/e2e.test.tsdiffbeforeafterboth80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},81 {tokenId: 0, collectionId: collectionB.collectionId},81 {tokenId: 0, collectionId: collectionB.collectionId},82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},83 {tokenId: 0, collectionId: collectionNative.collectionId},84 ]).and.has.length(4);83 ]).and.has.length(3);858486 // Burn all nested pieces85 // Burn all nested pieces87 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);86 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);88 expect(await targetToken.getChildren()).to.have.deep.members([87 expect(await targetToken.getChildren()).to.have.deep.members([89 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},88 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},90 {tokenId: 0, collectionId: collectionB.collectionId},89 {tokenId: 0, collectionId: collectionB.collectionId},91 {tokenId: 0, collectionId: collectionNative.collectionId},92 ])90 ])93 .and.has.length(3);91 .and.has.length(2);949295 // Move part of the fungible token inside token A deeper in the nesting tree93 // Move part of the fungible token inside token A deeper in the nesting tree96 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);94 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);97 expect(await targetToken.getChildren()).to.be.have.deep.members([95 expect(await targetToken.getChildren()).to.be.have.deep.members([98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},96 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},99 {tokenId: 0, collectionId: collectionB.collectionId},97 {tokenId: 0, collectionId: collectionB.collectionId},100 {tokenId: 0, collectionId: collectionNative.collectionId},101 ]).and.has.length(3);98 ]).and.has.length(2);102 // Nested token also has children now:99 // Nested token also has children now:103 expect(await tokenA.getChildren()).to.have.deep.members([100 expect(await tokenA.getChildren()).to.have.deep.members([104 {tokenId: 0, collectionId: collectionB.collectionId},101 {tokenId: 0, collectionId: collectionB.collectionId},108 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);105 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);109 expect(await targetToken.getChildren()).to.have.deep.members([106 expect(await targetToken.getChildren()).to.have.deep.members([110 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},111 {tokenId: 0, collectionId: collectionNative.collectionId},112 ]).and.has.length(2);108 ]).and.has.length(1);113 expect(await tokenA.getChildren()).to.have.deep.members([109 expect(await tokenA.getChildren()).to.have.deep.members([114 {tokenId: 0, collectionId: collectionB.collectionId},110 {tokenId: 0, collectionId: collectionB.collectionId},115 ]).and.has.length(1);111 ]).and.has.length(1);