git.delta.rocks / unique-network / refs/commits / e432f3ea920d

difftreelog

fix yarn warns

Daniel Shiposha2023-01-26parent: #a560e8d.patch.diff
in: master

2 files changed

modifiedtests/src/benchmarks/mintFee/benchmark.tsdiffbeforeafterboth
--- a/tests/src/benchmarks/mintFee/benchmark.ts
+++ b/tests/src/benchmarks/mintFee/benchmark.ts
@@ -100,7 +100,7 @@
 
     const ethSigner = await helper.eth.createAccountWithBalance(donor, 100n);
     const ethReceiver = await helper.eth.createAccountWithBalance(donor, 5n);
-   
+
     let susbtrateCollection: UniqueNFTCollection | null;
     const createCollectionSubstrateFee = convertToTokens(
       await helper.arrange.calculcateFee({Substrate: donor.address}, async () => {
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
before · tests/src/burnItem.test.ts
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';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    // 1. Zero burn of own tokens allowed:129    await helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenAlice.tokenId, 0]);130    // 2. Zero burn of non-owned tokens not allowed:131    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenBob.tokenId, 0])).to.be.rejectedWith('common.NoPermission');132    // 3. Zero burn of non-existing tokens not allowed: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    // 4. Storage is not corrupted: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    // 1. Zero burnFrom of non-existing tokens not allowed:151    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');152    // 2. Zero burnFrom of not approved tokens not allowed:153    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');154    // 3. Zero burnFrom of approved tokens allowed:155    await helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0]);156157    // 4.1 approvedNft still approved:158    expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;159    // 4.2 bob is still the owner:160    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});161    expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});162    // 4.3 Alice can burn approved nft:163    await approvedNft.burnFrom(alice, {Substrate: bob.address});164    expect(await approvedNft.doesExist()).to.be.false;165  });166});
after · tests/src/burnItem.test.ts
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, 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({filename: __filename});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({filename: __filename});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({filename: __filename});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    // 1. Zero burn of own tokens allowed:128    await helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenAlice.tokenId, 0]);129    // 2. Zero burn of non-owned tokens not allowed:130    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenBob.tokenId, 0])).to.be.rejectedWith('common.NoPermission');131    // 3. Zero burn of non-existing tokens not allowed: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    // 4. Storage is not corrupted: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    // 1. Zero burnFrom of non-existing tokens not allowed:150    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');151    // 2. Zero burnFrom of not approved tokens not allowed:152    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');153    // 3. Zero burnFrom of approved tokens allowed:154    await helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0]);155156    // 4.1 approvedNft still approved:157    expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;158    // 4.2 bob is still the owner:159    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});160    expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});161    // 4.3 Alice can burn approved nft:162    await approvedNft.burnFrom(alice, {Substrate: bob.address});163    expect(await approvedNft.doesExist()).to.be.false;164  });165});