1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from './util';192021describe('integration test: ext. burnItem():', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;24 let bob: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);30 });31 });3233 itSub('Burn item in NFT collection', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice);35 const token = await collection.mintToken(alice);3637 await token.burn(alice);38 expect(await token.doesExist()).to.be.false;39 });4041 itSub('Burn item in Fungible collection', async ({helper}) => {42 const collection = await helper.ft.mintCollection(alice, {}, 10);43 await collection.mint(alice, 10n);4445 await collection.burnTokens(alice, 1n);46 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);47 });4849 itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {50 const collection = await helper.rft.mintCollection(alice);51 const token = await collection.mintToken(alice, 100n);5253 await token.burn(alice, 90n);54 expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);5556 await token.burn(alice, 10n);57 expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);58 });5960 itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {61 const collection = await helper.rft.mintCollection(alice);62 const token = await collection.mintToken(alice, 100n);6364 await token.transfer(alice, {Substrate: bob.address}, 1n);6566 expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);67 expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);6869 await token.burn(bob, 1n);7071 expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);72 expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);73 });74});7576describe('integration test: ext. burnItem() with admin permissions:', () => {77 let donor: IKeyringPair;78 let alice: IKeyringPair;79 let bob: IKeyringPair;8081 before(async () => {82 await usingPlaygrounds(async (helper, privateKey) => {83 donor = await privateKey({filename: __filename});84 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);85 });86 });8788 itSub('Burn item in NFT collection', async ({helper}) => {89 const collection = await helper.nft.mintCollection(alice);90 await collection.setLimits(alice, {ownerCanTransfer: true});91 await collection.addAdmin(alice, {Substrate: bob.address});92 const token = await collection.mintToken(alice);9394 await token.burnFrom(bob, {Substrate: alice.address});95 expect(await token.doesExist()).to.be.false;96 });9798 itSub('Burn item in Fungible collection', async ({helper}) => {99 const collection = await helper.ft.mintCollection(alice, {}, 0);100 await collection.setLimits(alice, {ownerCanTransfer: true});101 await collection.addAdmin(alice, {Substrate: bob.address});102 await collection.mint(alice, 10n);103104 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);105 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);106 });107108 itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {109 const collection = await helper.rft.mintCollection(alice);110 await collection.setLimits(alice, {ownerCanTransfer: true});111 await collection.addAdmin(alice, {Substrate: bob.address});112 const token = await collection.mintToken(alice, 100n);113114 await token.burnFrom(bob, {Substrate: alice.address}, 100n);115 expect(await token.doesExist()).to.be.false;116 });117});118119describe('Negative integration test: ext. burnItem():', () => {120 let donor: IKeyringPair;121 let alice: IKeyringPair;122 let bob: IKeyringPair;123124 before(async () => {125 await usingPlaygrounds(async (helper, privateKey) => {126 donor = await privateKey({filename: __filename});127 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);128 });129 });130131 itSub('Burn a token that was never created', async ({helper}) => {132 const collection = await helper.nft.mintCollection(alice);133 await expect(collection.burnToken(alice, 10)).to.be.rejectedWith('common.TokenNotFound');134 });135136 itSub('Burn a token using the address that does not own it', async ({helper}) => {137 const collection = await helper.nft.mintCollection(alice);138 const token = await collection.mintToken(alice);139140 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');141 });142143 itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {144 const collection = await helper.rft.mintCollection(alice);145 const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});146 const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});147148 149 await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');150 await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');151 152 await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');153 await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');154 155 await aliceToken.burn(alice, 0n);156157 158 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);159 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);160161 162 await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);163 await bobToken.transfer(bob, {Substrate: alice.address}, 10n);164 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);165 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);166 });167168 itSub('Transfer a burned token', async ({helper}) => {169 const collection = await helper.nft.mintCollection(alice);170 const token = await collection.mintToken(alice);171 await token.burn(alice);172173 await expect(token.transfer(alice, {Substrate: bob.address})).to.be.rejectedWith('common.TokenNotFound');174 });175176 itSub('Burn more than owned in Fungible collection', async ({helper}) => {177 const collection = await helper.ft.mintCollection(alice, {}, 0);178 await collection.mint(alice, 10n);179180 await expect(collection.burnTokens(alice, 11n)).to.be.rejectedWith('common.TokenValueTooLow');181 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);182 });183});