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.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../../util';1920describe('Composite nesting tests', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({url: import.meta.url});27 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);28 });29 });3031 itSub('Checks token children e2e', async ({helper}) => {32 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const collectionB = await helper.ft.mintCollection(alice);34 const collectionC = await helper.rft.mintCollection(alice);35 const collectionNative = helper.ft.getCollectionObject(0);3637 const targetToken = await collectionA.mintToken(alice);38 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');3940 // Create a nested NFT token41 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());42 expect(await targetToken.getChildren()).to.have.deep.members([43 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},44 ]).and.has.length(1);4546 // Create then nest47 const tokenB = await collectionA.mintToken(alice);48 await tokenB.nest(alice, targetToken);49 expect(await targetToken.getChildren()).to.have.deep.members([50 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},51 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},52 ]).and.has.length(2);5354 // Move token B to a different user outside the nesting tree55 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});56 expect(await targetToken.getChildren()).to.have.deep.members([57 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},58 ]).and.has.length(1);5960 // Create a fungible token in another collection and then nest61 await collectionB.mint(alice, 10n);62 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);63 expect(await targetToken.getChildren()).to.have.deep.members([64 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},65 {tokenId: 0, collectionId: collectionB.collectionId},66 ]).and.has.length(2);6768 // Create a refungible token in another collection and then nest69 const tokenC = await collectionC.mintToken(alice, 10n);70 await tokenC.transfer(alice, targetToken.nestingAccount(), 2n);71 expect(await targetToken.getChildren()).to.have.deep.members([72 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},73 {tokenId: 0, collectionId: collectionB.collectionId},74 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},75 ]).and.has.length(3);7677 // Nest native fungible token into another collection78 await collectionNative.transfer(alice, targetToken.nestingAccount(), 2n);79 expect(await targetToken.getChildren()).to.have.deep.members([80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},81 {tokenId: 0, collectionId: collectionB.collectionId},82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},83 {tokenId: 0, collectionId: collectionNative.collectionId},84 ]).and.has.length(4);8586 // Burn all nested pieces87 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);88 expect(await targetToken.getChildren()).to.have.deep.members([89 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},90 {tokenId: 0, collectionId: collectionB.collectionId},91 {tokenId: 0, collectionId: collectionNative.collectionId},92 ])93 .and.has.length(3);9495 // Move part of the fungible token inside token A deeper in the nesting tree96 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);97 expect(await targetToken.getChildren()).to.be.have.deep.members([98 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},99 {tokenId: 0, collectionId: collectionB.collectionId},100 {tokenId: 0, collectionId: collectionNative.collectionId},101 ]).and.has.length(3);102 // Nested token also has children now:103 expect(await tokenA.getChildren()).to.have.deep.members([104 {tokenId: 0, collectionId: collectionB.collectionId},105 ]).and.has.length(1);106107 // Move the remaining part of the fungible token inside token A deeper in the nesting tree108 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);109 expect(await targetToken.getChildren()).to.have.deep.members([110 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},111 {tokenId: 0, collectionId: collectionNative.collectionId},112 ]).and.has.length(2);113 expect(await tokenA.getChildren()).to.have.deep.members([114 {tokenId: 0, collectionId: collectionB.collectionId},115 ]).and.has.length(1);116 });117118 /// TODO review this test119 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {120 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});121 const targetToken = await collection.mintToken(alice);122123 // Create an immediately nested token124 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());125 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});126 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());127128 // Create a token to be nested129 const newToken = await collection.mintToken(alice);130131 // Nest132 await newToken.nest(alice, targetToken);133 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});134 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());135136 // Move bundle to different user137 await targetToken.transfer(alice, {Substrate: bob.address});138 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});139 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());140 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});141 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());142143 // Unnest144 await newToken.unnest(bob, targetToken, {Substrate: bob.address});145 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});146 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});147 });148});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../../util';1920describe('Composite nesting tests', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({url: import.meta.url});27 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);28 });29 });3031 itSub('Checks token children e2e', async ({helper}) => {32 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const collectionB = await helper.ft.mintCollection(alice);34 const collectionC = await helper.rft.mintCollection(alice);35 const collectionNative = helper.ft.getCollectionObject(0);3637 const targetToken = await collectionA.mintToken(alice);38 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');3940 // Create a nested NFT token41 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());42 expect(await targetToken.getChildren()).to.have.deep.members([43 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},44 ]).and.has.length(1);4546 // Create then nest47 const tokenB = await collectionA.mintToken(alice);48 await tokenB.nest(alice, targetToken);49 expect(await targetToken.getChildren()).to.have.deep.members([50 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},51 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},52 ]).and.has.length(2);5354 // Move token B to a different user outside the nesting tree55 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});56 expect(await targetToken.getChildren()).to.have.deep.members([57 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},58 ]).and.has.length(1);5960 // Create a fungible token in another collection and then nest61 await collectionB.mint(alice, 10n);62 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);63 expect(await targetToken.getChildren()).to.have.deep.members([64 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},65 {tokenId: 0, collectionId: collectionB.collectionId},66 ]).and.has.length(2);6768 // Create a refungible token in another collection and then nest69 const tokenC = await collectionC.mintToken(alice, 10n);70 await tokenC.transfer(alice, targetToken.nestingAccount(), 2n);71 expect(await targetToken.getChildren()).to.have.deep.members([72 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},73 {tokenId: 0, collectionId: collectionB.collectionId},74 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},75 ]).and.has.length(3);7677 // Nest native fungible token into another collection78 await collectionNative.transfer(alice, targetToken.nestingAccount(), 2n);79 expect(await targetToken.getChildren()).to.have.deep.members([80 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},81 {tokenId: 0, collectionId: collectionB.collectionId},82 {tokenId: tokenC.tokenId, collectionId: collectionC.collectionId},83 ]).and.has.length(3);8485 // Burn all nested pieces86 await tokenC.burnFrom(alice, targetToken.nestingAccount(), 2n);87 expect(await targetToken.getChildren()).to.have.deep.members([88 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},89 {tokenId: 0, collectionId: collectionB.collectionId},90 ])91 .and.has.length(2);9293 // Move part of the fungible token inside token A deeper in the nesting tree94 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);95 expect(await targetToken.getChildren()).to.be.have.deep.members([96 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},97 {tokenId: 0, collectionId: collectionB.collectionId},98 ]).and.has.length(2);99 // Nested token also has children now:100 expect(await tokenA.getChildren()).to.have.deep.members([101 {tokenId: 0, collectionId: collectionB.collectionId},102 ]).and.has.length(1);103104 // Move the remaining part of the fungible token inside token A deeper in the nesting tree105 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);106 expect(await targetToken.getChildren()).to.have.deep.members([107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108 ]).and.has.length(1);109 expect(await tokenA.getChildren()).to.have.deep.members([110 {tokenId: 0, collectionId: collectionB.collectionId},111 ]).and.has.length(1);112 });113114 /// TODO review this test115 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {116 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});117 const targetToken = await collection.mintToken(alice);118119 // Create an immediately nested token120 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());121 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});122 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());123124 // Create a token to be nested125 const newToken = await collection.mintToken(alice);126127 // Nest128 await newToken.nest(alice, targetToken);129 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});130 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());131132 // Move bundle to different user133 await targetToken.transfer(alice, {Substrate: bob.address});134 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});135 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());136 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});137 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());138139 // Unnest140 await newToken.unnest(bob, targetToken, {Substrate: bob.address});141 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});142 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});143 });144});