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
85 }85 }
86}86}
8787
88/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete88/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallet
89/// 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(
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
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
80 {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);
8584
86 // Burn all nested pieces85 // Burn all nested pieces
87 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);
9492
95 // 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 tree
96 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);