1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '@unique/test-utils/util.js';1920const MAX_REFUNGIBLE_PIECES = 1_000_000_000_000_000_000_000n;2122describe('integration test: Refungible functionality:', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;25 let bob: IKeyringPair;2627 before(async function() {28 await usingPlaygrounds(async (helper, privateKey) => {29 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3031 donor = await privateKey({url: import.meta.url});32 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);33 });34 });3536 itSub('Create refungible collection and token', async ({helper}) => {37 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});3839 const itemCountBefore = await collection.getLastTokenId();40 const token = await collection.mintToken(alice, 100n);4142 const itemCountAfter = await collection.getLastTokenId();4344 45 expect(token?.tokenId).to.be.gte(itemCountBefore);46 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);47 expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());48 });4950 itSub('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async ({helper}) => {51 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});5253 const token = await collection.mintToken(alice, MAX_REFUNGIBLE_PIECES);5455 expect(await collection.getTokenBalance(token.tokenId, {Substrate: alice.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);5657 await collection.transferToken(alice, token.tokenId, {Substrate: bob.address}, MAX_REFUNGIBLE_PIECES);58 expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);59 expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);6061 await expect(collection.mintToken(alice, MAX_REFUNGIBLE_PIECES + 1n))62 .to.eventually.be.rejectedWith(/refungible\.WrongRefungiblePieces/);63 });6465 itSub('RPC method tokenOwners for refungible collection and token', async ({helper}) => {66 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};67 const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => ({Substrate: keyring.address}));6869 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});7071 const token = await collection.mintToken(alice, 10_000n);7273 await token.transfer(alice, {Substrate: bob.address}, 1000n);74 await token.transfer(alice, ethAcc, 900n);7576 for(let i = 0; i < 7; i++) {77 await token.transfer(alice, facelessCrowd[i], 50n * BigInt(i + 1));78 }7980 const owners = await token.getTop10Owners();8182 83 expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);84 expect(owners.length).to.be.equal(10);8586 const [eleven] = await helper.arrange.createAccounts([0n], donor);87 expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;88 expect((await token.getTop10Owners()).length).to.be.equal(10);89 });9091 itSub('Create multiple tokens', async ({helper}) => {92 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});93 94 95 96 97 98 99 await helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, [100 {pieces: 1n},101 {pieces: 2n},102 {pieces: 100n},103 ]);104 const lastTokenId = await collection.getLastTokenId();105 expect(lastTokenId).to.be.equal(3);106 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);107 });108109 itSub('Set allowance for token', async ({helper}) => {110 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});111 const token = await collection.mintToken(alice, 100n);112113 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);114115 expect(await token.approve(alice, {Substrate: bob.address}, 60n)).to.be.true;116 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);117118 expect(await token.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;119 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);120 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);121 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);122 });123124 itSub('Create new collection with properties', async ({helper}) => {125 const properties = [{key: 'key1', value: 'val1'}];126 const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];127 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});128 const info = await collection.getData();129 expect(info?.raw.properties).to.be.deep.equal(properties);130 expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);131 });132});