git.delta.rocks / unique-network / refs/commits / 004643cad6df

difftreelog

fix unnest NFT from parent

Daniel Shiposha2022-06-03parent: #4d135e3.patch.diff
in: master

3 files changed

modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -604,7 +604,7 @@
 
 		// =========
 
-		<PalletStructure<T>>::unnest_if_nested(from, collection.id, token);
+		<PalletStructure<T>>::unnest_if_nested(&token_data.owner, collection.id, token);
 
 		<TokenData<T>>::insert(
 			(collection.id, token),
modifiedpallets/structure/src/lib.rsdiffbeforeafterboth
191 token_id: TokenId,191 token_id: TokenId,
192 nesting_budget: &dyn Budget,192 nesting_budget: &dyn Budget,
193 ) -> DispatchResult {193 ) -> DispatchResult {
194 Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {194 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {
195 d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)195 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)
196 })196 })
197 }197 }
198198
203 token_id: TokenId,203 token_id: TokenId,
204 nesting_budget: &dyn Budget,204 nesting_budget: &dyn Budget,
205 ) -> DispatchResult {205 ) -> DispatchResult {
206 Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {206 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {
207 d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;207 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;
208208
209 d.nest(parent_id, (collection_id, token_id));209 collection.nest(parent_id, (collection_id, token_id));
210210
211 Ok(())211 Ok(())
212 })212 })
217 collection_id: CollectionId,217 collection_id: CollectionId,
218 token_id: TokenId,218 token_id: TokenId,
219 ) {219 ) {
220 Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {220 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {
221 d.nest(parent_id, (collection_id, token_id))221 collection.nest(parent_id, (collection_id, token_id))
222 });222 });
223 }223 }
224224
227 collection_id: CollectionId,227 collection_id: CollectionId,
228 token_id: TokenId,228 token_id: TokenId,
229 ) {229 ) {
230 Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {230 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {
231 d.unnest(parent_id, (collection_id, token_id))231 collection.unnest(parent_id, (collection_id, token_id))
232 });232 });
233 }233 }
234234
235 fn exec_if_owner_is_valid_nft(235 fn exec_if_owner_is_valid_nft(
236 account: &T::CrossAccountId,236 account: &T::CrossAccountId,
237 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),237 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),
238 ) {238 ) {
239 Self::try_exec_if_owner_is_valid_nft(account, |d, id| {239 Self::try_exec_if_owner_is_valid_nft(account, |collection, id| {
240 action(d, id);240 action(collection, id);
241 Ok(())241 Ok(())
242 })242 })
243 .unwrap();243 .unwrap();
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -78,8 +78,8 @@
         api,
         alice,
         api.tx.unique.transferFrom(
-          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), 
-          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), 
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}),
+          normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}),
           collection,
           tokenC,
           1,
@@ -120,13 +120,13 @@
       ], 'Children contents check at nesting #2');
 
       // Move token B to a different user outside the nesting tree
-      await transferFromExpectSuccess(collectionA, tokenB, alice, targetAddress, bob);
+      await transferExpectSuccess(collectionA, tokenB, alice, bob);
       children = await getTokenChildren(api, collectionA, targetToken);
       expect(children.length).to.be.equal(1, 'Children length check at unnesting');
       expect(children).to.be.have.deep.members([
         {token: tokenA, collection: collectionA},
       ], 'Children contents check at unnesting');
-      
+
       // Create a fungible token in another collection and then nest
       const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');
       await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');
@@ -287,20 +287,6 @@
     await usingApi(async () => {
       alice = privateKey('//Alice');
       bob = privateKey('//Bob');
-    });
-  });
-
-  // TODO delete if this is actually wrong
-  // TODO remake all other nesting tests if this is right
-  it('Affirms that transfer is disallowed to transfer nested tokens', async () => {
-    await usingApi(async () => {
-      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
-
-      const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');
-      const tokenB = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});
-      
-      await transferExpectFailure(collection, tokenB, alice, bob);
     });
   });