git.delta.rocks / unique-network / refs/commits / 80dcadd1d3b4

difftreelog

Merge pull request #567 from UniqueNetwork/test/playground-migration

ut-akuznetsov2022-09-12parents: #e4516e4 #5401624.patch.diff
in: master
Test/playground migration

5 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -49,6 +49,7 @@
     "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
     "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
     "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",
+    "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
     "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
     "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",
modifiedtests/src/adminTransferAndBurn.test.tsdiffbeforeafterboth
--- a/tests/src/adminTransferAndBurn.test.ts
+++ b/tests/src/adminTransferAndBurn.test.ts
@@ -17,56 +17,63 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi} from './substrate/substrate-api';
-import {
-  createCollectionExpectSuccess,
-  createItemExpectSuccess,
-  transferExpectFailure,
-  transferFromExpectSuccess,
-  burnItemExpectFailure,
-  burnFromExpectSuccess,
-  setCollectionLimitsExpectSuccess,
-} from './util/helpers';
+import {usingPlaygrounds} from './util/playgrounds';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
+let donor: IKeyringPair;
+
+before(async () => {
+  await usingPlaygrounds(async (_, privateKey) => {
+    donor = privateKey('//Alice');
+  });
+});
+
 describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {
   let alice: IKeyringPair;
   let bob: IKeyringPair;
   let charlie: IKeyringPair;
 
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
-      charlie = privateKeyWrapper('//Charlie');
+    await usingPlaygrounds(async (helper) => {
+      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
     });
   });
 
   it('admin transfers other user\'s token', async () => {
-    await usingApi(async () => {
-      const collectionId = await createCollectionExpectSuccess();
-      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
-
-      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
+      await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+      const limits = await helper.collection.getEffectiveLimits(collectionId);
+      expect(limits.ownerCanTransfer).to.be.true;
 
-      await transferExpectFailure(collectionId, tokenId, alice, charlie);
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+      const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await expect(transferResult()).to.be.rejected;
 
-      await transferFromExpectSuccess(collectionId, tokenId, alice, bob, charlie, 1);
+      await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});
+      const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(newTokenOwner.Substrate).to.be.equal(charlie.address);
     });
   });
 
   it('admin burns other user\'s token', async () => {
-    await usingApi(async () => {
-      const collectionId = await createCollectionExpectSuccess();
-      await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
+
+      await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
+      const limits = await helper.collection.getEffectiveLimits(collectionId);
+      expect(limits.ownerCanTransfer).to.be.true;
 
-      const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Substrate: bob.address});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
+      const burnTxFailed = async () => helper.nft.burnToken(alice, collectionId, tokenId);
 
-      await burnItemExpectFailure(alice, collectionId, tokenId);
+      await expect(burnTxFailed()).to.be.rejected;
 
-      await burnFromExpectSuccess(alice, bob, collectionId, tokenId);
+      await helper.nft.burnToken(bob, collectionId, tokenId);
+      const token = await helper.nft.getToken(collectionId, tokenId);
+      expect(token).to.be.null;
     });
   });
 });
modifiedtests/src/allowLists.test.tsdiffbeforeafterboth
--- a/tests/src/allowLists.test.ts
+++ b/tests/src/allowLists.test.ts
@@ -17,31 +17,19 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {
-  addToAllowListExpectSuccess,
-  createCollectionExpectSuccess,
-  createItemExpectSuccess,
-  destroyCollectionExpectSuccess,
-  enableAllowListExpectSuccess,
-  normalizeAccountId,
-  addCollectionAdminExpectSuccess,
-  addToAllowListExpectFail,
-  removeFromAllowListExpectSuccess,
-  removeFromAllowListExpectFailure,
-  addToAllowListAgainExpectSuccess,
-  transferExpectFailure,
-  approveExpectSuccess,
-  approveExpectFail,
-  transferExpectSuccess,
-  transferFromExpectSuccess,
-  setMintPermissionExpectSuccess,
-  createItemExpectFailure,
-} from './util/helpers';
+import {usingPlaygrounds} from './util/playgrounds';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
+let donor: IKeyringPair;
+
+before(async () => {
+  await usingPlaygrounds(async (_, privateKey) => {
+    donor = privateKey('//Alice');
+  });
+});
+
 let alice: IKeyringPair;
 let bob: IKeyringPair;
 let charlie: IKeyringPair;
@@ -49,266 +37,348 @@
 describe('Integration Test ext. Allow list tests', () => {
 
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
-      charlie = privateKeyWrapper('//Charlie');
+    await usingPlaygrounds(async (helper) => {
+      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
     });
   });
 
   it('Owner can add address to allow list', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectSuccess(alice, collectionId, bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      const allowList = await helper.nft.getAllowList(collectionId);
+      expect(allowList).to.be.deep.contains({Substrate: bob.address});
+    });
   });
 
   it('Admin can add address to allow list', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
+
+      await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
+      const allowList = await helper.nft.getAllowList(collectionId);
+      expect(allowList).to.be.deep.contains({Substrate: charlie.address});
+    });
   });
 
   it('Non-privileged user cannot add address to allow list', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectFail(bob, collectionId, charlie.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
+      await expect(addToAllowListTx()).to.be.rejected;
+    });
   });
 
   it('Nobody can add address to allow list of non-existing collection', async () => {
     const collectionId = (1<<32) - 1;
-    await addToAllowListExpectFail(alice, collectionId, bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
+      await expect(addToAllowListTx()).to.be.rejected;
+    });
   });
 
   it('Nobody can add address to allow list of destroyed collection', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await destroyCollectionExpectSuccess(collectionId, '//Alice');
-    await addToAllowListExpectFail(alice, collectionId, bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.collection.burn(alice, collectionId);
+      const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      await expect(addToAllowListTx()).to.be.rejected;
+    });
   });
 
   it('If address is already added to allow list, nothing happens', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectSuccess(alice, collectionId, bob.address);
-    await addToAllowListAgainExpectSuccess(alice, collectionId, bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      const allowList = await helper.nft.getAllowList(collectionId);
+      expect(allowList).to.be.deep.contains({Substrate: bob.address});
+    });
   });
 
   it('Owner can remove address from allow list', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectSuccess(alice, collectionId, bob.address);
-    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+
+      await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
+
+      const allowList = await helper.nft.getAllowList(collectionId);
+
+      expect(allowList).to.be.not.deep.contains({Substrate: bob.address});
+    });
   });
 
   it('Admin can remove address from allow list', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});
+
+      const allowList = await helper.nft.getAllowList(collectionId);
+
+      expect(allowList).to.be.not.deep.contains({Substrate: bob.address});
+    });
   });
 
   it('Non-privileged user cannot remove address from allow list', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+      const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
+      await expect(removeTx()).to.be.rejected;
+      const allowList = await helper.nft.getAllowList(collectionId);
+
+      expect(allowList).to.be.deep.contains({Substrate: charlie.address});
+    });
   });
 
   it('Nobody can remove address from allow list of non-existing collection', async () => {
     const collectionId = (1<<32) - 1;
-    await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
+    await usingPlaygrounds(async (helper) => {
+      const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
+      await expect(removeTx()).to.be.rejected;
+    });
   });
 
   it('Nobody can remove address from allow list of deleted collection', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await destroyCollectionExpectSuccess(collectionId, '//Alice');
-    await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      await helper.collection.burn(alice, collectionId);
+      const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
+
+      await expect(removeTx()).to.be.rejected;
+    });
   });
 
   it('If address is already removed from allow list, nothing happens', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
-    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
+      const allowListBefore = await helper.nft.getAllowList(collectionId);
+      expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});
+
+      await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
+
+      const allowListAfter = await helper.nft.getAllowList(collectionId);
+      expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
 
-    await transferExpectFailure(
-      collectionId,
-      itemId,
-      alice,
-      charlie,
-      1,
-    );
+      const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await expect(transferResult()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
-    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+      await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
 
-    await transferExpectFailure(
-      collectionId,
-      itemId,
-      alice,
-      charlie,
-      1,
-    );
+      const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await expect(transferResult()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
 
-    await transferExpectFailure(
-      collectionId,
-      itemId,
-      alice,
-      charlie,
-      1,
-    );
+      const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await expect(transferResult()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
-    await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+
+      await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
 
-    await transferExpectFailure(
-      collectionId,
-      itemId,
-      alice,
-      charlie,
-      1,
-    );
+      const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      await expect(transferResult()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);
-      const badTransaction = async function () {
-        await submitTransactionExpectFailAsync(alice, tx);
-      };
-      await expect(badTransaction()).to.be.rejected;
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);
+      await expect(burnTx()).to.be.rejected;
     });
   });
 
   it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await approveExpectFail(collectionId, itemId, alice, bob);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
+      await expect(approveTx()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+      await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(charlie.address);
+    });
   });
 
-  it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
-    await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
+  it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+      await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+
+      await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(charlie.address);
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+
+      await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(charlie.address);
+    });
   });
 
   it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await addToAllowListExpectSuccess(alice, collectionId, alice.address);
-    await addToAllowListExpectSuccess(alice, collectionId, charlie.address);
-    await approveExpectSuccess(collectionId, itemId, alice, charlie.address);
-    await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
+      await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
+
+      await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(charlie.address);
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, false);
-    await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      const token = await helper.nft.getToken(collectionId, tokenId);
+      expect(token).to.be.not.null;
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, false);
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
+      await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
+      const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
+      const token = await helper.nft.getToken(collectionId, tokenId);
+      expect(token).to.be.not.null;
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow-listed address', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, false);
-    await addToAllowListExpectSuccess(alice, collectionId, bob.address);
-    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
+      await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
+      await expect(mintTokenTx()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, false);
-    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
+      const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
+      await expect(mintTokenTx()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, true);
-    await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
+      const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(alice.address);
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, true);
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
+      await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
+      const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(bob.address);
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, true);
-    await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
+      const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
+      await expect(mintTokenTx()).to.be.rejected;
+    });
   });
 
   it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address', async () => {
-    const collectionId = await createCollectionExpectSuccess();
-    await enableAllowListExpectSuccess(alice, collectionId);
-    await setMintPermissionExpectSuccess(alice, collectionId, true);
-    await addToAllowListExpectSuccess(alice, collectionId, bob.address);
-    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);
+    await usingPlaygrounds(async (helper) => {
+      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+      await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
+      await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
+      const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
+      const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+      expect(owner.Substrate).to.be.equal(bob.address);
+    });
   });
 });
modifiedtests/src/approve.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {ApiPromise} from '@polkadot/api';
19import chai from 'chai';18import chai from 'chai';
20import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
21import {default as usingApi} from './substrate/substrate-api';
22import {20import {
23 approveExpectFail,21 approveExpectFail,
24 approveExpectSuccess,22 approveExpectSuccess,
25 createCollectionExpectSuccess,23 createCollectionExpectSuccess,
26 createItemExpectSuccess,24 createItemExpectSuccess,
27 destroyCollectionExpectSuccess,
28 setCollectionLimitsExpectSuccess,
29 transferExpectSuccess,
30 addCollectionAdminExpectSuccess,
31 adminApproveFromExpectFail,
32 getCreatedCollectionCount,
33 transferFromExpectSuccess,
34 transferFromExpectFail,
35 requirePallets,
36 Pallets,
37} from './util/helpers';25} from './util/helpers';
26import {usingPlaygrounds} from './util/playgrounds';
3827
28let donor: IKeyringPair;
29
30before(async () => {
31 await usingPlaygrounds(async (_, privateKey) => {
32 donor = privateKey('//Alice');
33 });
34});
35
39chai.use(chaiAsPromised);36chai.use(chaiAsPromised);
37const expect = chai.expect;
4038
41describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {39describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
42 let alice: IKeyringPair;40 let alice: IKeyringPair;
43 let bob: IKeyringPair;41 let bob: IKeyringPair;
44 let charlie: IKeyringPair;42 let charlie: IKeyringPair;
4543
46 before(async () => {44 before(async () => {
47 await usingApi(async (api, privateKeyWrapper) => {45 await usingPlaygrounds(async (helper) => {
48 alice = privateKeyWrapper('//Alice');46 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
49 bob = privateKeyWrapper('//Bob');
50 charlie = privateKeyWrapper('//Charlie');
51 });47 });
52 });48 });
5349
54 it('[nft] Execute the extrinsic and check approvedList', async () => {50 it('[nft] Execute the extrinsic and check approvedList', async () => {
55 const nftCollectionId = await createCollectionExpectSuccess();51 await usingPlaygrounds(async (helper) => {
52 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
56 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');53 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
57 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);54 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
55 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
56 });
58 });57 });
5958
60 it('[fungible] Execute the extrinsic and check approvedList', async () => {59 it('[fungible] Execute the extrinsic and check approvedList', async () => {
61 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});60 await usingPlaygrounds(async (helper) => {
61 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
62 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');62 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
63 const tokenId = await helper.ft.getLastTokenId(collectionId);
64 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
63 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);65 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
66 expect(amount).to.be.equal(BigInt(1));
67 });
64 });68 });
6569
66 it('[refungible] Execute the extrinsic and check approvedList', async function() {70 it('[refungible] Execute the extrinsic and check approvedList', async function() {
67 await requirePallets(this, [Pallets.ReFungible]);71 await usingPlaygrounds(async (helper) => {
68
69 const reFungibleCollectionId =72 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
70 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
71 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');73 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
72 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);74 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
75 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
76 expect(amount).to.be.equal(BigInt(1));
77 });
73 });78 });
7479
75 it('[nft] Remove approval by using 0 amount', async () => {80 it('[nft] Remove approval by using 0 amount', async () => {
76 const nftCollectionId = await createCollectionExpectSuccess();81 await usingPlaygrounds(async (helper) => {
82 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
77 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');83 const collectionId = collection.collectionId;
84 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
78 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);85 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
79 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);86 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
87 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));
88 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
89 });
80 });90 });
8191
82 it('[fungible] Remove approval by using 0 amount', async () => {92 it('[fungible] Remove approval by using 0 amount', async () => {
83 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});93 await usingPlaygrounds(async (helper) => {
94 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
84 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');95 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
96 const tokenId = await helper.ft.getLastTokenId(collectionId);
97 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
85 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);98 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
99 expect(amountBefore).to.be.equal(BigInt(1));
100
86 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);101 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
102 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
103 expect(amountAfter).to.be.equal(BigInt(0));
104 });
87 });105 });
88106
89 it('[refungible] Remove approval by using 0 amount', async function() {107 it('[refungible] Remove approval by using 0 amount', async function() {
90 await requirePallets(this, [Pallets.ReFungible]);108 await usingPlaygrounds(async (helper) => {
109 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
110 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
111 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
112 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
113 expect(amountBefore).to.be.equal(BigInt(1));
91114
92 const reFungibleCollectionId =115 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
93 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
94 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');116 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
95 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
96 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);117 expect(amountAfter).to.be.equal(BigInt(0));
118 });
97 });119 });
98120
99 it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {121 it('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
100 const collectionId = await createCollectionExpectSuccess();122 await usingPlaygrounds(async (helper) => {
123 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
101 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);124 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
102
103 await adminApproveFromExpectFail(collectionId, itemId, alice, bob.address, charlie.address);125 const approveTokenTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
126 await expect(approveTokenTx()).to.be.rejected;
127 });
104 });128 });
105});129});
106130
110 let charlie: IKeyringPair;134 let charlie: IKeyringPair;
111135
112 before(async () => {136 before(async () => {
113 await usingApi(async (api, privateKeyWrapper) => {137 await usingPlaygrounds(async (helper) => {
114 alice = privateKeyWrapper('//Alice');138 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
115 bob = privateKeyWrapper('//Bob');
116 charlie = privateKeyWrapper('//Charlie');
117 });139 });
118 }); 140 });
119141
120 it('NFT', async () => {142 it('NFT', async () => {
121 const collectionId = await createCollectionExpectSuccess();143 await usingPlaygrounds(async (helper) => {
144 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
122 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);145 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
123 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);146 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
147 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;
148 });
124 });149 });
125150
126 it('Fungible up to an approved amount', async () => {151 it('Fungible up to an approved amount', async () => {
127 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});152 await usingPlaygrounds(async (helper) => {
153 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
128 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 154 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);
155 const tokenId = await helper.ft.getLastTokenId(collectionId);
156 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
129 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);157 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});
158 expect(amount).to.be.equal(BigInt(1));
159 });
130 });160 });
131161
132 it('ReFungible up to an approved amount', async function() {162 it('ReFungible up to an approved amount', async function() {
133 await requirePallets(this, [Pallets.ReFungible]);163 await usingPlaygrounds(async (helper) => {
134
135 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});164 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
136 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);165 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
137 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);166 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
167 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});
168 expect(amount).to.be.equal(BigInt(100n));
169 });
138 });170 });
139});171});
140172
144 let charlie: IKeyringPair;176 let charlie: IKeyringPair;
145177
146 before(async () => {178 before(async () => {
147 await usingApi(async (api, privateKeyWrapper) => {179 await usingPlaygrounds(async (helper) => {
148 alice = privateKeyWrapper('//Alice');180 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
149 bob = privateKeyWrapper('//Bob');
150 charlie = privateKeyWrapper('//Charlie');
151 });181 });
152 }); 182 });
153183
154 it('NFT', async () => {184 it('NFT', async () => {
155 const collectionId = await createCollectionExpectSuccess();185 await usingPlaygrounds(async (helper) => {
186 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
156 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);187 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
157 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);188 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
158 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');189 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
190 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
191 expect(owner.Substrate).to.be.equal(alice.address);
192 });
159 });193 });
160194
161 it('Fungible up to an approved amount', async () => {195 it('Fungible up to an approved amount', async () => {
162 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});196 await usingPlaygrounds(async (helper) => {
197 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
163 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 198 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);
199 const tokenId = await helper.ft.getLastTokenId(collectionId);
164 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);200 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
165 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');201 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
202 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
203 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
204 expect(after - before).to.be.equal(BigInt(1));
205 });
166 });206 });
167207
168 it('ReFungible up to an approved amount', async function() {208 it('ReFungible up to an approved amount', async function() {
169 await requirePallets(this, [Pallets.ReFungible]);209 await usingPlaygrounds(async (helper) => {
170
171 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});210 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
172 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);211 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
173 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);212 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
174 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');213 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
214 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
215 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
216 expect(after - before).to.be.equal(BigInt(1));
217 });
175 });218 });
176});219});
177220
181 let charlie: IKeyringPair;224 let charlie: IKeyringPair;
182225
183 before(async () => {226 before(async () => {
184 await usingApi(async (api, privateKeyWrapper) => {227 await usingPlaygrounds(async (helper) => {
185 alice = privateKeyWrapper('//Alice');228 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
186 bob = privateKeyWrapper('//Bob');
187 charlie = privateKeyWrapper('//Charlie');
188 });229 });
189 }); 230 });
190231
191 it('NFT', async () => {232 it('NFT', async () => {
192 const collectionId = await createCollectionExpectSuccess();233 await usingPlaygrounds(async (helper) => {
234 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
193 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);235 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
194 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);236 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
195 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');237 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
238 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
196 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);239 expect(owner.Substrate).to.be.equal(alice.address);
240 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
241 await expect(transferTokenFromTx()).to.be.rejected;
242 });
197 });243 });
198244
199 it('Fungible up to an approved amount', async () => {245 it('Fungible up to an approved amount', async () => {
200 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});246 await usingPlaygrounds(async (helper) => {
247 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
201 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address); 248 await helper.ft.mintTokens(alice, collectionId, bob.address, 10n);
249 const tokenId = await helper.ft.getLastTokenId(collectionId);
202 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);250 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
203 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');251 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
252 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
204 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);253 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
254 expect(after - before).to.be.equal(BigInt(1));
255
256 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
257 await expect(transferTokenFromTx()).to.be.rejected;
258 });
205 });259 });
206260
207 it('ReFungible up to an approved amount', async function() {261 it('ReFungible up to an approved amount', async function() {
208 await requirePallets(this, [Pallets.ReFungible]);262 await usingPlaygrounds(async (helper) => {
209
210 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});263 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
211 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);264 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
212 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);265 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
213 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');266 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
267 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);
214 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);268 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
269 expect(after - before).to.be.equal(BigInt(100));
270 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);
271 await expect(transferTokenFromTx()).to.be.rejected;
272 });
215 });273 });
216});274});
217275
222 let dave: IKeyringPair;280 let dave: IKeyringPair;
223281
224 before(async () => {282 before(async () => {
225 await usingApi(async (api, privateKeyWrapper) => {283 await usingPlaygrounds(async (helper) => {
226 alice = privateKeyWrapper('//Alice');284 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
227 bob = privateKeyWrapper('//Bob');
228 charlie = privateKeyWrapper('//Charlie');
229 dave = privateKeyWrapper('//Dave');
230 });285 });
231 }); 286 });
232287
233 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {288 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {
234 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});289 await usingPlaygrounds(async (helper) => {
290 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
235 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address); 291 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
292 const tokenId = await helper.ft.getLastTokenId(collectionId);
236 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 10);293 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
294
237 await transferFromExpectSuccess(collectionId, itemId, bob, alice, charlie, 2, 'Fungible');295 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
296 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);
297 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
238 await transferFromExpectSuccess(collectionId, itemId, bob, alice, dave, 8, 'Fungible');298 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));
299
300 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
301 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);
302 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
303 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));
304 });
239 });305 });
240});306});
241307
245 let charlie: IKeyringPair;311 let charlie: IKeyringPair;
246312
247 before(async () => {313 before(async () => {
248 await usingApi(async (api, privateKeyWrapper) => {314 await usingPlaygrounds(async (helper) => {
249 alice = privateKeyWrapper('//Alice');315 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
250 bob = privateKeyWrapper('//Bob');
251 charlie = privateKeyWrapper('//Charlie');
252 });316 });
253 });317 });
254318
255 it('NFT', async () => {319 it('NFT', async () => {
256 const collectionId = await createCollectionExpectSuccess();320 await usingPlaygrounds(async (helper) => {
321 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
257 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT');322 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
258 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);323 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
259 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 0);324 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
325 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));
260 await transferFromExpectFail(collectionId, itemId, bob, bob, charlie, 1);326 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
327 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});
328 await expect(transferTokenFromTx()).to.be.rejected;
329 });
261 });330 });
262331
263 it('Fungible', async () => {332 it('Fungible', async () => {
264 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});333 await usingPlaygrounds(async (helper) => {
334 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
265 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');335 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
336 const tokenId = await helper.ft.getLastTokenId(collectionId);
337 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
266 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);338 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
339 expect(amountBefore).to.be.equal(BigInt(1));
340
267 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);341 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
268 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, bob, charlie, 1);342 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
343 expect(amountAfter).to.be.equal(BigInt(0));
344
345 const transferTokenFromTx = async () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);
346 await expect(transferTokenFromTx()).to.be.rejected;
347 });
269 });348 });
270349
271 it('ReFungible', async function() {350 it('ReFungible', async function() {
272 await requirePallets(this, [Pallets.ReFungible]);351 await usingPlaygrounds(async (helper) => {
352 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
353 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
354 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
355 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
356 expect(amountBefore).to.be.equal(BigInt(1));
273357
274 const reFungibleCollectionId =358 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
275 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
276 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');359 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
277 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);360 expect(amountAfter).to.be.equal(BigInt(0));
361
278 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);362 const transferTokenFromTx = async () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);
279 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, bob, charlie, 1);363 await expect(transferTokenFromTx()).to.be.rejected;
364 });
280 });365 });
281});366});
282367
286 let charlie: IKeyringPair;371 let charlie: IKeyringPair;
287372
288 before(async () => {373 before(async () => {
289 await usingApi(async (api, privateKeyWrapper) => {374 await usingPlaygrounds(async (helper) => {
290 alice = privateKeyWrapper('//Alice');375 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
291 bob = privateKeyWrapper('//Bob');
292 charlie = privateKeyWrapper('//Charlie');
293 });376 });
294 });377 });
295378
296 it('1 for NFT', async () => {379 it('1 for NFT', async () => {
297 const collectionId = await createCollectionExpectSuccess();380 await usingPlaygrounds(async (helper) => {
381 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
298 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);382 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
299 await approveExpectFail(collectionId, itemId, bob, charlie, 2);383 const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2));
384 await expect(approveTx()).to.be.rejected;
385 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
386 });
300 });387 });
301388
302 it('Fungible', async () => {389 it('Fungible', async () => {
303 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});390 await usingPlaygrounds(async (helper) => {
391 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
304 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');392 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
305 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, charlie, 11);393 const tokenId = await helper.ft.getLastTokenId(collectionId);
394 const approveTx = async () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n);
395 await expect(approveTx()).to.be.rejected;
396 });
306 });397 });
307398
308 it('ReFungible', async function() {399 it('ReFungible', async function() {
309 await requirePallets(this, [Pallets.ReFungible]);400 await usingPlaygrounds(async (helper) => {
310
311 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});401 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
312 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');402 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
313 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, charlie, 101);403 const approveTx = async () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n);
404 await expect(approveTx()).to.be.rejected;
405 });
314 });406 });
315});407});
316408
321 let dave: IKeyringPair;413 let dave: IKeyringPair;
322414
323 before(async () => {415 before(async () => {
324 await usingApi(async (api, privateKeyWrapper) => {416 await usingPlaygrounds(async (helper) => {
325 alice = privateKeyWrapper('//Alice');417 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
326 bob = privateKeyWrapper('//Bob');
327 charlie = privateKeyWrapper('//Charlie');
328 dave = privateKeyWrapper('//Dave');
329 });418 });
330 }); 419 });
331420
332 it('NFT', async () => {421 it('NFT', async () => {
333 const collectionId = await createCollectionExpectSuccess();422 await usingPlaygrounds(async (helper) => {
423 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
334 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});424 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
335 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', charlie.address);425 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: charlie.address});
426
336 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'NFT');427 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address});
428 const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId);
337 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);429 expect(owner1.Substrate).to.be.equal(dave.address);
430
431 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
338 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'NFT');432 await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address});
433 const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId);
434 expect(owner2.Substrate).to.be.equal(alice.address);
435 });
339 });436 });
340437
341 it('Fungible up to an approved amount', async () => {438 it('Fungible up to an approved amount', async () => {
342 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});439 await usingPlaygrounds(async (helper) => {
440 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
343 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});441 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
344 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', charlie.address); 442 await helper.ft.mintTokens(alice, collectionId, charlie.address, 10n);
443 const tokenId = await helper.ft.getLastTokenId(collectionId);
444
345 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'Fungible');445 const daveBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
446 await helper.ft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);
447 const daveBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
346 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);448 expect(daveBalanceAfter - daveBalanceBefore).to.be.equal(BigInt(1));
449
450 await helper.collection.addAdmin(alice ,collectionId, {Substrate: bob.address});
451
347 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'Fungible');452 const aliceBalanceBefore = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
453 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);
454 const aliceBalanceAfter = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
455 expect(aliceBalanceAfter - aliceBalanceBefore).to.be.equal(BigInt(1));
456 });
348 });457 });
349458
350 it('ReFungible up to an approved amount', async function() {459 it('ReFungible up to an approved amount', async function() {
351 await requirePallets(this, [Pallets.ReFungible]);460 await usingPlaygrounds(async (helper) => {
461 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
462 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
463 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: charlie.address, pieces: 100n});
352464
353 const collectionId = await createCollectionExpectSuccess({mode:{type: 'ReFungible'}});465 const daveBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});
354 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});466 await helper.rft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address}, 1n);
355 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', charlie.address);467 const daveAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: dave.address});
468 expect(daveAfter - daveBefore).to.be.equal(BigInt(1));
469
470 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
471
356 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'ReFungible');472 const aliceBefore = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
473 await helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address}, 1n);
357 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);474 const aliceAfter = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
358 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'ReFungible');475 expect(aliceAfter - aliceBefore).to.be.equal(BigInt(1));
476 });
359 });477 });
360});478});
361479
366 let dave: IKeyringPair;484 let dave: IKeyringPair;
367485
368 before(async () => {486 before(async () => {
369 await usingApi(async (api, privateKeyWrapper) => {487 await usingPlaygrounds(async (helper) => {
370 alice = privateKeyWrapper('//Alice');488 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
371 bob = privateKeyWrapper('//Bob');
372 charlie = privateKeyWrapper('//Charlie');
373 dave = privateKeyWrapper('//Dave');
374 });489 });
375 }); 490 });
376491
377 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {492 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {
378 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});493 const collectionId = await createCollectionExpectSuccess({mode:{type: 'Fungible', decimalPoints: 0}});
417 let charlie: IKeyringPair;532 let charlie: IKeyringPair;
418533
419 before(async () => {534 before(async () => {
420 await usingApi(async (api, privateKeyWrapper) => {535 await usingPlaygrounds(async (helper) => {
421 alice = privateKeyWrapper('//Alice');536 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
422 bob = privateKeyWrapper('//Bob');
423 charlie = privateKeyWrapper('//Charlie');
424 });537 });
425 });538 });
426539
427 it('can be called by collection admin on non-owned item', async () => {540 it('can be called by collection admin on non-owned item', async () => {
428 const collectionId = await createCollectionExpectSuccess();541 await usingPlaygrounds(async (helper) => {
542 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
429 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);543 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
430
431 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);544 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
432 await adminApproveFromExpectFail(collectionId, itemId, bob, alice.address, charlie.address);545 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
546 await expect(approveTx()).to.be.rejected;
547 });
433 });548 });
434});549});
435550
439 let charlie: IKeyringPair;554 let charlie: IKeyringPair;
440555
441 before(async () => {556 before(async () => {
442 await usingApi(async (api, privateKeyWrapper) => {557 await usingPlaygrounds(async (helper) => {
443 alice = privateKeyWrapper('//Alice');558 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
444 bob = privateKeyWrapper('//Bob');
445 charlie = privateKeyWrapper('//Charlie');
446 });559 });
447 });560 });
448561
449 it('[nft] Approve for a collection that does not exist', async () => {562 it('[nft] Approve for a collection that does not exist', async () => {
450 await usingApi(async (api: ApiPromise) => {563 await usingPlaygrounds(async (helper) => {
451 const nftCollectionCount = await getCreatedCollectionCount(api);564 const collectionId = 1 << 32 - 1;
452 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);565 const approveTx = async () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
566 await expect(approveTx()).to.be.rejected;
453 });567 });
454 });568 });
455569
456 it('[fungible] Approve for a collection that does not exist', async () => {570 it('[fungible] Approve for a collection that does not exist', async () => {
457 await usingApi(async (api: ApiPromise) => {571 await usingPlaygrounds(async (helper) => {
458 const fungibleCollectionCount = await getCreatedCollectionCount(api);572 const collectionId = 1 << 32 - 1;
459 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);573 const approveTx = async () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
574 await expect(approveTx()).to.be.rejected;
460 });575 });
461 });576 });
462577
463 it('[refungible] Approve for a collection that does not exist', async function() {578 it('[refungible] Approve for a collection that does not exist', async function() {
464 await requirePallets(this, [Pallets.ReFungible]);579 await usingPlaygrounds(async (helper) => {
465
466 await usingApi(async (api: ApiPromise) => {
467 const reFungibleCollectionCount = await getCreatedCollectionCount(api);580 const collectionId = 1 << 32 - 1;
468 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);581 const approveTx = async () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
582 await expect(approveTx()).to.be.rejected;
469 });583 });
470 });584 });
471585
472 it('[nft] Approve for a collection that was destroyed', async () => {586 it('[nft] Approve for a collection that was destroyed', async () => {
473 const nftCollectionId = await createCollectionExpectSuccess();587 await usingPlaygrounds(async (helper) => {
588 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
474 await destroyCollectionExpectSuccess(nftCollectionId);589 await helper.nft.burn(alice, collectionId);
475 await approveExpectFail(nftCollectionId, 1, alice, bob);590 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
591 await expect(approveTx()).to.be.rejected;
592 });
476 });593 });
477594
478 it('Approve for a collection that was destroyed', async () => {595 it('[fungible] Approve for a collection that was destroyed', async () => {
479 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});596 await usingPlaygrounds(async (helper) => {
597 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
480 await destroyCollectionExpectSuccess(fungibleCollectionId);598 await helper.ft.burn(alice, collectionId);
481 await approveExpectFail(fungibleCollectionId, 0, alice, bob);599 const approveTx = async () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
600 await expect(approveTx()).to.be.rejected;
601 });
482 });602 });
483603
484 it('[refungible] Approve for a collection that was destroyed', async function() {604 it('[refungible] Approve for a collection that was destroyed', async function() {
485 await requirePallets(this, [Pallets.ReFungible]);605 await usingPlaygrounds(async (helper) => {
486
487 const reFungibleCollectionId =606 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
488 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
489 await destroyCollectionExpectSuccess(reFungibleCollectionId);607 await helper.rft.burn(alice, collectionId);
490 await approveExpectFail(reFungibleCollectionId, 1, alice, bob);608 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
609 await expect(approveTx()).to.be.rejected;
610 });
491 });611 });
492612
493 it('[nft] Approve transfer of a token that does not exist', async () => {613 it('[nft] Approve transfer of a token that does not exist', async () => {
494 const nftCollectionId = await createCollectionExpectSuccess();614 await usingPlaygrounds(async (helper) => {
615 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
495 await approveExpectFail(nftCollectionId, 2, alice, bob);616 const approveTx = async () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});
617 await expect(approveTx()).to.be.rejected;
618 });
496 });619 });
497620
498 it('[refungible] Approve transfer of a token that does not exist', async function() {621 it('[refungible] Approve transfer of a token that does not exist', async function() {
499 await requirePallets(this, [Pallets.ReFungible]);622 await usingPlaygrounds(async (helper) => {
500
501 const reFungibleCollectionId =623 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
502 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
503 await approveExpectFail(reFungibleCollectionId, 2, alice, bob);624 const approveTx = async () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});
625 await expect(approveTx()).to.be.rejected;
626 });
504 });627 });
505628
506 it('[nft] Approve using the address that does not own the approved token', async () => {629 it('[nft] Approve using the address that does not own the approved token', async () => {
507 const nftCollectionId = await createCollectionExpectSuccess();630 await usingPlaygrounds(async (helper) => {
631 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
508 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');632 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
509 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);633 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
634 await expect(approveTx()).to.be.rejected;
635 });
510 });636 });
511637
512 it('[fungible] Approve using the address that does not own the approved token', async () => {638 it('[fungible] Approve using the address that does not own the approved token', async () => {
513 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});639 await usingPlaygrounds(async (helper) => {
640 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
514 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');641 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
515 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);642 const tokenId = await helper.ft.getLastTokenId(collectionId);
643 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
644 await expect(approveTx()).to.be.rejected;
645 });
516 });646 });
517647
518 it('[refungible] Approve using the address that does not own the approved token', async function() {648 it('[refungible] Approve using the address that does not own the approved token', async function() {
519 await requirePallets(this, [Pallets.ReFungible]);649 await usingPlaygrounds(async (helper) => {
520
521 const reFungibleCollectionId =650 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
522 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
523 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');651 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
524 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);652 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
653 await expect(approveTx()).to.be.rejected;
654 });
525 });655 });
526656
527 it('should fail if approved more ReFungibles than owned', async function() {657 it('should fail if approved more ReFungibles than owned', async function() {
528 await requirePallets(this, [Pallets.ReFungible]);658 await usingPlaygrounds(async (helper) => {
659 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
660 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
661 await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);
662 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n);
529663
530 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});664 const approveTx = async () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n);
531 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');
532 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');
533 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);
534 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);665 await expect(approveTx()).to.be.rejected;
666 });
535 });667 });
536668
537 it('should fail if approved more Fungibles than owned', async () => {669 it('should fail if approved more Fungibles than owned', async () => {
538 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});670 await usingPlaygrounds(async (helper) => {
671 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
539 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');672 await helper.ft.mintTokens(alice, collectionId, alice.address, 10n);
540 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');673 const tokenId = await helper.ft.getLastTokenId(collectionId);
674
675 await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
541 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);676 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n);
542 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);677 const approveTx = async () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n);
678 await expect(approveTx()).to.be.rejected;
679 });
543 });680 });
544681
545 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {682 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
546 const collectionId = await createCollectionExpectSuccess();683 await usingPlaygrounds(async (helper) => {
684 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
547 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);685 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
548 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});686 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});
549687
550 await approveExpectFail(collectionId, itemId, alice, charlie);688 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
689 await expect(approveTx()).to.be.rejected;
690 });
551 });691 });
552});692});
553693
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -255,9 +255,9 @@
     return network;
   }
 
-  static async createConnection(wsEndpoint: string, listeners?: IApiListeners, network?: TUniqueNetworks | null): Promise<{ 
-    api: ApiPromise; 
-    network: TUniqueNetworks; 
+  static async createConnection(wsEndpoint: string, listeners?: IApiListeners, network?: TUniqueNetworks | null): Promise<{
+    api: ApiPromise;
+    network: TUniqueNetworks;
   }> {
     if(typeof network === 'undefined' || network === null) network = 'opal';
     const supportedRPC = {
@@ -444,7 +444,7 @@
     if(this.api === null) throw Error('API not initialized');
     return this.api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());
   }
-  
+
   fetchMissingPalletNames(requiredPallets: string[]): string[] {
     const palletNames = this.fetchAllPalletNames();
     return requiredPallets.filter(p => !palletNames.includes(p));
@@ -477,7 +477,7 @@
 
   /**
    * Get the number of created collections.
-   * 
+   *
    * @returns number of created collections
    */
   async getTotalCount(): Promise<number> {
@@ -485,10 +485,10 @@
   }
 
   /**
-   * Get information about the collection with additional data, 
-   * including the number of tokens it contains, its administrators, 
+   * Get information about the collection with additional data,
+   * including the number of tokens it contains, its administrators,
    * the normalized address of the collection's owner, and decoded name and description.
-   * 
+   *
    * @param collectionId ID of collection
    * @example await getData(2)
    * @returns collection information object
@@ -515,8 +515,8 @@
       collectionData[key] = this.helper.util.vec2str(humanCollection[key]);
     }
 
-    collectionData.tokensCount = (['RFT', 'NFT'].includes(humanCollection.mode)) 
-      ? await this.helper[humanCollection.mode.toLocaleLowerCase() as 'nft' | 'rft'].getLastTokenId(collectionId) 
+    collectionData.tokensCount = (['RFT', 'NFT'].includes(humanCollection.mode))
+      ? await this.helper[humanCollection.mode.toLocaleLowerCase() as 'nft' | 'rft'].getLastTokenId(collectionId)
       : 0;
     collectionData.admins = await this.getAdmins(collectionId);
 
@@ -525,7 +525,7 @@
 
   /**
    * Get the addresses of the collection's administrators, optionally normalized.
-   * 
+   *
    * @param collectionId ID of collection
    * @param normalize whether to normalize the addresses to the default ss58 format
    * @example await getAdmins(1)
@@ -539,7 +539,7 @@
         return address.Substrate
           ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
           : address;
-      }) 
+      })
       : admins;
   }
 
@@ -557,13 +557,13 @@
         return address.Substrate
           ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
           : address;
-      }) 
+      })
       : allowListed;
   }
 
   /**
    * Get the effective limits of the collection instead of null for default values
-   * 
+   *
    * @param collectionId ID of collection
    * @example await getEffectiveLimits(2)
    * @returns object of collection limits
@@ -574,7 +574,7 @@
 
   /**
    * Burns the collection if the signer has sufficient permissions and collection is empty.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @example await helper.collection.burn(aliceKeyring, 3);
@@ -592,7 +592,7 @@
 
   /**
    * Sets the sponsor for the collection (Requires the Substrate address). Needs confirmation by the sponsor.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param sponsorAddress Sponsor substrate address
@@ -611,7 +611,7 @@
 
   /**
    * Confirms consent to sponsor the collection on behalf of the signer.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @example confirmSponsorship(aliceKeyring, 10)
@@ -629,7 +629,7 @@
 
   /**
    * Removes the sponsor of a collection, regardless if it consented or not.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @example removeSponsor(aliceKeyring, 10)
@@ -647,7 +647,7 @@
 
   /**
    * Sets the limits of the collection. At least one limit must be specified for a correct call.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param limits collection limits object
@@ -674,7 +674,7 @@
 
   /**
    * Changes the owner of the collection to the new Substrate address.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param ownerAddress substrate address of new owner
@@ -692,8 +692,8 @@
   }
 
   /**
-   * Adds a collection administrator. 
-   * 
+   * Adds a collection administrator.
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param adminAddressObj Administrator address (substrate or ethereum)
@@ -712,7 +712,7 @@
 
   /**
    * Removes a collection administrator.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param adminAddressObj Administrator address (substrate or ethereum)
@@ -730,7 +730,7 @@
   }
 
   /**
-   * Adds an address to allow list 
+   * Adds an address to allow list
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param addressObj address to add to the allow list
@@ -747,8 +747,8 @@
   }
 
   /**
-   * Removes an address from allow list 
-   * 
+   * Removes an address from allow list
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param addressObj address to remove from the allow list
@@ -766,7 +766,7 @@
 
   /**
    * Sets onchain permissions for selected collection.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param permissions collection permissions object
@@ -785,7 +785,7 @@
 
   /**
    * Enables nesting for selected collection. If `restricted` set, you can nest only tokens from specified collections.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param permissions nesting permissions object
@@ -798,7 +798,7 @@
 
   /**
    * Disables nesting for selected collection.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @example disableNesting(aliceKeyring, 10);
@@ -810,7 +810,7 @@
 
   /**
    * Sets onchain properties to the collection.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param properties array of property objects
@@ -829,7 +829,7 @@
 
   /**
    * Deletes onchain properties from the collection.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param propertyKeys array of property keys to delete
@@ -848,7 +848,7 @@
 
   /**
    * Changes the owner of the token.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -868,9 +868,9 @@
   }
 
   /**
-   * 
-   * Change ownership of a token(s) on behalf of the owner. 
-   * 
+   *
+   * Change ownership of a token(s) on behalf of the owner.
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -890,9 +890,9 @@
   }
 
   /**
-   * 
+   *
    * Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -916,7 +916,7 @@
 
   /**
    * Destroys a concrete instance of NFT on behalf of the owner
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param fromAddressObj address on behalf of which the token will be burnt
@@ -937,7 +937,7 @@
 
   /**
    * Set, change, or remove approved address to transfer the ownership of the NFT.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -947,7 +947,7 @@
    */
   async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
     const approveResult = await this.helper.executeExtrinsic(
-      signer, 
+      signer,
       'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],
       true, // `Unable to approve token for ${label}`,
     );
@@ -957,7 +957,7 @@
 
   /**
    * Get the amount of token pieces approved to transfer or burn. Normally 0.
-   * 
+   *
    * @param collectionId ID of collection
    * @param tokenId ID of token
    * @param toAccountObj address which is approved to use token pieces
@@ -971,7 +971,7 @@
 
   /**
    * Get the last created token ID in a collection
-   * 
+   *
    * @param collectionId ID of collection
    * @example getLastTokenId(10);
    * @returns id of the last created token
@@ -982,7 +982,7 @@
 
   /**
    * Check if token exists
-   * 
+   *
    * @param collectionId ID of collection
    * @param tokenId ID of token
    * @example isTokenExists(10, 20);
@@ -996,7 +996,7 @@
 class NFTnRFT extends CollectionGroup {
   /**
    * Get tokens owned by account
-   * 
+   *
    * @param collectionId ID of collection
    * @param addressObj tokens owner
    * @example getTokensByAddress(10, {Substrate: "5DyN4Y92vZCjv38fg..."})
@@ -1008,13 +1008,13 @@
 
   /**
    * Get token data
-   * 
+   *
    * @param collectionId ID of collection
    * @param tokenId ID of token
    * @param propertyKeys optionally filter the token properties to only these keys
    * @param blockHashAt optionally query the data at some block with this hash
    * @example getToken(10, 5);
-   * @returns human readable token data 
+   * @returns human readable token data
    */
   async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{
     properties: IProperty[];
@@ -1045,7 +1045,7 @@
 
   /**
    * Set permissions to change token properties
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param permissions permissions to change a property by the collection owner or admin
@@ -1066,7 +1066,7 @@
 
   /**
    * Set token properties
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -1089,7 +1089,7 @@
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
-   * @param propertyKeys property keys to be deleted 
+   * @param propertyKeys property keys to be deleted
    * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])
    * @returns ```true``` if extrinsic success, otherwise ```false```
    */
@@ -1105,9 +1105,9 @@
 
   /**
    * Mint new collection
-   * 
+   *
    * @param signer keyring of signer
-   * @param collectionOptions basic collection options and properties 
+   * @param collectionOptions basic collection options and properties
    * @param mode NFT or RFT type of a collection
    * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")
    * @returns object of the created collection
@@ -1189,7 +1189,7 @@
 
   /**
    * Changes the owner of the token.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -1202,9 +1202,9 @@
   }
 
   /**
-   * 
-   * Change ownership of a NFT on behalf of the owner. 
-   * 
+   *
+   * Change ownership of a NFT on behalf of the owner.
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -1221,7 +1221,7 @@
    * Recursively find the address that owns the token
    * @param collectionId ID of collection
    * @param tokenId ID of token
-   * @param blockHashAt 
+   * @param blockHashAt
    * @example getTokenTopmostOwner(10, 5);
    * @returns address in CrossAccountId format, e.g. {Substrate: "5DyN4Y92vZCjv38fg..."}
    */
@@ -1246,7 +1246,7 @@
    * @param tokenId ID of token
    * @param blockHashAt optionally query the data at the block with this hash
    * @example getTokenChildren(10, 5);
-   * @returns tokens whose depth of nesting is <= 5 
+   * @returns tokens whose depth of nesting is <= 5
    */
   async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {
     let children;
@@ -1283,7 +1283,7 @@
    * @param signer keyring of signer
    * @param tokenObj token to unnest
    * @param rootTokenObj parent of a token
-   * @param toAddressObj address of a new token owner 
+   * @param toAddressObj address of a new token owner
    * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});
    * @returns ```true``` if extrinsic success, otherwise ```false```
    */
@@ -1300,7 +1300,7 @@
    * Mint new collection
    * @param signer keyring of signer
    * @param collectionOptions Collection options
-   * @example 
+   * @example
    * mintCollection(aliceKeyring, {
    *   name: 'New',
    *   description: 'New collection',
@@ -1339,7 +1339,7 @@
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokens array of tokens with owner and properties
-   * @example 
+   * @example
    * mintMultipleTokens(aliceKeyring, 10, [{
    *     owner: {Substrate: "5DyN4Y92vZCjv38fg..."},
    *     properties: [{key: "gender", value: "male"},{key: "age", value: "45"}],
@@ -1390,23 +1390,11 @@
     );
     const collection = this.getCollectionObject(collectionId);
     return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
-  }
-
-  /**
-   * Destroys a concrete instance of NFT.
-   * @param signer keyring of signer
-   * @param collectionId ID of collection
-   * @param tokenId ID of token
-   * @example burnToken(aliceKeyring, 10, 5);
-   * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
-   */
-  async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number): Promise<{ success: boolean; token: number | null; }> {
-    return await super.burnToken(signer, collectionId, tokenId, 1n);
   }
 
   /**
    * Set, change, or remove approved address to transfer the ownership of the NFT.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -1443,7 +1431,7 @@
   }
 
   /**
-   * Get top 10 token owners with the largest number of pieces 
+   * Get top 10 token owners with the largest number of pieces
    * @param collectionId ID of collection
    * @param tokenId ID of token
    * @example getTokenTop10Owners(10, 5);
@@ -1480,7 +1468,7 @@
   }
 
   /**
-   * Change ownership of some pieces of RFT on behalf of the owner. 
+   * Change ownership of some pieces of RFT on behalf of the owner.
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -1584,7 +1572,7 @@
 
   /**
    * Set, change, or remove approved address to transfer the ownership of the RFT.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param tokenId ID of token
@@ -1645,7 +1633,7 @@
    * Mint new fungible collection
    * @param signer keyring of signer
    * @param collectionOptions Collection options
-   * @param decimalPoints number of token decimals 
+   * @param decimalPoints number of token decimals
    * @example
    * mintCollection(aliceKeyring, {
    *   name: 'New',
@@ -1676,7 +1664,7 @@
    * @param owner address owner of new tokens
    * @param amount amount of tokens to be meanted
    * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async mintTokens(signer: TSigner, collectionId: number, amount: bigint, owner: ICrossAccountId | string): Promise<boolean> {
     const creationResult = await this.helper.executeExtrinsic(
@@ -1697,7 +1685,7 @@
    * @param collectionId ID of collection
    * @param owner tokens owner
    * @param tokens array of tokens with properties and pieces
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, tokens: {value: bigint}[], owner: ICrossAccountId): Promise<boolean> {
     const rawTokens = [];
@@ -1714,7 +1702,7 @@
   }
 
   /**
-   * Get the top 10 owners with the largest balance for the Fungible collection 
+   * Get the top 10 owners with the largest balance for the Fungible collection
    * @param collectionId ID of collection
    * @example getTop10Owners(10);
    * @returns array of ```ICrossAccountId```
@@ -1741,7 +1729,7 @@
    * @param toAddressObj address recipient
    * @param amount amount of tokens to be sent
    * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
     return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);
@@ -1755,7 +1743,7 @@
    * @param toAddressObj address where token to be sent
    * @param amount number of tokens to be sent
    * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
     return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);
@@ -1767,7 +1755,7 @@
    * @param collectionId ID of collection
    * @param amount amount of tokens to be destroyed
    * @example burnTokens(aliceKeyring, 10, 1000n);
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {
     return (await super.burnToken(signer, collectionId, 0, amount)).success;
@@ -1780,7 +1768,7 @@
    * @param fromAddressObj address on behalf of which tokens will be burnt
    * @param amount amount of tokens to be burnt
    * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {
     return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, amount);
@@ -1788,8 +1776,8 @@
 
   /**
    * Get total collection supply
-   * @param collectionId 
-   * @returns 
+   * @param collectionId
+   * @returns
    */
   async getTotalPieces(collectionId: number): Promise<bigint> {
     return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, 0])).unwrap().toBigInt();
@@ -1797,13 +1785,13 @@
 
   /**
    * Set, change, or remove approved address to transfer tokens.
-   * 
+   *
    * @param signer keyring of signer
    * @param collectionId ID of collection
    * @param toAddressObj address to be approved
    * @param amount amount of tokens to be approved
    * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)
-   * @returns ```true``` if extrinsic success, otherwise ```false``` 
+   * @returns ```true``` if extrinsic success, otherwise ```false```
    */
   async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
     return super.approveToken(signer, collectionId, 0, toAddressObj, amount);
@@ -1901,7 +1889,7 @@
   /**
    * Get full substrate balance including free, miscFrozen, feeFrozen, and reserved
    * @param address substrate address
-   * @returns 
+   * @returns
    */
   async getSubstrateFull(address: TSubstrateAccount): Promise<ISubstrateBalance> {
     const accountInfo = (await this.helper.callRpc('api.query.system.account', [address])).data;
@@ -2022,7 +2010,7 @@
   async unstake(signer: TSigner, label?: string): Promise<number> {
     if(typeof label === 'undefined') label = `${signer.address}`;
     const unstakeResult = await this.helper.executeExtrinsic(
-      signer, 'api.tx.appPromotion.unstake', 
+      signer, 'api.tx.appPromotion.unstake',
       [], true,
     );
     // TODO extract block number fron events
@@ -2041,7 +2029,7 @@
   async getPendingUnstake(address: ICrossAccountId): Promise<bigint> {
     return (await this.helper.callRpc('api.rpc.appPromotion.pendingUnstake', [address])).toBigInt();
   }
-  
+
   async getPendingUnstakePerBlock(address: ICrossAccountId): Promise<bigint[][]> {
     return (await this.helper.callRpc('api.rpc.appPromotion.pendingUnstakePerBlock', [address])).map(([block, amount]: any[]) => [block.toBigInt(), amount.toBigInt()]);
   }
@@ -2067,7 +2055,7 @@
     this.rft = new RFTGroup(this);
     this.ft = new FTGroup(this);
     this.staking = new StakingGroup(this);
-  }  
+  }
 }