git.delta.rocks / unique-network / refs/commits / 3833b2da5ea7

difftreelog

source

tests/src/burnItem.test.ts6.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds';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('Transfer a burned token', async ({helper}) => {144    const collection = await helper.nft.mintCollection(alice);145    const token = await collection.mintToken(alice);146    await token.burn(alice);147148    await expect(token.transfer(alice, {Substrate: bob.address})).to.be.rejectedWith('common.TokenNotFound');149  });150151  itSub('Burn more than owned in Fungible collection', async ({helper}) => {152    const collection = await helper.ft.mintCollection(alice, {}, 0);153    await collection.mint(alice, 10n);154155    await expect(collection.burnTokens(alice, 11n)).to.be.rejectedWith('common.TokenValueTooLow');156    expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);157  });158});