difftreelog
fix remove native ft from childrens
in: master
4 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth85 }85 }86}86}878788/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete88/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallet89/// methods and adds weight info.89/// methods and adds weight info.90impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {90impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {91 fn create_item(91 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.tsdiffbeforeafterboth--- 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);