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 });48});4950describe('integration test: ext. burnItem() with admin permissions:', () => {51 let donor: IKeyringPair;52 let alice: IKeyringPair;53 let bob: IKeyringPair;5455 before(async () => {56 await usingPlaygrounds(async (helper, privateKey) => {57 donor = await privateKey({filename: __filename});58 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);59 });60 });6162 itSub('Burn item in NFT collection', async ({helper}) => {63 const collection = await helper.nft.mintCollection(alice);64 await collection.setLimits(alice, {ownerCanTransfer: true});65 await collection.addAdmin(alice, {Substrate: bob.address});66 const token = await collection.mintToken(alice);6768 await token.burnFrom(bob, {Substrate: alice.address});69 expect(await token.doesExist()).to.be.false;70 });7172 itSub('Burn item in Fungible collection', async ({helper}) => {73 const collection = await helper.ft.mintCollection(alice, {}, 0);74 await collection.setLimits(alice, {ownerCanTransfer: true});75 await collection.addAdmin(alice, {Substrate: bob.address});76 await collection.mint(alice, 10n);7778 await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);79 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);80 });81});8283describe('Negative integration test: ext. burnItem():', () => {84 let donor: IKeyringPair;85 let alice: IKeyringPair;86 let bob: IKeyringPair;8788 before(async () => {89 await usingPlaygrounds(async (helper, privateKey) => {90 donor = await privateKey({filename: __filename});91 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);92 });93 });9495 itSub('Burn a token that was never created', async ({helper}) => {96 const collection = await helper.nft.mintCollection(alice);97 await expect(collection.burnToken(alice, 10)).to.be.rejectedWith('common.TokenNotFound');98 });99100 itSub('Burn a token using the address that does not own it', async ({helper}) => {101 const collection = await helper.nft.mintCollection(alice);102 const token = await collection.mintToken(alice);103104 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');105 });106107 itSub('Transfer a burned token', async ({helper}) => {108 const collection = await helper.nft.mintCollection(alice);109 const token = await collection.mintToken(alice);110 await token.burn(alice);111112 await expect(token.transfer(alice, {Substrate: bob.address})).to.be.rejectedWith('common.TokenNotFound');113 });114115 itSub('Burn more than owned in Fungible collection', async ({helper}) => {116 const collection = await helper.ft.mintCollection(alice, {}, 0);117 await collection.mint(alice, 10n);118119 await expect(collection.burnTokens(alice, 11n)).to.be.rejectedWith('common.TokenValueTooLow');120 expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);121 });122123 itSub('Zero burn NFT', async ({helper}) => {124 const collection = await helper.nft.mintCollection(alice, {name: 'Coll', description: 'Desc', tokenPrefix: 'T'});125 const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});126 const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});127128 129 await helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenAlice.tokenId, 0]);130 131 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenBob.tokenId, 0])).to.be.rejectedWith('common.NoPermission');132 133 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, 9999, 0])).to.be.rejectedWith('common.TokenNotFound');134 expect(await tokenAlice.doesExist()).to.be.true;135 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});136 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});137 138 await tokenAlice.transfer(alice, {Substrate: bob.address});139 await tokenBob.transfer(bob, {Substrate: alice.address});140 expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});141 expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});142 });143144 itSub('zero burnFrom NFT', async ({helper}) => {145 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});146 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});147 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});148 await approvedNft.approve(bob, {Substrate: alice.address});149150 151 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');152 153 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');154 155 await helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0]);156157 158 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;159 160 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});161 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});162 163 await approvedNft.burnFrom(alice, {Substrate: bob.address});164 expect(await approvedNft.doesExist()).to.be.false;165 });166});