git.delta.rocks / unique-network / refs/commits / 79a270aa7ee9

difftreelog

fix serde rpc Fixed method signature `total_pieces`. Before that the number of pieces greater than 2^53 -1 caused an error when calling this method.

PraetorP2022-08-12parent: #e4268af.patch.diff
in: master

7 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -12379,7 +12379,7 @@
 
 [[package]]
 name = "uc-rpc"
-version = "0.1.1"
+version = "0.1.2"
 dependencies = [
  "anyhow",
  "jsonrpsee",
modifiedclient/rpc/CHANGELOG.mddiffbeforeafterboth
--- a/client/rpc/CHANGELOG.md
+++ b/client/rpc/CHANGELOG.md
@@ -2,10 +2,15 @@
 
 All notable changes to this project will be documented in this file.
 
+## [0.1.2] - 2022-08-12
+
+### Fixed
+
+-   Method signature `total_pieces`. Before that the number of pieces greater than 2^53 -1 caused an error when calling this method.
+
 ## [0.1.1] - 2022-07-14
 
 ### Added
 
- - Implementation of RPC method `token_owners` returning 10 owners in no particular order.
-    This was an internal request to improve the web interface and support fractionalization event. 
- 
\ No newline at end of file
+-   Implementation of RPC method `token_owners` returning 10 owners in no particular order.
+    This was an internal request to improve the web interface and support fractionalization event.
modifiedclient/rpc/Cargo.tomldiffbeforeafterboth
--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "uc-rpc"
-version = "0.1.1"
+version = "0.1.2"
 license = "GPLv3"
 edition = "2021"
 
modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -242,7 +242,7 @@
 		collection_id: CollectionId,
 		token_id: TokenId,
 		at: Option<BlockHash>,
-	) -> Result<Option<u128>>;
+	) -> Result<Option<String>>;
 }
 
 mod rmrk_unique_rpc {
@@ -518,7 +518,7 @@
 	pass_method!(collection_stats() -> CollectionStats, unique_api);
 	pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
 	pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);
-	pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);
+	pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<String> => |o| o.map(|number| number.to_string()) , unique_api);
 	pass_method!(token_owners(collection: CollectionId, token: TokenId) -> Vec<CrossAccountId>, unique_api);
 }
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -536,7 +536,7 @@
 		/// Can't transfer tokens to ethereum zero address
 		AddressIsZero,
 
-		/// The oprtation is not supported
+		/// The operation is not supported
 		UnsupportedOperation,
 
 		/// Insufficient funds to perform an action
modifiedtests/CHANGELOG.mddiffbeforeafterboth
--- a/tests/CHANGELOG.md
+++ b/tests/CHANGELOG.md
@@ -2,10 +2,15 @@
 
 All notable changes to this project will be documented in this file.
 
+## 2022-08-12
+
+### Added
+
+-   In integration tests for `RFT` added check of work with the maximum allowable number of pieces (MAX_REFUNGIBLE_PIECES).
+
 ## 2022-07-14
 
 ### Added
- - Integrintegration tests of RPC method `token_owners`.
- - Integrintegration tests of Fungible Pallet.
-  
- 
\ No newline at end of file
+
+-   Integrintegration tests of RPC method `token_owners`.
+-   Integrintegration tests of Fungible Pallet.
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;3334describe('integration test: Refungible functionality:', async () => {35  before(async function() {36    await requirePallets(this, [Pallets.ReFungible]);3738    await usingPlaygrounds(async (helper, privateKey) => {39      alice = privateKey('//Alice');40      bob = privateKey('//Bob');41      if (!getModuleNames(helper.api!).includes(Pallets.ReFungible)) this.skip();42    });43  });44  45  it('Create refungible collection and token', async () => {46    await usingPlaygrounds(async helper => {47      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});4849      const itemCountBefore = await collection.getLastTokenId();50      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);51      52      const itemCountAfter = await collection.getLastTokenId();53      54      // What to expect55      expect(token?.tokenId).to.be.gte(itemCountBefore);56      expect(itemCountAfter).to.be.equal(itemCountBefore + 1);57      expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());58    });59  });60  61  it('RPC method tokenOnewrs for refungible collection and token', async () => {62    await usingPlaygrounds(async (helper, privateKey) => {63      const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};64      const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));6566      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});6768      const token = await collection.mintToken(alice, {Substrate: alice.address}, 10_000n);6970      await token.transfer(alice, {Substrate: bob.address}, 1000n);71      await token.transfer(alice, ethAcc, 900n);72      73      for (let i = 0; i < 7; i++) {74        await token.transfer(alice, facelessCrowd[i], 50n * BigInt(i + 1));75      } 7677      const owners = await token.getTop10Owners();7879      // What to expect80      expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);81      expect(owners.length).to.be.equal(10);82      83      const eleven = privateKey('//ALice+11');84      expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;85      expect((await token.getTop10Owners()).length).to.be.equal(10);86    });87  });88  89  it('Transfer token pieces', async () => {90    await usingPlaygrounds(async helper => {91      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});92      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);9394      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);95      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;96      97      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);98      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);99      100      await expect(token.transfer(alice, {Substrate: bob.address}, 41n)).to.eventually.be.rejected;101    });102  });103104  it('Create multiple tokens', async () => {105    await usingPlaygrounds(async helper => {106      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});107      // TODO: fix mintMultipleTokens108      // await collection.mintMultipleTokens(alice, [109      //   {owner: {Substrate: alice.address}, pieces: 1n},110      //   {owner: {Substrate: alice.address}, pieces: 2n},111      //   {owner: {Substrate: alice.address}, pieces: 100n},112      // ]);113      await helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, [114        {pieces: 1n}, 115        {pieces: 2n}, 116        {pieces: 100n},117      ]);118      const lastTokenId = await collection.getLastTokenId();119      expect(lastTokenId).to.be.equal(3);120      expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);121    });122  });123124  it('Burn some pieces', async () => {125    await usingPlaygrounds(async helper => {126      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});127      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);128      expect(await collection.isTokenExists(token.tokenId)).to.be.true;129      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);130      expect((await token.burn(alice, 99n)).success).to.be.true;131      expect(await collection.isTokenExists(token.tokenId)).to.be.true;132      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);133    });134  });135136  it('Burn all pieces', async () => {137    await usingPlaygrounds(async helper => {   138      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});139      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);140      141      expect(await collection.isTokenExists(token.tokenId)).to.be.true;142      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);143144      expect((await token.burn(alice, 100n)).success).to.be.true;145      expect(await collection.isTokenExists(token.tokenId)).to.be.false;146    });147  });148149  it('Burn some pieces for multiple users', async () => {150    await usingPlaygrounds(async helper => {151      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});152      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);153154      expect(await collection.isTokenExists(token.tokenId)).to.be.true;155      156      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);157      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;158159      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);160      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);161162      expect((await token.burn(alice, 40n)).success).to.be.true;163164      expect(await collection.isTokenExists(token.tokenId)).to.be.true;165      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);166167      expect((await token.burn(bob, 59n)).success).to.be.true;168169      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);170      expect(await collection.isTokenExists(token.tokenId)).to.be.true;171172      expect((await token.burn(bob, 1n)).success).to.be.true;173174      expect(await collection.isTokenExists(token.tokenId)).to.be.false;175    });176  });177178  it('Set allowance for token', async () => {179    await usingPlaygrounds(async helper => {180      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});181      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);182      183      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);184185      expect(await token.approve(alice, {Substrate: bob.address}, 60n)).to.be.true;186      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);187188      expect(await token.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;189      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);190      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);191      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);192    });193  });194195  it('Repartition', 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);199200      expect(await token.repartition(alice, 200n)).to.be.true;201      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);202      expect(await token.getTotalPieces()).to.be.equal(200n);203      204      expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;205      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);206      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);207      208      await expect(token.repartition(alice, 80n)).to.eventually.be.rejected;209      210      expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;211      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);212      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);213214      expect(await token.repartition(bob, 150n)).to.be.true;215      await expect(token.transfer(bob, {Substrate: alice.address}, 160n)).to.eventually.be.rejected;216217    });218  });219220  it('Repartition with increased amount', async () => {221    await usingPlaygrounds(async helper => {222      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});223      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);224      await token.repartition(alice, 200n);225      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);226      expect(chainEvents).to.include.deep.members([{227        method: 'ItemCreated',228        section: 'common',229        index: '0x4202',230        data: [ 231          collection.collectionId.toString(), 232          token.tokenId.toString(), 233          {Substrate: alice.address}, 234          '100',235        ],236      }]);237    });238  });239240  it('Repartition with decreased amount', async () => {241    await usingPlaygrounds(async helper => {242      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});243      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);244      await token.repartition(alice, 50n);245      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);246      expect(chainEvents).to.include.deep.members([{247        method: 'ItemDestroyed',248        section: 'common',249        index: '0x4203',250        data: [ 251          collection.collectionId.toString(), 252          token.tokenId.toString(), 253          {Substrate: alice.address}, 254          '50',255        ],256      }]);257    });258  });259  260  it('Create new collection with properties', async () => {261    await usingPlaygrounds(async helper => {262      const properties = [{key: 'key1', value: 'val1'}];263      const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];264      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});265      const info = await collection.getData();266      expect(info?.raw.properties).to.be.deep.equal(properties);267      expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);268    });269  });270});271
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          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