git.delta.rocks / unique-network / refs/commits / 570880cf1d2e

difftreelog

CORE-180. burnItem

str-mv2021-08-03parent: #b255f4b.patch.diff
in: master

9 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -987,12 +987,12 @@
 		/// * item_id: ID of NFT to burn.
 		#[weight = <SelfWeightOf<T>>::burn_item()]
 		#[transactional]
-		pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {
+		pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, item_owner: T::CrossAccountId, value: u128) -> DispatchResult {
 
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let target_collection = Self::get_collection(collection_id)?;
 
-			Self::burn_item_internal(&sender, &target_collection, item_id, value)?;
+			Self::burn_item_internal(&sender, &target_collection, item_id, &item_owner, value)?;
 
 			target_collection.submit_logs()
 		}
@@ -1596,6 +1596,7 @@
 		sender: &T::CrossAccountId,
 		collection: &CollectionHandle<T>,
 		item_id: TokenId,
+		item_owner: &T::CrossAccountId,
 		value: u128,
 	) -> DispatchResult {
 		ensure!(
@@ -1611,8 +1612,11 @@
 
 		match collection.mode {
 			CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,
-			CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,
-			CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,
+			CollectionMode::Fungible(_) => Self::burn_fungible_item(collection, item_owner, value)?,
+			CollectionMode::ReFungible => {
+				Self::burn_refungible_item(collection, item_id, item_owner)?
+			}
+			_ => (),
 		};
 
 		Ok(())
@@ -1947,8 +1951,8 @@
 	}
 
 	fn burn_fungible_item(
-		owner: &T::CrossAccountId,
 		collection: &CollectionHandle<T>,
+		owner: &T::CrossAccountId,
 		value: u128,
 	) -> DispatchResult {
 		let collection_id = collection.id;
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -707,9 +707,15 @@
 		assert_eq!(TemplateModule::balance_count(1, 1), 1);
 
 		// burn item
-		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
+		assert_ok!(TemplateModule::burn_item(
+			origin1.clone(),
+			1,
+			1,
+			account(1),
+			5
+		));
 		assert_noop!(
-			TemplateModule::burn_item(origin1, 1, 1, 5),
+			TemplateModule::burn_item(origin1, 1, 1, account(1), 5),
 			Error::<Test>::TokenNotFound
 		);
 
@@ -736,9 +742,15 @@
 		assert_eq!(TemplateModule::balance_count(1, 1), 5);
 
 		// burn item
-		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
+		assert_ok!(TemplateModule::burn_item(
+			origin1.clone(),
+			1,
+			1,
+			account(1),
+			5
+		));
 		assert_noop!(
-			TemplateModule::burn_item(origin1, 1, 1, 5),
+			TemplateModule::burn_item(origin1, 1, 1, account(1), 5),
 			Error::<Test>::TokenValueNotEnough
 		);
 
@@ -781,9 +793,15 @@
 		assert_eq!(TemplateModule::balance_count(1, 1), 1023);
 
 		// burn item
-		assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));
+		assert_ok!(TemplateModule::burn_item(
+			origin1.clone(),
+			1,
+			1,
+			account(1),
+			1023
+		));
 		assert_noop!(
-			TemplateModule::burn_item(origin1, 1, 1, 1023),
+			TemplateModule::burn_item(origin1, 1, 1, account(1), 1023),
 			Error::<Test>::TokenNotFound
 		);
 
@@ -1378,7 +1396,7 @@
 			AccessMode::WhiteList
 		));
 		assert_noop!(
-			TemplateModule::burn_item(origin1, 1, 1, 5),
+			TemplateModule::burn_item(origin1.clone(), 1, 1, account(1), 5),
 			Error::<Test>::AddresNotInWhiteList
 		);
 	});
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -38,7 +38,7 @@
     const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
 
     await usingApi(async (api) => {
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 0);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
       // Get the item
@@ -59,7 +59,7 @@
 
     await usingApi(async (api) => {
       // Destroy 1 of 10
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 1);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
   
@@ -79,7 +79,7 @@
     const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
 
     await usingApi(async (api) => {
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 1);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
   
@@ -107,7 +107,7 @@
       const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
 
       // Bob burns his portion
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(bob.address), 0);
       const events2 = await submitTransactionAsync(bob, tx);
       const result2 = getGenericResult(events2);
 
@@ -152,7 +152,7 @@
     await addCollectionAdminExpectSuccess(alice, collectionId, bob);
 
     await usingApi(async (api) => {
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 0);
       const events = await submitTransactionAsync(bob, tx);
       const result = getGenericResult(events);
       // Get the item
@@ -164,6 +164,49 @@
       expect(item).to.be.null;
     });
   });
+
+
+  it('Burn item in Fungible collection', async () => {
+    const createMode = 'Fungible';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+    await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
+    await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+    const tokenId = 0; // ignored
+
+    await usingApi(async (api) => {
+      // Destroy 1 of 10
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 1);
+      const events = await submitTransactionAsync(bob, tx);
+      const result = getGenericResult(events);
+  
+      // Get alice balance 
+      const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+ 
+      // What to expect
+      expect(result.success).to.be.true;
+      expect(balance).to.be.not.null;
+      expect(balance.Value).to.be.equal(9);
+    });
+  });
+  
+  it('Burn item in ReFungible collection', async () => {
+    const createMode = 'ReFungible';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+    await addCollectionAdminExpectSuccess(alice, collectionId, bob);
+
+    await usingApi(async (api) => {
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 1);
+      const events = await submitTransactionAsync(bob, tx);
+      const result = getGenericResult(events);
+      // Get alice balance 
+      const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+      
+      // What to expect
+      expect(result.success).to.be.true;
+      expect(balance).to.be.null;
+    });
+  });
 });
 
 describe('Negative integration test: ext. burnItem():', () => {
@@ -182,7 +225,7 @@
     await destroyCollectionExpectSuccess(collectionId);
 
     await usingApi(async (api) => {
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 0);
       const badTransaction = async function () { 
         await submitTransactionExpectFailAsync(alice, tx);
       };
@@ -197,7 +240,7 @@
     const tokenId = 10;
 
     await usingApi(async (api) => {
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 0);
       const badTransaction = async function () { 
         await submitTransactionExpectFailAsync(alice, tx);
       };
@@ -212,7 +255,7 @@
     const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
 
     await usingApi(async (api) => {
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 0);
       const badTransaction = async function () { 
         await submitTransactionExpectFailAsync(bob, tx);
       };
@@ -228,7 +271,7 @@
 
     await usingApi(async (api) => {
 
-      const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const burntx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 0);
       const events1 = await submitTransactionAsync(alice, burntx);
       const result1 = getGenericResult(events1);
       expect(result1.success).to.be.true;
@@ -251,7 +294,7 @@
 
     await usingApi(async (api) => {
       // Destroy 11 of 10
-      const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(alice.address), 11);
       const badTransaction = async function () { 
         await submitTransactionExpectFailAsync(alice, tx);
       };
modifiedtests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth
--- a/tests/src/check-event/burnItemEvent.test.ts
+++ b/tests/src/check-event/burnItemEvent.test.ts
@@ -10,7 +10,7 @@
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from '../substrate/privateKey';
 import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage, normalizeAccountId } from '../util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -29,7 +29,7 @@
     await usingApi(async (api: ApiPromise) => {
       const collectionID = await createCollectionExpectSuccess();
       const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
-      const burnItem = api.tx.nft.burnItem(collectionID, itemID, 1);
+      const burnItem = api.tx.nft.burnItem(collectionID, itemID, normalizeAccountId(Alice.address), 1);
       const events = await submitTransactionAsync(Alice, burnItem);
       const msg = JSON.stringify(nftEventMessage(events));
       expect(msg).to.be.contain(checkSection);
modifiedtests/src/collision-tests/admVsOwnerTake.test.tsdiffbeforeafterboth
--- a/tests/src/collision-tests/admVsOwnerTake.test.ts
+++ b/tests/src/collision-tests/admVsOwnerTake.test.ts
@@ -34,7 +34,7 @@
       const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
       //
       const sendItem = api.tx.nft.transfer(normalizeAccountId(Ferdie.address), collectionId, itemId, 1);
-      const burnItem = api.tx.nft.burnItem(collectionId, itemId, 1);
+      const burnItem = api.tx.nft.burnItem(collectionId, itemId, normalizeAccountId(Alice.address), 1);
       await Promise.all([
         sendItem.signAndSend(Bob),
         burnItem.signAndSend(Alice),
modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -116,7 +116,7 @@
   it('fails on removed token', async () => {
     const removedTokenCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
     const removedTokenId = await createItemExpectSuccess(alice, removedTokenCollectionId, 'NFT');
-    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId);
+    await burnItemExpectSuccess(alice, removedTokenCollectionId, removedTokenId, alice);
 
     await setVariableMetaDataExpectFailure(alice, removedTokenCollectionId, removedTokenId, data);
   });
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -188,18 +188,18 @@
     // nft
     const nftCollectionId = await createCollectionExpectSuccess();
     const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
-    await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
+    await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, Alice, 1);
     await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
     // fungible
     const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
     const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
-    await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 10);
+    await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, Alice, 10);
     await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
     // reFungible
     const reFungibleCollectionId = await
     createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
     const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
-    await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
+    await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, Alice, 1);
     await transferExpectFailure(
       reFungibleCollectionId,
       newReFungibleTokenId,
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
before · tests/src/transferFrom.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import { ApiPromise } from '@polkadot/api';6import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi } from './substrate/substrate-api';11import {12  approveExpectFail,13  approveExpectSuccess,14  createCollectionExpectSuccess,15  createFungibleItemExpectSuccess,16  createItemExpectSuccess,17  getAllowance,18  transferFromExpectFail,19  transferFromExpectSuccess,20  burnItemExpectSuccess,21  setCollectionLimitsExpectSuccess,22} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {28  let Alice: IKeyringPair;29  let Bob: IKeyringPair;30  let Charlie: IKeyringPair;3132  before(async () => {33    await usingApi(async () => {34      Alice = privateKey('//Alice');35      Bob = privateKey('//Bob');36      Charlie = privateKey('//Charlie');37    });38  });3940  it('Execute the extrinsic and check nftItemList - owner of token', async () => {41    await usingApi(async () => {42      // nft43      const nftCollectionId = await createCollectionExpectSuccess();44      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');45      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);4647      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');4849      // fungible50      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});51      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');52      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);53      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');5455      // reFungible56      const reFungibleCollectionId = await57      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});58      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');59      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);60      await transferFromExpectSuccess(61        reFungibleCollectionId,62        newReFungibleTokenId,63        Bob,64        Alice,65        Charlie,66        100,67        'ReFungible',68      );69    });70  });7172  it('Should reduce allowance if value is big', async () => {73    await usingApi(async () => {74      const alice = privateKey('//Alice');75      const bob = privateKey('//Bob');76      const charlie = privateKey('//Charlie');7778      // fungible79      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});80      const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });8182      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);83      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');84      expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');85    });86  });8788  it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {89    const collectionId = await createCollectionExpectSuccess();90    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);9192    await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);93  });94});9596describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {97  let Alice: IKeyringPair;98  let Bob: IKeyringPair;99  let Charlie: IKeyringPair;100101  before(async () => {102    await usingApi(async () => {103      Alice = privateKey('//Alice');104      Bob = privateKey('//Bob');105      Charlie = privateKey('//Charlie');106    });107  });108109  it('transferFrom for a collection that does not exist', async () => {110    await usingApi(async (api: ApiPromise) => {111      // nft112      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;113      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);114115      await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);116117      // fungible118      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;119      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);120121      await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);122      // reFungible123      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;124      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);125126      await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);127    });128  });129130  /* it('transferFrom for a collection that was destroyed', async () => {131    await usingApi(async (api: ApiPromise) => {132      this test copies approve negative test133    });134  }); */135136  /* it('transferFrom a token that does not exist', async () => {137    await usingApi(async (api: ApiPromise) => {138      this test copies approve negative test139    });140  }); */141142  /* it('transferFrom a token that was deleted', async () => {143    await usingApi(async (api: ApiPromise) => {144      this test copies approve negative test145    });146  }); */147148  it('transferFrom for not approved address', async () => {149    await usingApi(async () => {150      // nft151      const nftCollectionId = await createCollectionExpectSuccess();152      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');153154      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);155156      // fungible157      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});158      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');159      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);160      // reFungible161      const reFungibleCollectionId = await162      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});163      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');164      await transferFromExpectFail(165        reFungibleCollectionId,166        newReFungibleTokenId,167        Bob,168        Alice,169        Charlie,170        1,171      );172    });173  });174175  it('transferFrom incorrect token count', async () => {176    await usingApi(async () => {177      // nft178      const nftCollectionId = await createCollectionExpectSuccess();179      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');180      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);181182      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);183184      // fungible185      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});186      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');187      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);188      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);189      // reFungible190      const reFungibleCollectionId = await191      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});192      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');193      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);194      await transferFromExpectFail(195        reFungibleCollectionId,196        newReFungibleTokenId,197        Bob,198        Alice,199        Charlie,200        2,201      );202    });203  });204205  it('execute transferFrom from account that is not owner of collection', async () => {206    await usingApi(async () => {207      const Dave = privateKey('//Dave');208      // nft209      const nftCollectionId = await createCollectionExpectSuccess();210      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');211      try {212        await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);213        await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);214      } catch (e) {215        // tslint:disable-next-line:no-unused-expression216        expect(e).to.be.exist;217      }218219      // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);220221      // fungible222      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});223      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');224      try {225        await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);226        await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);227      } catch (e) {228        // tslint:disable-next-line:no-unused-expression229        expect(e).to.be.exist;230      }231      // reFungible232      const reFungibleCollectionId = await233      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});234      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');235      try {236        await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);237        await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);238      } catch (e) {239        // tslint:disable-next-line:no-unused-expression240        expect(e).to.be.exist;241      }242    });243  });244  it( 'transferFrom burnt token before approve NFT', async () => {245    await usingApi(async () => {246      // nft247      const nftCollectionId = await createCollectionExpectSuccess();248      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');249      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);250      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);251      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      252    });253  });254  it( 'transferFrom burnt token before approve Fungible', async () => {255    await usingApi(async () => {256      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});257      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');258      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);259      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);260      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);261          262    });263  }); 264  it( 'transferFrom burnt token before approve ReFungible', async () => {265    await usingApi(async () => {266      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});267      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');268      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);269      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);270      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);271          272    });273  });274  275  it( 'transferFrom burnt token after approve NFT', async () => {276    await usingApi(async () => {277      // nft278      const nftCollectionId = await createCollectionExpectSuccess();279      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');280      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);281      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);282      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      283    });284  });285  it( 'transferFrom burnt token after approve Fungible', async () => {286    await usingApi(async () => {287      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});288      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');289      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);290      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);291      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);292          293    });294  }); 295  it( 'transferFrom burnt token after approve ReFungible', async () => {296    await usingApi(async () => {297      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});298      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');299      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);300      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);301      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);302          303    });304  });305306  it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {307    const collectionId = await createCollectionExpectSuccess();308    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);309    await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });310311    await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);312  });313});
after · tests/src/transferFrom.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import { ApiPromise } from '@polkadot/api';6import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi } from './substrate/substrate-api';11import {12  approveExpectFail,13  approveExpectSuccess,14  createCollectionExpectSuccess,15  createFungibleItemExpectSuccess,16  createItemExpectSuccess,17  getAllowance,18  transferFromExpectFail,19  transferFromExpectSuccess,20  burnItemExpectSuccess,21  setCollectionLimitsExpectSuccess,22} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {28  let Alice: IKeyringPair;29  let Bob: IKeyringPair;30  let Charlie: IKeyringPair;3132  before(async () => {33    await usingApi(async () => {34      Alice = privateKey('//Alice');35      Bob = privateKey('//Bob');36      Charlie = privateKey('//Charlie');37    });38  });3940  it('Execute the extrinsic and check nftItemList - owner of token', async () => {41    await usingApi(async () => {42      // nft43      const nftCollectionId = await createCollectionExpectSuccess();44      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');45      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);4647      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');4849      // fungible50      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});51      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');52      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);53      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');5455      // reFungible56      const reFungibleCollectionId = await57      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});58      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');59      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);60      await transferFromExpectSuccess(61        reFungibleCollectionId,62        newReFungibleTokenId,63        Bob,64        Alice,65        Charlie,66        100,67        'ReFungible',68      );69    });70  });7172  it('Should reduce allowance if value is big', async () => {73    await usingApi(async () => {74      const alice = privateKey('//Alice');75      const bob = privateKey('//Bob');76      const charlie = privateKey('//Charlie');7778      // fungible79      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});80      const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });8182      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);83      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');84      expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');85    });86  });8788  it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {89    const collectionId = await createCollectionExpectSuccess();90    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);9192    await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);93  });94});9596describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {97  let Alice: IKeyringPair;98  let Bob: IKeyringPair;99  let Charlie: IKeyringPair;100101  before(async () => {102    await usingApi(async () => {103      Alice = privateKey('//Alice');104      Bob = privateKey('//Bob');105      Charlie = privateKey('//Charlie');106    });107  });108109  it('transferFrom for a collection that does not exist', async () => {110    await usingApi(async (api: ApiPromise) => {111      // nft112      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;113      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);114115      await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);116117      // fungible118      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;119      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);120121      await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);122      // reFungible123      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;124      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);125126      await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);127    });128  });129130  /* it('transferFrom for a collection that was destroyed', async () => {131    await usingApi(async (api: ApiPromise) => {132      this test copies approve negative test133    });134  }); */135136  /* it('transferFrom a token that does not exist', async () => {137    await usingApi(async (api: ApiPromise) => {138      this test copies approve negative test139    });140  }); */141142  /* it('transferFrom a token that was deleted', async () => {143    await usingApi(async (api: ApiPromise) => {144      this test copies approve negative test145    });146  }); */147148  it('transferFrom for not approved address', async () => {149    await usingApi(async () => {150      // nft151      const nftCollectionId = await createCollectionExpectSuccess();152      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');153154      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);155156      // fungible157      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});158      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');159      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);160      // reFungible161      const reFungibleCollectionId = await162      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});163      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');164      await transferFromExpectFail(165        reFungibleCollectionId,166        newReFungibleTokenId,167        Bob,168        Alice,169        Charlie,170        1,171      );172    });173  });174175  it('transferFrom incorrect token count', async () => {176    await usingApi(async () => {177      // nft178      const nftCollectionId = await createCollectionExpectSuccess();179      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');180      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);181182      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);183184      // fungible185      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});186      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');187      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);188      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);189      // reFungible190      const reFungibleCollectionId = await191      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});192      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');193      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);194      await transferFromExpectFail(195        reFungibleCollectionId,196        newReFungibleTokenId,197        Bob,198        Alice,199        Charlie,200        2,201      );202    });203  });204205  it('execute transferFrom from account that is not owner of collection', async () => {206    await usingApi(async () => {207      const Dave = privateKey('//Dave');208      // nft209      const nftCollectionId = await createCollectionExpectSuccess();210      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');211      try {212        await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);213        await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);214      } catch (e) {215        // tslint:disable-next-line:no-unused-expression216        expect(e).to.be.exist;217      }218219      // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);220221      // fungible222      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});223      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');224      try {225        await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);226        await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);227      } catch (e) {228        // tslint:disable-next-line:no-unused-expression229        expect(e).to.be.exist;230      }231      // reFungible232      const reFungibleCollectionId = await233      createCollectionExpectSuccess({mode: {type: 'ReFungible'}});234      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');235      try {236        await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);237        await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);238      } catch (e) {239        // tslint:disable-next-line:no-unused-expression240        expect(e).to.be.exist;241      }242    });243  });244  it( 'transferFrom burnt token before approve NFT', async () => {245    await usingApi(async () => {246      // nft247      const nftCollectionId = await createCollectionExpectSuccess();248      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');249      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, Alice, 1);250      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);251      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      252    });253  });254  it( 'transferFrom burnt token before approve Fungible', async () => {255    await usingApi(async () => {256      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});257      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');258      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, Alice, 10);259      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);260      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);261          262    });263  }); 264  it( 'transferFrom burnt token before approve ReFungible', async () => {265    await usingApi(async () => {266      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});267      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');268      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, Alice, 1);269      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);270      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);271          272    });273  });274  275  it( 'transferFrom burnt token after approve NFT', async () => {276    await usingApi(async () => {277      // nft278      const nftCollectionId = await createCollectionExpectSuccess();279      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');280      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);281      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, Alice, 1);282      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      283    });284  });285  it( 'transferFrom burnt token after approve Fungible', async () => {286    await usingApi(async () => {287      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});288      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');289      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);290      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, Alice, 10);291      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);292          293    });294  }); 295  it( 'transferFrom burnt token after approve ReFungible', async () => {296    await usingApi(async () => {297      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});298      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');299      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);300      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, Alice, 1);301      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);302          303    });304  });305306  it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {307    const collectionId = await createCollectionExpectSuccess();308    const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);309    await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });310311    await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);312  });313});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -700,10 +700,10 @@
   ReFungible: CreateReFungibleData;
 };
 
-export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {
+export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, owner: IKeyringPair, value = 0) {
   await usingApi(async (api) => {
-    const tx = api.tx.nft.burnItem(collectionId, tokenId, value);
-    const events = await submitTransactionAsync(owner, tx);
+    const tx = api.tx.nft.burnItem(collectionId, tokenId, normalizeAccountId(owner.address), value);
+    const events = await submitTransactionAsync(sender, tx);
     const result = getGenericResult(events);
     // Get the item
     const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();