1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '@unique/test-utils/util.js';1920describe('integration test: Refungible functionality:', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async function() {26 await usingPlaygrounds(async (helper, privateKey) => {27 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2829 donor = await privateKey({url: import.meta.url});30 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);31 });32 });3334 itSub('Repartition', async ({helper}) => {35 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});36 const token = await collection.mintToken(alice, 100n);3738 expect(await token.repartition(alice, 200n)).to.be.true;39 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);40 expect(await token.getTotalPieces()).to.be.equal(200n);4142 expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;43 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);44 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);4546 await expect(token.repartition(alice, 80n))47 .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);4849 expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;50 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);51 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);5253 expect(await token.repartition(bob, 150n)).to.be.true;54 await expect(token.transfer(bob, {Substrate: alice.address}, 160n))55 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);56 });5758 itSub('Repartition with increased amount', async ({helper}) => {59 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});60 const token = await collection.mintToken(alice, 100n);61 await token.repartition(alice, 200n);62 const chainEvents = helper.chainLog.slice(-1)[0].events;63 const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');64 expect(event).to.deep.include({65 section: 'common',66 method: 'ItemCreated',67 index: [66, 2],68 data: [69 collection.collectionId,70 token.tokenId,71 {substrate: alice.address},72 100n,73 ],74 });75 });7677 itSub('Repartition with decreased amount', async ({helper}) => {78 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});79 const token = await collection.mintToken(alice, 100n);80 await token.repartition(alice, 50n);81 const chainEvents = helper.chainLog.slice(-1)[0].events;82 const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');83 expect(event).to.deep.include({84 section: 'common',85 method: 'ItemDestroyed',86 index: [66, 3],87 data: [88 collection.collectionId,89 token.tokenId,90 {substrate: alice.address},91 50n,92 ],93 });94 });95});96