git.delta.rocks / unique-network / refs/commits / 3db00dc56ee4

difftreelog

source

tests/src/createItem.test.ts8.5 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 {default as usingApi, executeTransaction} from './substrate/substrate-api';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';21import {22  createCollectionExpectSuccess,23  createItemExpectSuccess,24  addCollectionAdminExpectSuccess,25  createCollectionWithPropsExpectSuccess,26} from './util/helpers';2728const expect = chai.expect;29let alice: IKeyringPair;30let bob: IKeyringPair;3132describe('integration test: ext. createItem():', () => {33  before(async () => {34    await usingApi(async () => {35      const keyring = new Keyring({type: 'sr25519'});36      alice = keyring.addFromUri('//Alice');37      bob = keyring.addFromUri('//Bob');38    });39  });4041  it('Create new item in NFT collection', async () => {42    const createMode = 'NFT';43    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});44    await createItemExpectSuccess(alice, newCollectionID, createMode);45  });46  it('Create new item in Fungible collection', async () => {47    const createMode = 'Fungible';48    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});49    await createItemExpectSuccess(alice, newCollectionID, createMode);50  });51  it('Create new item in ReFungible collection', async () => {52    const createMode = 'ReFungible';53    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});54    await createItemExpectSuccess(alice, newCollectionID, createMode);55  });56  it('Create new item in NFT collection with collection admin permissions', async () => {57    const createMode = 'NFT';58    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});59    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);60    await createItemExpectSuccess(bob, newCollectionID, createMode);61  });62  it('Create new item in Fungible collection with collection admin permissions', async () => {63    const createMode = 'Fungible';64    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});65    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);66    await createItemExpectSuccess(bob, newCollectionID, createMode);67  });68  it('Create new item in ReFungible collection with collection admin permissions', async () => {69    const createMode = 'ReFungible';70    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});71    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);72    await createItemExpectSuccess(bob, newCollectionID, createMode);73  });7475  it('Set property Admin', async () => {76    const createMode = 'NFT';77    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78      properties: [{key: 'key1', value: 'val1'}], 79      propPerm:   [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});80    81    await createItemExpectSuccess(alice, newCollectionID, createMode);82  });8384  it('Set property AdminConst', async () => {85    const createMode = 'NFT';86    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87      properties: [{key: 'key1', value: 'val1'}], 88      propPerm:   [{key: 'key1', mutable: false, collectionAdmin: true, tokenOwner: false}]});89    90    await createItemExpectSuccess(alice, newCollectionID, createMode);91  });9293  it('Set property itemOwnerOrAdmin', async () => {94    const createMode = 'NFT';95    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 96      properties: [{key: 'key1', value: 'val1'}], 97      propPerm:   [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: true}]});98    99    await createItemExpectSuccess(alice, newCollectionID, createMode);100  });101});102103describe('Negative integration test: ext. createItem():', () => {104  before(async () => {105    await usingApi(async () => {106      const keyring = new Keyring({type: 'sr25519'});107      alice = keyring.addFromUri('//Alice');108      bob = keyring.addFromUri('//Bob');109    });110  });111112  it('Regular user cannot create new item in NFT collection', async () => {113    const createMode = 'NFT';114    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});115    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;116  });117  it('Regular user cannot create new item in Fungible collection', async () => {118    const createMode = 'Fungible';119    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});120    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;121  });122  it('Regular user cannot create new item in ReFungible collection', async () => {123    const createMode = 'ReFungible';124    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});125    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;126  });127128  it('No editing rights', async () => {129    await usingApi(async api => {130      const createMode = 'NFT';131      const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 132        propPerm:   [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});133134      const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');135      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);136137      await expect(executeTransaction(138        api, 139        alice, 140        api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 141      )).to.be.rejected;142    });143  });144145  it('User doesnt have editing rights', async () => {146    await usingApi(async api => {147      const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});148      const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');149150      await expect(executeTransaction(151        api, 152        bob, 153        api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 154      )).to.be.rejected;155    });156  });157158  it('Adding property without access rights', async () => {159    await usingApi(async api => {160      const createMode = 'NFT';161      const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});162163      const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');164      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);165      166      await expect(executeTransaction(167        api, 168        bob, 169        api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 170      )).to.be.rejected;171    });172  });173174  it('Adding more than 64 prps', async () => {175    await usingApi(async api => {176      const createMode = 'NFT';177178      const prps = [];179180      for (let i = 0; i < 65; i++) {181        prps.push({key: `key${i}`, value: `value${i}`});182      }183184      const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});185      186      await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);187    });188  });189190  it('Trying to add bigger property than allowed', async () => {191    await usingApi(async api => {192      const createMode = 'NFT';193      const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});194      195      await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]))).to.be.rejectedWith(/common\.NoSpaceForProperty/);196    });197  });198});