git.delta.rocks / unique-network / refs/commits / 27a31c97aaab

difftreelog

Merge pull request #620 from UniqueNetwork/test/burnItemPlaygrounds

ut-akuznetsov2022-10-04parents: #e9e910f #55c7c97.patch.diff
in: master
Move burnItemTests to playgrounds

5 files changed

modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -34,7 +34,10 @@
 let accounts: IKeyringPair[] = [];
 const LOCKING_PERIOD = 20n; // 20 blocks of relay
 const UNLOCKING_PERIOD = 10n; // 10 blocks of parachain
-const rewardAvailableInBlock = (stakedInBlock: bigint) => (stakedInBlock - stakedInBlock % LOCKING_PERIOD) + (LOCKING_PERIOD * 2n);
+const rewardAvailableInBlock = (stakedInBlock: bigint) => {
+  if (stakedInBlock % LOCKING_PERIOD === 0n) return stakedInBlock + 20n;
+  return (stakedInBlock - stakedInBlock % LOCKING_PERIOD) + (LOCKING_PERIOD * 2n);
+};
 
 describe('App promotion', () => {
   before(async function () {
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -14,289 +14,145 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
 import {IKeyringPair} from '@polkadot/types/types';
-import {
-  createCollectionExpectSuccess,
-  createItemExpectSuccess,
-  getGenericResult,
-  normalizeAccountId,
-  addCollectionAdminExpectSuccess,
-  getBalance,
-  setCollectionLimitsExpectSuccess,
-  isTokenExists,
-  requirePallets,
-  Pallets,
-} from './util/helpers';
+import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds';
 
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-chai.use(chaiAsPromised);
-const expect = chai.expect;
 
-let alice: IKeyringPair;
-let bob: IKeyringPair;
+describe('integration test: ext. burnItem():', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
 
-describe('integration test: ext. burnItem():', () => {
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
+    await usingPlaygrounds(async (helper, privateKey) => {
+      donor = privateKey('//Alice');
+      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
     });
   });
-
-  it('Burn item in NFT collection', async () => {
-    const createMode = 'NFT';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
 
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);
-      const events = await submitTransactionAsync(alice, tx);
-      const result = getGenericResult(events);
+  itSub('Burn item in NFT collection', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice);
+    const token = await collection.mintToken(alice);
 
-      expect(result.success).to.be.true;
-      // Get the item
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
-    });
+    await token.burn(alice);
+    expect(await token.doesExist()).to.be.false;
   });
-
-  it('Burn item in Fungible collection', async () => {
-    const createMode = 'Fungible';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
-    await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
-    const tokenId = 0; // ignored
 
-    await usingApi(async (api) => {
-      // Destroy 1 of 10
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);
-      const events = await submitTransactionAsync(alice, tx);
-      const result = getGenericResult(events);
-
-      // Get alice balance
-      const balance = await getBalance(api, collectionId, alice.address, 0);
+  itSub('Burn item in Fungible collection', async ({helper}) => {
+    const collection = await helper.ft.mintCollection(alice, {}, 10);
+    await collection.mint(alice, 10n);
 
-      // What to expect
-      expect(result.success).to.be.true;
-      expect(balance).to.be.equal(9n);
-    });
+    await collection.burnTokens(alice, 1n);
+    expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
   });
 
-  it('Burn item in ReFungible collection', async function() {
-    await requirePallets(this, [Pallets.ReFungible]);
+  itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
+    const collection = await helper.rft.mintCollection(alice);
+    const token = await collection.mintToken(alice, 100n);
 
-    const createMode = 'ReFungible';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+    await token.burn(alice, 90n);
+    expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);
 
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 100);
-      const events = await submitTransactionAsync(alice, tx);
-      const result = getGenericResult(events);
-
-      // Get alice balance
-      const balance = await getBalance(api, collectionId, alice.address, tokenId);
-
-      // What to expect
-      expect(result.success).to.be.true;
-      expect(balance).to.be.equal(0n);
-    });
+    await token.burn(alice, 10n);
+    expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);
   });
 
-  it('Burn owned portion of item in ReFungible collection', async function() {
-    await requirePallets(this, [Pallets.ReFungible]);
-
-    const createMode = 'ReFungible';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
-
-    await usingApi(async (api) => {
-      // Transfer 1/100 of the token to Bob
-      const transfertx = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);
-      const events1 = await submitTransactionAsync(alice, transfertx);
-      const result1 = getGenericResult(events1);
-
-      // Get balances
-      const bobBalanceBefore = await getBalance(api, collectionId, bob.address, tokenId);
-      const aliceBalanceBefore = await getBalance(api, collectionId, alice.address, tokenId);
-
-      // Bob burns his portion
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);
-      const events2 = await submitTransactionAsync(bob, tx);
-      const result2 = getGenericResult(events2);
+  itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
+    const collection = await helper.rft.mintCollection(alice);
+    const token = await collection.mintToken(alice, 100n);
 
-      // Get balances
-      const bobBalanceAfter = await getBalance(api, collectionId, bob.address, tokenId);
-      const aliceBalanceAfter = await getBalance(api, collectionId, alice.address, tokenId);
-      // console.log(balance);
+    await token.transfer(alice, {Substrate: bob.address}, 1n);
 
-      // What to expect before burning
-      expect(result1.success).to.be.true;
-      expect(aliceBalanceBefore).to.be.equal(99n);
-      expect(bobBalanceBefore).to.be.equal(1n);
+    expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
+    expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);
 
-      // What to expect after burning
-      expect(result2.success).to.be.true;
-      expect(aliceBalanceAfter).to.be.equal(99n);
-      expect(bobBalanceAfter).to.be.equal(0n);
-    });
+    await token.burn(bob, 1n);
 
+    expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
+    expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);
   });
-
 });
 
 describe('integration test: ext. burnItem() with admin permissions:', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
+    await usingPlaygrounds(async (helper, privateKey) => {
+      donor = privateKey('//Alice');
+      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
     });
   });
 
-  it('Burn item in NFT collection', async () => {
-    const createMode = 'NFT';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+  itSub('Burn item in NFT collection', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice);
+    await collection.setLimits(alice, {ownerCanTransfer: true});
+    await collection.addAdmin(alice, {Substrate: bob.address});
+    const token = await collection.mintToken(alice);
 
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnFrom(collectionId, {Substrate: alice.address}, tokenId, 1);
-      const events = await submitTransactionAsync(bob, tx);
-      const result = getGenericResult(events);
-
-      expect(result.success).to.be.true;
-      // Get the item
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
-    });
+    await token.burnFrom(bob, {Substrate: alice.address});
+    expect(await token.doesExist()).to.be.false;
   });
 
-  // TODO: burnFrom
-  it('Burn item in Fungible collection', async () => {
-    const createMode = 'Fungible';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
-    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+  itSub('Burn item in Fungible collection', async ({helper}) => {
+    const collection = await helper.ft.mintCollection(alice, {}, 0);
+    await collection.setLimits(alice, {ownerCanTransfer: true});
+    await collection.addAdmin(alice, {Substrate: bob.address});
+    await collection.mint(alice, 10n);
 
-    await usingApi(async (api) => {
-      // Destroy 1 of 10
-      const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 1);
-      const events = await submitTransactionAsync(bob, tx);
-      const result = getGenericResult(events);
-
-      // Get alice balance
-      const balance = await getBalance(api, collectionId, alice.address, 0);
-
-      // What to expect
-      expect(result.success).to.be.true;
-      expect(balance).to.be.equal(9n);
-    });
+    await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);
+    expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
   });
 
-  // TODO: burnFrom
-  it('Burn item in ReFungible collection', async function() {
-    await requirePallets(this, [Pallets.ReFungible]);
-
-    const createMode = 'ReFungible';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
-    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+  itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
+    const collection = await helper.rft.mintCollection(alice);
+    await collection.setLimits(alice, {ownerCanTransfer: true});
+    await collection.addAdmin(alice, {Substrate: bob.address});
+    const token = await collection.mintToken(alice, 100n);
 
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 100);
-      const events = await submitTransactionAsync(bob, tx);
-      const result = getGenericResult(events);
-      // Get alice balance
-      expect(result.success).to.be.true;
-      // Get the item
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
-    });
+    await token.burnFrom(bob, {Substrate: alice.address}, 100n);
+    expect(await token.doesExist()).to.be.false;
   });
 });
 
 describe('Negative integration test: ext. burnItem():', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
+    await usingPlaygrounds(async (helper, privateKey) => {
+      donor = privateKey('//Alice');
+      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
     });
   });
 
-  it('Burn a token that was never created', async () => {
-    const createMode = 'NFT';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    const tokenId = 10;
-
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);
-      const badTransaction = async function () {
-        await submitTransactionExpectFailAsync(alice, tx);
-      };
-      await expect(badTransaction()).to.be.rejected;
-    });
-
+  itSub('Burn a token that was never created', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice);
+    await expect(collection.burnToken(alice, 10)).to.be.rejectedWith('common.TokenNotFound');
   });
 
-  it('Burn a token using the address that does not own it', async () => {
-    const createMode = 'NFT';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+  itSub('Burn a token using the address that does not own it', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice);
+    const token = await collection.mintToken(alice);
 
-    await usingApi(async (api) => {
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);
-      const badTransaction = async function () {
-        await submitTransactionExpectFailAsync(bob, tx);
-      };
-      await expect(badTransaction()).to.be.rejected;
-    });
-
+    await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
   });
-
-  it('Transfer a burned a token', async () => {
-    const createMode = 'NFT';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
-    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
-
-    await usingApi(async (api) => {
 
-      const burntx = api.tx.unique.burnItem(collectionId, tokenId, 1);
-      const events1 = await submitTransactionAsync(alice, burntx);
-      const result1 = getGenericResult(events1);
-      expect(result1.success).to.be.true;
+  itSub('Transfer a burned token', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice);
+    const token = await collection.mintToken(alice);
+    await token.burn(alice);
 
-      const tx = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);
-      const badTransaction = async function () {
-        await submitTransactionExpectFailAsync(alice, tx);
-      };
-      await expect(badTransaction()).to.be.rejected;
-    });
-
+    await expect(token.transfer(alice, {Substrate: bob.address})).to.be.rejectedWith('common.TokenNotFound');
   });
-
-  it('Burn more than owned in Fungible collection', async () => {
-    const createMode = 'Fungible';
-    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
-    // Helper creates 10 fungible tokens
-    await createItemExpectSuccess(alice, collectionId, createMode);
-    const tokenId = 0; // ignored
 
-    await usingApi(async (api) => {
-      // Destroy 11 of 10
-      const tx = api.tx.unique.burnItem(collectionId, tokenId, 11);
-      const badTransaction = async function () {
-        await submitTransactionExpectFailAsync(alice, tx);
-      };
-      await expect(badTransaction()).to.be.rejected;
-
-      // Get alice balance
-      const balance = await getBalance(api, collectionId, alice.address, 0);
-
-      // What to expect
-      expect(balance).to.be.equal(10n);
-    });
+  itSub('Burn more than owned in Fungible collection', async ({helper}) => {
+    const collection = await helper.ft.mintCollection(alice, {}, 0);
+    await collection.mint(alice, 10n);
 
+    await expect(collection.burnTokens(alice, 11n)).to.be.rejectedWith('common.TokenValueTooLow');
+    expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);
   });
-
 });
modifiedtests/src/fungible.test.tsdiffbeforeafterboth
before · tests/src/fungible.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/playgrounds';1920const U128_MAX = (1n << 128n) - 1n;2122describe('integration test: Fungible functionality:', () => {23  let alice: IKeyringPair;24  let bob: IKeyringPair;2526  before(async () => {27    await usingPlaygrounds(async (helper, privateKey) => {28      const donor = privateKey('//Alice');29      [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);30    });31  });3233  itSub('Create fungible collection and token', async ({helper}) => {34    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});35    const defaultTokenId = await collection.getLastTokenId();36    expect(defaultTokenId).to.be.equal(0);3738    await collection.mint(alice, U128_MAX);39    const aliceBalance = await collection.getBalance({Substrate: alice.address});40    const itemCountAfter = await collection.getLastTokenId();4142    expect(itemCountAfter).to.be.equal(defaultTokenId);43    expect(aliceBalance).to.be.equal(U128_MAX);44  });45  46  itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper, privateKey}) => {47    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};48    const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));4950    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5152    await collection.mint(alice, U128_MAX);5354    await collection.transfer(alice, {Substrate: bob.address}, 1000n);55    await collection.transfer(alice, ethAcc, 900n);56    57    for (let i = 0; i < 7; i++) {58      await collection.transfer(alice, facelessCrowd[i], 1n);59    } 6061    const owners = await collection.getTop10Owners();6263    // What to expect64    expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);65    expect(owners.length).to.be.equal(10);66    67    const eleven = privateKey('//ALice+11');68    expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;69    expect((await collection.getTop10Owners()).length).to.be.equal(10);70  });71  72  itSub('Transfer token', async ({helper}) => {73    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};74    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});75    await collection.mint(alice, 500n);7677    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);78    expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;79    expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;8081    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);82    expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);83    expect(await collection.getBalance(ethAcc)).to.be.equal(140n);8485    await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);86  });8788  itSub('Tokens multiple creation', async ({helper}) => {89    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9091    await collection.mintWithOneOwner(alice, [92      {value: 500n},93      {value: 400n},94      {value: 300n},95    ]);9697    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);98  });99100  itSub('Burn some tokens ', async ({helper}) => {101    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});102    await collection.mint(alice, 500n);103104    expect(await collection.isTokenExists(0)).to.be.true;105    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);106    expect(await collection.burnTokens(alice, 499n)).to.be.true;107    expect(await collection.isTokenExists(0)).to.be.true;108    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);109  });110  111  itSub('Burn all tokens ', async ({helper}) => {112    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113    await collection.mint(alice, 500n);114115    expect(await collection.isTokenExists(0)).to.be.true;116    expect(await collection.burnTokens(alice, 500n)).to.be.true;117    expect(await collection.isTokenExists(0)).to.be.true;118119    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);120    expect(await collection.getTotalPieces()).to.be.equal(0n);121  });122123  itSub('Set allowance for token', async ({helper}) => {124    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});125    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};126    await collection.mint(alice, 100n);127128    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);129    130    expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;131    expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);132    expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);133134    expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;135    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);136    expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);137    expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);138139    await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);140141    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);142    expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);143    expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;144    expect(await collection.getBalance(ethAcc)).to.be.equal(10n);145  });146});
after · tests/src/fungible.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/playgrounds';1920const U128_MAX = (1n << 128n) - 1n;2122describe('integration test: Fungible functionality:', () => {23  let alice: IKeyringPair;24  let bob: IKeyringPair;2526  before(async () => {27    await usingPlaygrounds(async (helper, privateKey) => {28      const donor = privateKey('//Alice');29      [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);30    });31  });3233  itSub('Create fungible collection and token', async ({helper}) => {34    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});35    const defaultTokenId = await collection.getLastTokenId();36    expect(defaultTokenId).to.be.equal(0);3738    await collection.mint(alice, U128_MAX);39    const aliceBalance = await collection.getBalance({Substrate: alice.address});40    const itemCountAfter = await collection.getLastTokenId();4142    expect(itemCountAfter).to.be.equal(defaultTokenId);43    expect(aliceBalance).to.be.equal(U128_MAX);44  });45  46  itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper, privateKey}) => {47    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};48    const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));4950    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5152    await collection.mint(alice, U128_MAX);5354    await collection.transfer(alice, {Substrate: bob.address}, 1000n);55    await collection.transfer(alice, ethAcc, 900n);56    57    for (let i = 0; i < 7; i++) {58      await collection.transfer(alice, facelessCrowd[i], 1n);59    } 6061    const owners = await collection.getTop10Owners();6263    // What to expect64    expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);65    expect(owners.length).to.be.equal(10);66    67    const eleven = privateKey('//ALice+11');68    expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;69    expect((await collection.getTop10Owners()).length).to.be.equal(10);70  });71  72  itSub('Transfer token', async ({helper}) => {73    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};74    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});75    await collection.mint(alice, 500n);7677    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);78    expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;79    expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;8081    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);82    expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);83    expect(await collection.getBalance(ethAcc)).to.be.equal(140n);8485    await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);86  });8788  itSub('Tokens multiple creation', async ({helper}) => {89    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9091    await collection.mintWithOneOwner(alice, [92      {value: 500n},93      {value: 400n},94      {value: 300n},95    ]);9697    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);98  });99100  itSub('Burn some tokens ', async ({helper}) => {101    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});102    await collection.mint(alice, 500n);103104    expect(await collection.doesTokenExist(0)).to.be.true;105    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);106    expect(await collection.burnTokens(alice, 499n)).to.be.true;107    expect(await collection.doesTokenExist(0)).to.be.true;108    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);109  });110  111  itSub('Burn all tokens ', async ({helper}) => {112    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113    await collection.mint(alice, 500n);114115    expect(await collection.doesTokenExist(0)).to.be.true;116    expect(await collection.burnTokens(alice, 500n)).to.be.true;117    expect(await collection.doesTokenExist(0)).to.be.true;118119    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);120    expect(await collection.getTotalPieces()).to.be.equal(0n);121  });122123  itSub('Set allowance for token', async ({helper}) => {124    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});125    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};126    await collection.mint(alice, 100n);127128    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);129    130    expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;131    expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);132    expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);133134    expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;135    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);136    expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);137    expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);138139    await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);140141    expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);142    expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);143    expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;144    expect(await collection.getBalance(ethAcc)).to.be.equal(10n);145  });146});
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -122,10 +122,10 @@
   itSub('Burn some pieces', async ({helper}) => {
     const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     const token = await collection.mintToken(alice, 100n);
-    expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
     expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
     expect(await token.burn(alice, 99n)).to.be.true;
-    expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
     expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
   });
 
@@ -133,18 +133,18 @@
     const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     const token = await collection.mintToken(alice, 100n);
     
-    expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
     expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
 
     expect(await token.burn(alice, 100n)).to.be.true;
-    expect(await collection.isTokenExists(token.tokenId)).to.be.false;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
   });
 
   itSub('Burn some pieces for multiple users', async ({helper}) => {
     const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     const token = await collection.mintToken(alice, 100n);
 
-    expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
     
     expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
     expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
@@ -154,17 +154,17 @@
 
     expect(await token.burn(alice, 40n)).to.be.true;
 
-    expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
     expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
 
     expect(await token.burn(bob, 59n)).to.be.true;
 
     expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
-    expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
 
     expect(await token.burn(bob, 1n)).to.be.true;
 
-    expect(await collection.isTokenExists(token.tokenId)).to.be.false;
+    expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
   });
 
   itSub('Set allowance for token', async ({helper}) => {
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -1114,10 +1114,10 @@
    *
    * @param collectionId ID of collection
    * @param tokenId ID of token
-   * @example isTokenExists(10, 20);
+   * @example doesTokenExist(10, 20);
    * @returns true if the token exists, otherwise false
    */
-  async isTokenExists(collectionId: number, tokenId: number): Promise<boolean> {
+  async doesTokenExist(collectionId: number, tokenId: number): Promise<boolean> {
     return (await this.helper.callRpc('api.rpc.unique.tokenExists', [collectionId, tokenId])).toJSON();
   }
 }
@@ -2277,8 +2277,8 @@
     return await this.helper.collection.getLastTokenId(this.collectionId);
   }
 
-  async isTokenExists(tokenId: number) {
-    return await this.helper.collection.isTokenExists(this.collectionId, tokenId);
+  async doesTokenExist(tokenId: number) {
+    return await this.helper.collection.doesTokenExist(this.collectionId, tokenId);
   }
 
   async getAdmins() {
@@ -2607,6 +2607,10 @@
     return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);
   }
 
+  async doesExist() {
+    return await this.collection.doesTokenExist(this.tokenId);
+  }
+
   nestingAccount() {
     return this.collection.helper.util.getTokenAccount(this);
   }