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

difftreelog

test fix eslint warnings

Yaroslav Bolyukin2022-05-30parent: #5e512fa.patch.diff
in: master

2 files changed

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 {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';18import {Keyring} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';20import {21  createCollectionExpectSuccess,22  createItemExpectSuccess,23  getGenericResult,24  destroyCollectionExpectSuccess,25  normalizeAccountId,26  addCollectionAdminExpectSuccess,27  getBalance,28  isTokenExists,29} from './util/helpers';3031import chai from 'chai';32import chaiAsPromised from 'chai-as-promised';33chai.use(chaiAsPromised);34const expect = chai.expect;3536let alice: IKeyringPair;37let bob: IKeyringPair;3839describe('integration test: ext. burnItem():', () => {40  before(async () => {41    await usingApi(async () => {42      const keyring = new Keyring({type: 'sr25519'});43      alice = keyring.addFromUri('//Alice');44      bob = keyring.addFromUri('//Bob');45    });46  });4748  it('Burn item in NFT collection', async () => {49    const createMode = 'NFT';50    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});51    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);5253    await usingApi(async (api) => {54      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);55      const events = await submitTransactionAsync(alice, tx);56      const result = getGenericResult(events);5758      expect(result.success).to.be.true;59      // Get the item60      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;61    });62  });6364  it('Burn item in Fungible collection', async () => {65    const createMode = 'Fungible';66    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});67    await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens68    const tokenId = 0; // ignored6970    await usingApi(async (api) => {71      // Destroy 1 of 1072      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);73      const events = await submitTransactionAsync(alice, tx);74      const result = getGenericResult(events);7576      // Get alice balance77      const balance = await getBalance(api, collectionId, alice.address, 0);7879      // What to expect80      expect(result.success).to.be.true;81      expect(balance).to.be.equal(9n);82    });83  });8485  it('Burn item in ReFungible collection', async () => {86    const createMode = 'ReFungible';87    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});88    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);8990    await usingApi(async (api) => {91      const tx = api.tx.unique.burnItem(collectionId, tokenId, 100);92      const events = await submitTransactionAsync(alice, tx);93      const result = getGenericResult(events);9495      // Get alice balance96      const balance = await getBalance(api, collectionId, alice.address, tokenId);9798      // What to expect99      expect(result.success).to.be.true;100      expect(balance).to.be.equal(0n);101    });102  });103104  it('Burn owned portion of item in ReFungible collection', async () => {105    const createMode = 'ReFungible';106    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});107    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);108109    await usingApi(async (api) => {110      // Transfer 1/100 of the token to Bob111      const transfertx = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);112      const events1 = await submitTransactionAsync(alice, transfertx);113      const result1 = getGenericResult(events1);114115      // Get balances116      const bobBalanceBefore = await getBalance(api, collectionId, bob.address, tokenId);117      const aliceBalanceBefore = await getBalance(api, collectionId, alice.address, tokenId);118119      // Bob burns his portion120      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);121      const events2 = await submitTransactionAsync(bob, tx);122      const result2 = getGenericResult(events2);123124      // Get balances125      const bobBalanceAfter = await getBalance(api, collectionId, bob.address, tokenId);126      const aliceBalanceAfter = await getBalance(api, collectionId, alice.address, tokenId);127      // console.log(balance);128129      // What to expect before burning130      expect(result1.success).to.be.true;131      expect(aliceBalanceBefore).to.be.equal(99n);132      expect(bobBalanceBefore).to.be.equal(1n);133134      // What to expect after burning135      expect(result2.success).to.be.true;136      expect(aliceBalanceAfter).to.be.equal(99n);137      expect(bobBalanceAfter).to.be.equal(0n);138    });139140  });141142});143144describe('integration test: ext. burnItem() with admin permissions:', () => {145  before(async () => {146    await usingApi(async () => {147      const keyring = new Keyring({type: 'sr25519'});148      alice = keyring.addFromUri('//Alice');149      bob = keyring.addFromUri('//Bob');150    });151  });152153  it('Burn item in NFT collection', async () => {154    const createMode = 'NFT';155    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});156    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);157    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);158159    await usingApi(async (api) => {160      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);161      const events = await submitTransactionAsync(bob, tx);162      const result = getGenericResult(events);163164      expect(result.success).to.be.true;165      // Get the item166      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;167    });168  });169170  // TODO: burnFrom171  it('Burn item in Fungible collection', async () => {172    const createMode = 'Fungible';173    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});174    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens175    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);176177    await usingApi(async (api) => {178      // Destroy 1 of 10179      const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 1);180      const events = await submitTransactionAsync(bob, tx);181      const result = getGenericResult(events);182183      // Get alice balance184      const balance = await getBalance(api, collectionId, alice.address, 0);185186      // What to expect187      expect(result.success).to.be.true;188      expect(balance).to.be.equal(9n);189    });190  });191192  // TODO: burnFrom193  it('Burn item in ReFungible collection', async () => {194    const createMode = 'ReFungible';195    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});196    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);197    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);198199    await usingApi(async (api) => {200      const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 100);201      const events = await submitTransactionAsync(bob, tx);202      const result = getGenericResult(events);203      // Get alice balance204      expect(result.success).to.be.true;205      // Get the item206      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;207    });208  });209});210211describe('Negative integration test: ext. burnItem():', () => {212  before(async () => {213    await usingApi(async () => {214      const keyring = new Keyring({type: 'sr25519'});215      alice = keyring.addFromUri('//Alice');216      bob = keyring.addFromUri('//Bob');217    });218  });219220  it('Burn a token that was never created', async () => {221    const createMode = 'NFT';222    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});223    const tokenId = 10;224225    await usingApi(async (api) => {226      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);227      const badTransaction = async function () {228        await submitTransactionExpectFailAsync(alice, tx);229      };230      await expect(badTransaction()).to.be.rejected;231    });232233  });234235  it('Burn a token using the address that does not own it', async () => {236    const createMode = 'NFT';237    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});238    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);239240    await usingApi(async (api) => {241      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);242      const badTransaction = async function () {243        await submitTransactionExpectFailAsync(bob, tx);244      };245      await expect(badTransaction()).to.be.rejected;246    });247248  });249250  it('Transfer a burned a token', async () => {251    const createMode = 'NFT';252    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});253    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);254255    await usingApi(async (api) => {256257      const burntx = api.tx.unique.burnItem(collectionId, tokenId, 1);258      const events1 = await submitTransactionAsync(alice, burntx);259      const result1 = getGenericResult(events1);260      expect(result1.success).to.be.true;261262      const tx = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);263      const badTransaction = async function () {264        await submitTransactionExpectFailAsync(alice, tx);265      };266      await expect(badTransaction()).to.be.rejected;267    });268269  });270271  it('Burn more than owned in Fungible collection', async () => {272    const createMode = 'Fungible';273    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});274    // Helper creates 10 fungible tokens275    await createItemExpectSuccess(alice, collectionId, createMode);276    const tokenId = 0; // ignored277278    await usingApi(async (api) => {279      // Destroy 11 of 10280      const tx = api.tx.unique.burnItem(collectionId, tokenId, 11);281      const badTransaction = async function () {282        await submitTransactionExpectFailAsync(alice, tx);283      };284      await expect(badTransaction()).to.be.rejected;285286      // Get alice balance287      const balance = await getBalance(api, collectionId, alice.address, 0);288289      // What to expect290      expect(balance).to.be.equal(10n);291    });292293  });294295});
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 {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';18import {Keyring} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';20import {21  createCollectionExpectSuccess,22  createItemExpectSuccess,23  getGenericResult,24  normalizeAccountId,25  addCollectionAdminExpectSuccess,26  getBalance,27  isTokenExists,28} from './util/helpers';2930import chai from 'chai';31import chaiAsPromised from 'chai-as-promised';32chai.use(chaiAsPromised);33const expect = chai.expect;3435let alice: IKeyringPair;36let bob: IKeyringPair;3738describe('integration test: ext. burnItem():', () => {39  before(async () => {40    await usingApi(async () => {41      const keyring = new Keyring({type: 'sr25519'});42      alice = keyring.addFromUri('//Alice');43      bob = keyring.addFromUri('//Bob');44    });45  });4647  it('Burn item in NFT collection', async () => {48    const createMode = 'NFT';49    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});50    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);5152    await usingApi(async (api) => {53      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);54      const events = await submitTransactionAsync(alice, tx);55      const result = getGenericResult(events);5657      expect(result.success).to.be.true;58      // Get the item59      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;60    });61  });6263  it('Burn item in Fungible collection', async () => {64    const createMode = 'Fungible';65    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});66    await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens67    const tokenId = 0; // ignored6869    await usingApi(async (api) => {70      // Destroy 1 of 1071      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);72      const events = await submitTransactionAsync(alice, tx);73      const result = getGenericResult(events);7475      // Get alice balance76      const balance = await getBalance(api, collectionId, alice.address, 0);7778      // What to expect79      expect(result.success).to.be.true;80      expect(balance).to.be.equal(9n);81    });82  });8384  it('Burn item in ReFungible collection', async () => {85    const createMode = 'ReFungible';86    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});87    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);8889    await usingApi(async (api) => {90      const tx = api.tx.unique.burnItem(collectionId, tokenId, 100);91      const events = await submitTransactionAsync(alice, tx);92      const result = getGenericResult(events);9394      // Get alice balance95      const balance = await getBalance(api, collectionId, alice.address, tokenId);9697      // What to expect98      expect(result.success).to.be.true;99      expect(balance).to.be.equal(0n);100    });101  });102103  it('Burn owned portion of item in ReFungible collection', async () => {104    const createMode = 'ReFungible';105    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});106    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);107108    await usingApi(async (api) => {109      // Transfer 1/100 of the token to Bob110      const transfertx = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);111      const events1 = await submitTransactionAsync(alice, transfertx);112      const result1 = getGenericResult(events1);113114      // Get balances115      const bobBalanceBefore = await getBalance(api, collectionId, bob.address, tokenId);116      const aliceBalanceBefore = await getBalance(api, collectionId, alice.address, tokenId);117118      // Bob burns his portion119      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);120      const events2 = await submitTransactionAsync(bob, tx);121      const result2 = getGenericResult(events2);122123      // Get balances124      const bobBalanceAfter = await getBalance(api, collectionId, bob.address, tokenId);125      const aliceBalanceAfter = await getBalance(api, collectionId, alice.address, tokenId);126      // console.log(balance);127128      // What to expect before burning129      expect(result1.success).to.be.true;130      expect(aliceBalanceBefore).to.be.equal(99n);131      expect(bobBalanceBefore).to.be.equal(1n);132133      // What to expect after burning134      expect(result2.success).to.be.true;135      expect(aliceBalanceAfter).to.be.equal(99n);136      expect(bobBalanceAfter).to.be.equal(0n);137    });138139  });140141});142143describe('integration test: ext. burnItem() with admin permissions:', () => {144  before(async () => {145    await usingApi(async () => {146      const keyring = new Keyring({type: 'sr25519'});147      alice = keyring.addFromUri('//Alice');148      bob = keyring.addFromUri('//Bob');149    });150  });151152  it('Burn item in NFT collection', async () => {153    const createMode = 'NFT';154    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});155    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);156    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);157158    await usingApi(async (api) => {159      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);160      const events = await submitTransactionAsync(bob, tx);161      const result = getGenericResult(events);162163      expect(result.success).to.be.true;164      // Get the item165      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;166    });167  });168169  // TODO: burnFrom170  it('Burn item in Fungible collection', async () => {171    const createMode = 'Fungible';172    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});173    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens174    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);175176    await usingApi(async (api) => {177      // Destroy 1 of 10178      const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 1);179      const events = await submitTransactionAsync(bob, tx);180      const result = getGenericResult(events);181182      // Get alice balance183      const balance = await getBalance(api, collectionId, alice.address, 0);184185      // What to expect186      expect(result.success).to.be.true;187      expect(balance).to.be.equal(9n);188    });189  });190191  // TODO: burnFrom192  it('Burn item in ReFungible collection', async () => {193    const createMode = 'ReFungible';194    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});195    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);196    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);197198    await usingApi(async (api) => {199      const tx = api.tx.unique.burnFrom(collectionId, normalizeAccountId(alice.address), tokenId, 100);200      const events = await submitTransactionAsync(bob, tx);201      const result = getGenericResult(events);202      // Get alice balance203      expect(result.success).to.be.true;204      // Get the item205      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;206    });207  });208});209210describe('Negative integration test: ext. burnItem():', () => {211  before(async () => {212    await usingApi(async () => {213      const keyring = new Keyring({type: 'sr25519'});214      alice = keyring.addFromUri('//Alice');215      bob = keyring.addFromUri('//Bob');216    });217  });218219  it('Burn a token that was never created', async () => {220    const createMode = 'NFT';221    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});222    const tokenId = 10;223224    await usingApi(async (api) => {225      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);226      const badTransaction = async function () {227        await submitTransactionExpectFailAsync(alice, tx);228      };229      await expect(badTransaction()).to.be.rejected;230    });231232  });233234  it('Burn a token using the address that does not own it', async () => {235    const createMode = 'NFT';236    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});237    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);238239    await usingApi(async (api) => {240      const tx = api.tx.unique.burnItem(collectionId, tokenId, 1);241      const badTransaction = async function () {242        await submitTransactionExpectFailAsync(bob, tx);243      };244      await expect(badTransaction()).to.be.rejected;245    });246247  });248249  it('Transfer a burned a token', async () => {250    const createMode = 'NFT';251    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});252    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);253254    await usingApi(async (api) => {255256      const burntx = api.tx.unique.burnItem(collectionId, tokenId, 1);257      const events1 = await submitTransactionAsync(alice, burntx);258      const result1 = getGenericResult(events1);259      expect(result1.success).to.be.true;260261      const tx = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 1);262      const badTransaction = async function () {263        await submitTransactionExpectFailAsync(alice, tx);264      };265      await expect(badTransaction()).to.be.rejected;266    });267268  });269270  it('Burn more than owned in Fungible collection', async () => {271    const createMode = 'Fungible';272    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});273    // Helper creates 10 fungible tokens274    await createItemExpectSuccess(alice, collectionId, createMode);275    const tokenId = 0; // ignored276277    await usingApi(async (api) => {278      // Destroy 11 of 10279      const tx = api.tx.unique.burnItem(collectionId, tokenId, 11);280      const badTransaction = async function () {281        await submitTransactionExpectFailAsync(alice, tx);282      };283      await expect(badTransaction()).to.be.rejected;284285      // Get alice balance286      const balance = await getBalance(api, collectionId, alice.address, 0);287288      // What to expect289      expect(balance).to.be.equal(10n);290    });291292  });293294});
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -64,7 +64,7 @@
       const tx = api.tx.unique.createCollectionEx({
         mode: {Fungible: 8},
         permissions: {
-          access: 'AllowList'
+          access: 'AllowList',
         },
         name: [1],
         description: [2],