1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util/index.js';1920describe('Refungible: burn', () => {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('can burn some pieces', async ({helper}) => {35 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});36 const token = await collection.mintToken(alice, 100n);37 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;38 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);39 await token.burn(alice, 99n);40 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;41 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);42 });4344 itSub('can burn all pieces', async ({helper}) => {45 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});46 const token = await collection.mintToken(alice, 100n);4748 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;49 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);5051 await token.burn(alice, 100n);52 expect(await collection.doesTokenExist(token.tokenId)).to.be.false;53 });5455 itSub('burn pieces for multiple users', async ({helper}) => {56 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});57 const token = await collection.mintToken(alice, 100n);5859 await token.transfer(alice, {Substrate: bob.address}, 60n);6061 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);62 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);6364 await token.burn(alice, 40n);6566 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;67 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);6869 await token.burn(bob, 59n);7071 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);72 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;7374 await token.burn(bob, 1n);7576 expect(await collection.doesTokenExist(token.tokenId)).to.be.false;77 });7879 itSub('burn pieces by admin', async function({helper}) {80 const collection = await helper.rft.mintCollection(alice);81 await collection.setLimits(alice, {ownerCanTransfer: true});82 await collection.addAdmin(alice, {Substrate: bob.address});83 const token = await collection.mintToken(alice, 100n);8485 await token.burnFrom(bob, {Substrate: alice.address}, 100n);86 expect(await token.doesExist()).to.be.false;87 });88});8990describe('Refungible: burn negative tests', () => {91 let donor: IKeyringPair;92 let alice: IKeyringPair;93 let bob: IKeyringPair;9495 before(async function() {96 await usingPlaygrounds(async (helper, privateKey) => {97 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);98 donor = await privateKey({url: import.meta.url});99 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);100 });101 });102103 itSub('cannot burn non-owned token pieces', async ({helper}) => {104 const collection = await helper.rft.mintCollection(alice);105 const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});106 const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});107108 109 await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');110 await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');111 112 await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');113 await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');114 115 await aliceToken.burn(alice, 0n);116117 118 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);119 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);120121 122 await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);123 await bobToken.transfer(bob, {Substrate: alice.address}, 10n);124 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);125 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);126 });127});