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
1347 }1347 }
13481348
1349 fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {1349 fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {
1350 let address = T::CrossTokenAddressMapping::token_to_address(collection_id, token_id);
1351 let balance = <pallet_balances::Pallet<T>>::free_balance(address.as_sub());
1352
1353 balance > T::Balance::default()
1354 || <TokenChildren<T>>::iter_prefix((collection_id, token_id))1350 <TokenChildren<T>>::iter_prefix((collection_id, token_id))
1355 .next()1351 .next()
1356 .is_some()1352 .is_some()
1357 }1353 }
13581354
1359 pub fn token_children_ids(collection_id: CollectionId, token_id: TokenId) -> Vec<TokenChild> {1355 pub fn token_children_ids(collection_id: CollectionId, token_id: TokenId) -> Vec<TokenChild> {
1360 let mut tokens: Vec<_> = vec![];
1361
1362 let address = T::CrossTokenAddressMapping::token_to_address(collection_id, token_id);
1363 let balance = <pallet_balances::Pallet<T>>::free_balance(address.as_sub());
1364 if balance > T::Balance::default() {
1365 tokens.push(TokenChild {
1366 token: TokenId(0),
1367 collection: pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID,
1368 })
1369 }
1370
1371 tokens.extend(
1372 <TokenChildren<T>>::iter_prefix((collection_id, token_id)).map(1356 <TokenChildren<T>>::iter_prefix((collection_id, token_id))
1373 |((child_collection_id, child_id), _)| TokenChild {1357 .map(|((child_collection_id, child_id), _)| TokenChild {
1374 collection: child_collection_id,1358 collection: child_collection_id,
1375 token: child_id,1359 token: child_id,
1376 },1360 })
1377 ),1361 .collect()
1378 );
1379
1380 tokens
1381 }1362 }
13821363
1383 /// Mint single NFT token.1364 /// Mint single NFT token.
modifiedtests/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);
   });
 });
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);