git.delta.rocks / unique-network / refs/commits / 1dbc03134213

difftreelog

Fix tests

Max Andreev2022-09-08parent: #048106f.patch.diff
in: master
Add waiter function
Remove global before script
Remove useless logs
Fix refungible tests

3 files changed

modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -28,6 +28,7 @@
 import {encodeAddress} from '@polkadot/util-crypto';
 import {stringToU8a} from '@polkadot/util';
 import {SponsoringMode, contractHelpers, createEthAccountWithBalance, deployFlipper, itWeb3, transferBalanceToEth} from './eth/util/helpers';
+import {DevUniqueHelper} from './util/playgrounds/unique.dev';
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
@@ -40,9 +41,9 @@
 const UNLOCKING_PERIOD = 10n; // 20 blocks of parachain
 const rewardAvailableInBlock = (stakedInBlock: bigint) => (stakedInBlock - stakedInBlock % LOCKING_PERIOD) + (LOCKING_PERIOD * 2n);
 
-before(async function () {
+const beforeEach = async (context: Mocha.Context) => {
   await usingPlaygrounds(async (helper, privateKey) => {
-    if (!getModuleNames(helper.api!).includes(Pallets.AppPromotion)) this.skip();
+    if (!getModuleNames(helper.api!).includes(Pallets.AppPromotion)) context.skip();
     alice = privateKey('//Alice');
     palletAdmin = privateKey('//Charlie'); // TODO use custom address
     await helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
@@ -51,9 +52,13 @@
     await helper.balance.transferToSubstrate(alice, palletAddress, 1000n * nominal);
     accounts = await helper.arrange.createCrowd(100, 1000n, alice); // create accounts-pool to speed up tests
   });
-});
+};
 
 describe('app-promotions.stake extrinsic', () => {
+  before(async function () {
+    await beforeEach(this);
+  });
+
   it('should "lock" staking balance, add it to "staked" map, and increase "totalStaked" amount', async () => {
     await usingPlaygrounds(async (helper) => {
       const [staker, recepient] = [accounts.pop()!, accounts.pop()!];
@@ -128,6 +133,10 @@
 });
 
 describe('unstake balance extrinsic', () => {  
+  before(async function () {
+    await beforeEach(this);
+  });
+
   it('should change balance state from "frozen" to "reserved", add it to "pendingUnstake" map, and subtract it from totalStaked', async () => {
     await usingPlaygrounds(async helper => {
       const [staker, recepient] = [accounts.pop()!, accounts.pop()!];
@@ -247,6 +256,10 @@
 });
 
 describe('Admin adress', () => {
+  before(async function () {
+    await beforeEach(this);
+  });
+
   it('can be set by sudo only', async () => {
     await usingPlaygrounds(async (helper) => {
       const nonAdmin = accounts.pop()!;
@@ -291,6 +304,7 @@
 
 describe('App-promotion collection sponsoring', () => {
   before(async function () {
+    await beforeEach(this);
     await usingPlaygrounds(async (helper) => {
       const tx = helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));
       await helper.signTransaction(alice, tx);
@@ -394,6 +408,10 @@
 });
 
 describe('app-promotion stopSponsoringCollection', () => {
+  before(async function () {
+    await beforeEach(this);
+  });
+
   it('can not be called by non-admin', async () => {    
     await usingPlaygrounds(async (helper) => {
       const [collectionOwner, nonAdmin] = [accounts.pop()!, accounts.pop()!];
@@ -450,6 +468,10 @@
 });
 
 describe('app-promotion contract sponsoring', () => {
+  before(async function () {
+    await beforeEach(this);
+  });
+
   itWeb3('should set palletes address as a sponsor', async ({api, web3, privateKeyWrapper}) => {
     await usingPlaygrounds(async (helper) => {
       const contractOwner = (await createEthAccountWithBalance(api, web3, privateKeyWrapper)).toLowerCase();
@@ -570,6 +592,10 @@
 });
 
 describe('app-promotion stopSponsoringContract', () => {  
+  before(async function () {
+    await beforeEach(this);
+  });
+
   itWeb3('should remove pallet address from contract sponsors', async ({api, web3, privateKeyWrapper}) => {
     await usingPlaygrounds(async (helper) => {      
       const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
@@ -624,6 +650,10 @@
 });
 
 describe('app-promotion rewards', () => {
+  before(async function () {
+    await beforeEach(this);
+  });
+
   it('can not be called by non admin', async () => {
     await usingPlaygrounds(async (helper) => {
       const nonAdmin = accounts.pop()!;
@@ -634,11 +664,13 @@
   it('should credit 0.05% for staking period', async () => {    
     await usingPlaygrounds(async helper => {
       const staker = accounts.pop()!;
+
+      await waitPromotionPeriodDoesntEnd(helper);
       
       await helper.staking.stake(staker, 100n * nominal);
       await helper.staking.stake(staker, 200n * nominal);
 
-      // wair rewards are available:
+      // wait rewards are available:
       const stakedInBlock = (await helper.staking.getTotalStakedPerBlock({Substrate: staker.address}))[1][0];
       await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stakedInBlock));
 
@@ -688,7 +720,6 @@
   });
   
   it('should bring compound interest', async () => {
-    // TODO flaky test
     await usingPlaygrounds(async helper => {
       const staker = accounts.pop()!;
             
@@ -756,3 +787,14 @@
     return calculateIncome(income, calcPeriod, iter - 1);
   } else return income;
 }
+
+// Wait while promotion period less than specified block, to avoid boundary cases
+// 0 if this should be the beginning of the period.
+async function waitPromotionPeriodDoesntEnd(helper: DevUniqueHelper, waitBlockLessThan = LOCKING_PERIOD / 3n) {
+  const relayBlockNumber = (await helper.api!.query.parachainSystem.validationData()).value.relayParentNumber.toNumber(); // await helper.chain.getLatestBlockNumber();
+  const currentPeriodBlock = BigInt(relayBlockNumber) % LOCKING_PERIOD;
+
+  if (currentPeriodBlock > waitBlockLessThan) {
+    await helper.wait.forRelayBlockNumber(BigInt(relayBlockNumber) + LOCKING_PERIOD - currentPeriodBlock);
+  }
+}
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
before · tests/src/refungible.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';1819import {usingPlaygrounds} from './util/playgrounds';20import {21  getModuleNames,22  Pallets,23  requirePallets,24} from './util/helpers';2526import chai from 'chai';27import chaiAsPromised from 'chai-as-promised';28chai.use(chaiAsPromised);29const expect = chai.expect;3031let alice: IKeyringPair;32let bob: IKeyringPair;33const MAX_REFUNGIBLE_PIECES = 1_000_000_000_000_000_000_000n;3435describe('integration test: Refungible functionality:', async () => {36  before(async function() {37    await requirePallets(this, [Pallets.ReFungible]);3839    await usingPlaygrounds(async (helper, privateKey) => {40      alice = privateKey('//Alice');41      bob = privateKey('//Bob');42      if (!getModuleNames(helper.api!).includes(Pallets.ReFungible)) this.skip();43    });44  });45  46  it('Create refungible collection and token', async () => {47    await usingPlaygrounds(async helper => {48      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});4950      const itemCountBefore = await collection.getLastTokenId();51      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);52      53      const itemCountAfter = await collection.getLastTokenId();54      55      // What to expect56      expect(token?.tokenId).to.be.gte(itemCountBefore);57      expect(itemCountAfter).to.be.equal(itemCountBefore + 1);58      expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());59    });60  });61  62  it('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async () => {63    await usingPlaygrounds(async helper => {64      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});65      66      const token = await collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES);67      68      expect(await collection.getTokenBalance(token.tokenId, {Substrate: alice.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);69      70      await collection.transferToken(alice, token.tokenId, {Substrate: bob.address}, MAX_REFUNGIBLE_PIECES);71      expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);72      expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);73      74      await expect(collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES + 1n)).to.eventually.be.rejected;75    });76  });77  78  it('RPC method tokenOnewrs for refungible collection and token', async () => {79    await usingPlaygrounds(async (helper, privateKey) => {80      const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};81      const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));8283      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8485      const token = await collection.mintToken(alice, {Substrate: alice.address}, 10_000n);8687      await token.transfer(alice, {Substrate: bob.address}, 1000n);88      await token.transfer(alice, ethAcc, 900n);89      90      for (let i = 0; i < 7; i++) {91        await token.transfer(alice, facelessCrowd[i], 50n * BigInt(i + 1));92      } 9394      const owners = await token.getTop10Owners();9596      // What to expect97      expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);98      expect(owners.length).to.be.equal(10);99      100      const eleven = privateKey('//ALice+11');101      expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;102      expect((await token.getTop10Owners()).length).to.be.equal(10);103    });104  });105  106  it('Transfer token pieces', async () => {107    await usingPlaygrounds(async helper => {108      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});109      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);110111      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);112      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;113      114      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);115      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);116      117      await expect(token.transfer(alice, {Substrate: bob.address}, 41n)).to.eventually.be.rejected;118    });119  });120121  it('Create multiple tokens', async () => {122    await usingPlaygrounds(async helper => {123      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});124      // TODO: fix mintMultipleTokens125      // await collection.mintMultipleTokens(alice, [126      //   {owner: {Substrate: alice.address}, pieces: 1n},127      //   {owner: {Substrate: alice.address}, pieces: 2n},128      //   {owner: {Substrate: alice.address}, pieces: 100n},129      // ]);130      await helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, [131        {pieces: 1n}, 132        {pieces: 2n}, 133        {pieces: 100n},134      ]);135      const lastTokenId = await collection.getLastTokenId();136      expect(lastTokenId).to.be.equal(3);137      expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);138    });139  });140141  it('Burn some pieces', async () => {142    await usingPlaygrounds(async helper => {143      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});144      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);145      expect(await collection.isTokenExists(token.tokenId)).to.be.true;146      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);147      expect((await token.burn(alice, 99n)).success).to.be.true;148      expect(await collection.isTokenExists(token.tokenId)).to.be.true;149      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);150    });151  });152153  it('Burn all pieces', async () => {154    await usingPlaygrounds(async helper => {   155      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});156      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);157      158      expect(await collection.isTokenExists(token.tokenId)).to.be.true;159      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);160161      expect((await token.burn(alice, 100n)).success).to.be.true;162      expect(await collection.isTokenExists(token.tokenId)).to.be.false;163    });164  });165166  it('Burn some pieces for multiple users', async () => {167    await usingPlaygrounds(async helper => {168      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});169      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);170171      expect(await collection.isTokenExists(token.tokenId)).to.be.true;172      173      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);174      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;175176      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);177      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);178179      expect((await token.burn(alice, 40n)).success).to.be.true;180181      expect(await collection.isTokenExists(token.tokenId)).to.be.true;182      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);183184      expect((await token.burn(bob, 59n)).success).to.be.true;185186      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);187      expect(await collection.isTokenExists(token.tokenId)).to.be.true;188189      expect((await token.burn(bob, 1n)).success).to.be.true;190191      expect(await collection.isTokenExists(token.tokenId)).to.be.false;192    });193  });194195  it('Set allowance for token', async () => {196    await usingPlaygrounds(async helper => {197      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});198      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);199      200      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);201202      expect(await token.approve(alice, {Substrate: bob.address}, 60n)).to.be.true;203      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);204205      expect(await token.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;206      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);207      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);208      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);209    });210  });211212  it('Repartition', async () => {213    await usingPlaygrounds(async helper => {214      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});215      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);216217      expect(await token.repartition(alice, 200n)).to.be.true;218      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);219      expect(await token.getTotalPieces()).to.be.equal(200n);220      221      expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;222      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);223      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);224      225      await expect(token.repartition(alice, 80n)).to.eventually.be.rejected;226      227      expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;228      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);229      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);230231      expect(await token.repartition(bob, 150n)).to.be.true;232      await expect(token.transfer(bob, {Substrate: alice.address}, 160n)).to.eventually.be.rejected;233234    });235  });236237  it('Repartition with increased amount', async () => {238    await usingPlaygrounds(async helper => {239      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});240      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);241      await token.repartition(alice, 200n);242      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);243      expect(chainEvents).to.include.deep.members([{244        method: 'ItemCreated',245        section: 'common',246        index: '0x4202',247        data: [ 248          collection.collectionId.toString(), 249          token.tokenId.toString(), 250          {Substrate: alice.address}, 251          '100',252        ],253      }]);254    });255  });256257  it('Repartition with decreased amount', async () => {258    await usingPlaygrounds(async helper => {259      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});260      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);261      await token.repartition(alice, 50n);262      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);263      expect(chainEvents).to.include.deep.members([{264        method: 'ItemDestroyed',265        section: 'common',266        index: '0x4203',267        data: [ 268          collection.collectionId.toString(), 269          token.tokenId.toString(), 270          {Substrate: alice.address}, 271          '50',272        ],273      }]);274    });275  });276  277  it('Create new collection with properties', async () => {278    await usingPlaygrounds(async helper => {279      const properties = [{key: 'key1', value: 'val1'}];280      const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];281      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});282      const info = await collection.getData();283      expect(info?.raw.properties).to.be.deep.equal(properties);284      expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);285    });286  });287});288
after · tests/src/refungible.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';1819import {usingPlaygrounds} from './util/playgrounds';20import {21  getModuleNames,22  Pallets,23  requirePallets,24} from './util/helpers';2526import chai from 'chai';27import chaiAsPromised from 'chai-as-promised';28chai.use(chaiAsPromised);29const expect = chai.expect;3031let alice: IKeyringPair;32let bob: IKeyringPair;33const MAX_REFUNGIBLE_PIECES = 1_000_000_000_000_000_000_000n;3435describe('integration test: Refungible functionality:', async () => {36  before(async function() {37    await requirePallets(this, [Pallets.ReFungible]);3839    await usingPlaygrounds(async (helper, privateKey) => {40      alice = privateKey('//Alice');41      bob = privateKey('//Bob');42      if (!getModuleNames(helper.api!).includes(Pallets.ReFungible)) this.skip();43    });44  });45  46  it('Create refungible collection and token', async () => {47    await usingPlaygrounds(async helper => {48      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});4950      const itemCountBefore = await collection.getLastTokenId();51      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);52      53      const itemCountAfter = await collection.getLastTokenId();54      55      // What to expect56      expect(token?.tokenId).to.be.gte(itemCountBefore);57      expect(itemCountAfter).to.be.equal(itemCountBefore + 1);58      expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());59    });60  });61  62  it('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async () => {63    await usingPlaygrounds(async helper => {64      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});65      66      const token = await collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES);67      68      expect(await collection.getTokenBalance(token.tokenId, {Substrate: alice.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);69      70      await collection.transferToken(alice, token.tokenId, {Substrate: bob.address}, MAX_REFUNGIBLE_PIECES);71      expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);72      expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);73      74      await expect(collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES + 1n)).to.eventually.be.rejected;75    });76  });77  78  it('RPC method tokenOnewrs for refungible collection and token', async () => {79    await usingPlaygrounds(async (helper, privateKey) => {80      const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};81      const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));8283      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8485      const token = await collection.mintToken(alice, {Substrate: alice.address}, 10_000n);8687      await token.transfer(alice, {Substrate: bob.address}, 1000n);88      await token.transfer(alice, ethAcc, 900n);89      90      for (let i = 0; i < 7; i++) {91        await token.transfer(alice, facelessCrowd[i], 50n * BigInt(i + 1));92      } 9394      const owners = await token.getTop10Owners();9596      // What to expect97      expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);98      expect(owners.length).to.be.equal(10);99      100      const eleven = privateKey('//ALice+11');101      expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;102      expect((await token.getTop10Owners()).length).to.be.equal(10);103    });104  });105  106  it('Transfer token pieces', async () => {107    await usingPlaygrounds(async helper => {108      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});109      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);110111      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);112      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;113      114      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);115      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);116      117      await expect(token.transfer(alice, {Substrate: bob.address}, 41n)).to.eventually.be.rejected;118    });119  });120121  it('Create multiple tokens', async () => {122    await usingPlaygrounds(async helper => {123      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});124      // TODO: fix mintMultipleTokens125      // await collection.mintMultipleTokens(alice, [126      //   {owner: {Substrate: alice.address}, pieces: 1n},127      //   {owner: {Substrate: alice.address}, pieces: 2n},128      //   {owner: {Substrate: alice.address}, pieces: 100n},129      // ]);130      await helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, [131        {pieces: 1n}, 132        {pieces: 2n}, 133        {pieces: 100n},134      ]);135      const lastTokenId = await collection.getLastTokenId();136      expect(lastTokenId).to.be.equal(3);137      expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);138    });139  });140141  it('Burn some pieces', async () => {142    await usingPlaygrounds(async helper => {143      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});144      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);145      expect(await collection.isTokenExists(token.tokenId)).to.be.true;146      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);147      expect((await token.burn(alice, 99n)).success).to.be.true;148      expect(await collection.isTokenExists(token.tokenId)).to.be.true;149      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);150    });151  });152153  it('Burn all pieces', async () => {154    await usingPlaygrounds(async helper => {   155      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});156      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);157      158      expect(await collection.isTokenExists(token.tokenId)).to.be.true;159      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);160161      expect((await token.burn(alice, 100n)).success).to.be.true;162      expect(await collection.isTokenExists(token.tokenId)).to.be.false;163    });164  });165166  it('Burn some pieces for multiple users', async () => {167    await usingPlaygrounds(async helper => {168      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});169      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);170171      expect(await collection.isTokenExists(token.tokenId)).to.be.true;172      173      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);174      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;175176      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);177      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);178179      expect((await token.burn(alice, 40n)).success).to.be.true;180181      expect(await collection.isTokenExists(token.tokenId)).to.be.true;182      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);183184      expect((await token.burn(bob, 59n)).success).to.be.true;185186      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);187      expect(await collection.isTokenExists(token.tokenId)).to.be.true;188189      expect((await token.burn(bob, 1n)).success).to.be.true;190191      expect(await collection.isTokenExists(token.tokenId)).to.be.false;192    });193  });194195  it('Set allowance for token', async () => {196    await usingPlaygrounds(async helper => {197      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});198      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);199      200      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);201202      expect(await token.approve(alice, {Substrate: bob.address}, 60n)).to.be.true;203      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);204205      expect(await token.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;206      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);207      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);208      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);209    });210  });211212  it('Repartition', async () => {213    await usingPlaygrounds(async helper => {214      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});215      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);216217      expect(await token.repartition(alice, 200n)).to.be.true;218      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);219      expect(await token.getTotalPieces()).to.be.equal(200n);220      221      expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;222      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);223      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);224      225      await expect(token.repartition(alice, 80n)).to.eventually.be.rejected;226      227      expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;228      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);229      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);230231      expect(await token.repartition(bob, 150n)).to.be.true;232      await expect(token.transfer(bob, {Substrate: alice.address}, 160n)).to.eventually.be.rejected;233234    });235  });236237  it('Repartition with increased amount', async () => {238    await usingPlaygrounds(async helper => {239      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});240      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);241      await token.repartition(alice, 200n);242      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);243      expect(chainEvents).to.include.deep.members([{244        method: 'ItemCreated',245        section: 'common',246        index: '0x4202',247        data: [ 248          helper.api!.createType('u32', collection.collectionId).toHuman(), 249          helper.api!.createType('u32', token.tokenId).toHuman(),250          {Substrate: alice.address}, 251          '100',252        ],253      }]);254    });255  });256257  it('Repartition with decreased amount', async () => {258    await usingPlaygrounds(async helper => {259      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});260      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);261      await token.repartition(alice, 50n);262      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);263      expect(chainEvents).to.include.deep.members([{264        method: 'ItemDestroyed',265        section: 'common',266        index: '0x4203',267        data: [ 268          helper.api!.createType('u32', collection.collectionId).toHuman(), 269          helper.api!.createType('u32', token.tokenId).toHuman(),270          {Substrate: alice.address}, 271          '50',272        ],273      }]);274    });275  });276  277  it('Create new collection with properties', async () => {278    await usingPlaygrounds(async helper => {279      const properties = [{key: 'key1', value: 'val1'}];280      const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];281      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});282      const info = await collection.getData();283      expect(info?.raw.properties).to.be.deep.equal(properties);284      expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);285    });286  });287});288
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -35,7 +35,7 @@
       for (const arg of args) {
         if (typeof arg !== 'string')
           continue;
-        if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis: UniqueApi/2, RmrkApi/1') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
+        if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
           return;
       }
       printer(...args);