1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, U128_MAX} from './util/playgrounds';1920describe('integration test: Fungible functionality:', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = privateKey('//Alice');27 [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);28 });29 });3031 itSub('Create fungible collection and token', async ({helper}) => {32 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});33 const defaultTokenId = await collection.getLastTokenId();34 expect(defaultTokenId).to.be.equal(0);3536 await collection.mint(alice, U128_MAX);37 const aliceBalance = await collection.getBalance({Substrate: alice.address});38 const itemCountAfter = await collection.getLastTokenId();3940 expect(itemCountAfter).to.be.equal(defaultTokenId);41 expect(aliceBalance).to.be.equal(U128_MAX);42 });43 44 itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper, privateKey}) => {45 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};46 const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));4748 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});4950 await collection.mint(alice, U128_MAX);5152 await collection.transfer(alice, {Substrate: bob.address}, 1000n);53 await collection.transfer(alice, ethAcc, 900n);54 55 for (let i = 0; i < 7; i++) {56 await collection.transfer(alice, facelessCrowd[i], 1n);57 } 5859 const owners = await collection.getTop10Owners();6061 62 expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);63 expect(owners.length).to.be.equal(10);64 65 const eleven = privateKey('//ALice+11');66 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;67 expect((await collection.getTop10Owners()).length).to.be.equal(10);68 });69 70 itSub('Transfer token', async ({helper}) => {71 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};72 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});73 await collection.mint(alice, 500n);7475 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);76 expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;77 expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;7879 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);80 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);81 expect(await collection.getBalance(ethAcc)).to.be.equal(140n);8283 await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);84 });8586 itSub('Tokens multiple creation', async ({helper}) => {87 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8889 await collection.mintWithOneOwner(alice, [90 {value: 500n},91 {value: 400n},92 {value: 300n},93 ]);9495 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);96 });9798 itSub('Burn some tokens ', async ({helper}) => {99 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});100 await collection.mint(alice, 500n);101102 expect(await collection.isTokenExists(0)).to.be.true;103 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);104 expect(await collection.burnTokens(alice, 499n)).to.be.true;105 expect(await collection.isTokenExists(0)).to.be.true;106 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);107 });108 109 itSub('Burn all tokens ', async ({helper}) => {110 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});111 await collection.mint(alice, 500n);112113 expect(await collection.isTokenExists(0)).to.be.true;114 expect(await collection.burnTokens(alice, 500n)).to.be.true;115 expect(await collection.isTokenExists(0)).to.be.true;116117 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);118 expect(await collection.getTotalPieces()).to.be.equal(0n);119 });120121 itSub('Set allowance for token', async ({helper}) => {122 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});123 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};124 await collection.mint(alice, 100n);125126 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);127 128 expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;129 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);130 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);131132 expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;133 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);134 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);135 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);136137 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);138139 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);140 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);141 expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;142 expect(await collection.getBalance(ethAcc)).to.be.equal(10n);143 });144});