git.delta.rocks / unique-network / refs/commits / 2c6fa32b7608

difftreelog

fix remove native ft from childrens

Trubnikov Sergey2023-05-23parent: #95338e2.patch.diff
in: master

4 files changed

modifiedpallets/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(
modifiedpallets/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.
modifiedtests/src/sub/nesting/common.test.tsdiffbeforeafterboth
109 // Bob can nest Native FT into their NFT:109 // Bob can nest Native FT into their NFT:
110 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);110 await collectionForNesting.transfer(bob, targetTokenBob.nestingAccount(), 50n);
111 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);111 expect(await collectionForNesting.getBalance(targetTokenBob.nestingAccount())).eq(50n);
112 // Native FT should't be visible in NFT children:
112 expect(await targetTokenBob.getChildren()).to.be.deep.equal([{collectionId: 0, tokenId: 0}]);113 expect(await targetTokenBob.getChildren()).to.be.deep.equal([]);
113 });114 });
114 });115 });
115116
134 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);135 expect(await ftCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);
135 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);136 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(100n);
136137
137 expect(await tokenA.getChildren()).to.be.length(4);138 expect(await tokenA.getChildren()).to.be.length(3);
138 expect(await tokenB.getChildren()).to.be.length(0);139 expect(await tokenB.getChildren()).to.be.length(0);
139140
140 // Transfer the nested token to another token141 // Transfer the nested token to another token
155 expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);156 expect(await nativeFtCollectionToBeNested.getBalance(tokenB.nestingAccount())).to.equal(25n);
156 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);157 expect(await nativeFtCollectionToBeNested.getBalance(tokenA.nestingAccount())).to.equal(75n);
157158
158 // RFT, FT, and native FT159 // RFT, FT, and without native FT
159 expect(await tokenA.getChildren()).to.be.length(3);160 expect(await tokenA.getChildren()).to.be.length(2);
160 // NFT, RFT, FT, and native FT161 // NFT, RFT, FT, and without native FT
161 expect(await tokenB.getChildren()).to.be.length(4);162 expect(await tokenB.getChildren()).to.be.length(3);
162 });163 });
163});164});
164165
modifiedtests/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);