git.delta.rocks / unique-network / refs/commits / 33605551e558

difftreelog

source

js-packages/tests/sub/refungible/repartition.test.ts4.0 KiBsourcehistory
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 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