1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from './util';192021describe('integration test: ext. burnItem():', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 donor = await privateKey({url: import.meta.url});28 [alice] = await helper.arrange.createAccounts([100n], donor);29 });30 });3132 itSub('Burn item in NFT collection', async ({helper}) => {33 const collection = await helper.nft.mintCollection(alice);34 const token = await collection.mintToken(alice);3536 await token.burn(alice);37 expect(await token.doesExist()).to.be.false;38 });3940 itSub('Burn item in Fungible collection', async ({helper}) => {41 const collection = await helper.ft.mintCollection(alice, {}, 10);42 await collection.mint(alice, 10n);4344 await collection.burnTokens(alice, 1n);45 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);46 });47});4849describe('integration test: ext. burnItem() with admin permissions:', () => {50 let donor: IKeyringPair;51 let alice: IKeyringPair;52 let bob: IKeyringPair;5354 before(async () => {55 await usingPlaygrounds(async (helper, privateKey) => {56 donor = await privateKey({url: import.meta.url});57 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);58 });59 });6061 itSub('Burn item in NFT collection', async ({helper}) => {62 const collection = await helper.nft.mintCollection(alice);63 await collection.setLimits(alice, {ownerCanTransfer: true});64 await collection.addAdmin(alice, {Substrate: bob.address});65 const token = await collection.mintToken(alice);6667 await token.burnFrom(bob, {Substrate: alice.address});68 expect(await token.doesExist()).to.be.false;69 });7071 itSub('Burn item in Fungible collection', async ({helper}) => {72 const collection = await helper.ft.mintCollection(alice, {}, 0);73 await collection.setLimits(alice, {ownerCanTransfer: true});74 await collection.addAdmin(alice, {Substrate: bob.address});75 await collection.mint(alice, 10n);7677 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);78 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);79 });80});8182describe('Negative integration test: ext. burnItem():', () => {83 let donor: IKeyringPair;84 let alice: IKeyringPair;85 let bob: IKeyringPair;8687 before(async () => {88 await usingPlaygrounds(async (helper, privateKey) => {89 donor = await privateKey({url: import.meta.url});90 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);91 });92 });9394 itSub('Burn a token that was never created', async ({helper}) => {95 const collection = await helper.nft.mintCollection(alice);96 await expect(collection.burnToken(alice, 10)).to.be.rejectedWith('common.TokenNotFound');97 });9899 itSub('Burn a token using the address that does not own it', async ({helper}) => {100 const collection = await helper.nft.mintCollection(alice);101 const token = await collection.mintToken(alice);102103 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');104 });105106 itSub('Transfer a burned token', async ({helper}) => {107 const collection = await helper.nft.mintCollection(alice);108 const token = await collection.mintToken(alice);109 await token.burn(alice);110111 await expect(token.transfer(alice, {Substrate: bob.address})).to.be.rejectedWith('common.TokenNotFound');112 });113114 itSub('Burn more than owned in Fungible collection', async ({helper}) => {115 const collection = await helper.ft.mintCollection(alice, {}, 0);116 await collection.mint(alice, 10n);117118 await expect(collection.burnTokens(alice, 11n)).to.be.rejectedWith('common.TokenValueTooLow');119 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);120 });121122 itSub('Zero burn NFT', async ({helper}) => {123 const collection = await helper.nft.mintCollection(alice, {name: 'Coll', description: 'Desc', tokenPrefix: 'T'});124 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});125 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});126127 128 await helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenAlice.tokenId, 0]);129 130 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenBob.tokenId, 0])).to.be.rejectedWith('common.NoPermission');131 132 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, 9999, 0])).to.be.rejectedWith('common.TokenNotFound');133 expect(await tokenAlice.doesExist()).to.be.true;134 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});135 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});136 137 await tokenAlice.transfer(alice, {Substrate: bob.address});138 await tokenBob.transfer(bob, {Substrate: alice.address});139 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});140 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});141 });142143 itSub('zero burnFrom NFT', async ({helper}) => {144 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});145 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});146 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});147 await approvedNft.approve(bob, {Substrate: alice.address});148149 150 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');151 152 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');153 154 await helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0]);155156 157 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;158 159 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});160 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});161 162 await approvedNft.burnFrom(alice, {Substrate: bob.address});163 expect(await approvedNft.doesExist()).to.be.false;164 });165});