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

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  createItemWithPropsExpectSuccess,27} from './util/helpers';2829const expect = chai.expect;30let alice: IKeyringPair;31let bob: IKeyringPair;3233describe('integration test: ext. ():', () => {34  before(async () => {35    await usingApi(async () => {36      const keyring = new Keyring({type: 'sr25519'});37      alice = keyring.addFromUri('//Alice');38      bob = keyring.addFromUri('//Bob');39    });40  });4142  it('Create new item in NFT collection', async () => {43    const createMode = 'NFT';44    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});45    await createItemExpectSuccess(alice, newCollectionID, createMode);46  });47  it('Create new item in Fungible collection', async () => {48    const createMode = 'Fungible';49    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});50    await createItemExpectSuccess(alice, newCollectionID, createMode);51  });52  it('Create new item in ReFungible collection', async () => {53    const createMode = 'ReFungible';54    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});55    await createItemExpectSuccess(alice, newCollectionID, createMode);56  });57  it('Create new item in NFT collection with collection admin permissions', async () => {58    const createMode = 'NFT';59    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});60    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);61    await createItemExpectSuccess(bob, newCollectionID, createMode);62  });63  it('Create new item in Fungible collection with collection admin permissions', async () => {64    const createMode = 'Fungible';65    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});66    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);67    await createItemExpectSuccess(bob, newCollectionID, createMode);68  });69  it('Create new item in ReFungible collection with collection admin permissions', async () => {70    const createMode = 'ReFungible';71    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});72    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);73    await createItemExpectSuccess(bob, newCollectionID, createMode);74  });7576  it('Set property Admin', async () => {77    const createMode = 'NFT';78    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 79      propPerm:   [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});80    81    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);82  });8384  it('Set property AdminConst', async () => {85    const createMode = 'NFT';86    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 87      propPerm:   [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});88    89    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);90  });9192  it('Set property itemOwnerOrAdmin', async () => {93    const createMode = 'NFT';94    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},95      propPerm:   [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});96    97    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);98  });99});100101describe('Negative integration test: ext. createItem():', () => {102  before(async () => {103    await usingApi(async () => {104      const keyring = new Keyring({type: 'sr25519'});105      alice = keyring.addFromUri('//Alice');106      bob = keyring.addFromUri('//Bob');107    });108  });109110  it('Regular user cannot create new item in NFT collection', async () => {111    const createMode = 'NFT';112    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});113    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;114  });115  it('Regular user cannot create new item in Fungible collection', async () => {116    const createMode = 'Fungible';117    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});118    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;119  });120  it('Regular user cannot create new item in ReFungible collection', async () => {121    const createMode = 'ReFungible';122    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});123    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;124  });125126  it('No editing rights', async () => {127    await usingApi(async api => {128      const createMode = 'NFT';129      const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 130        propPerm:   [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});131132      const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');133      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);134135      await expect(executeTransaction(136        api, 137        alice, 138        api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 139      )).to.be.rejected;140    });141  });142143  it('User doesnt have editing rights', async () => {144    await usingApi(async api => {145      const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});146      const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');147148      await expect(executeTransaction(149        api, 150        bob, 151        api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 152      )).to.be.rejected;153    });154  });155156  it('Adding property without access rights', async () => {157    await usingApi(async api => {158      const createMode = 'NFT';159      const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});160161      const token = await createItemExpectSuccess(alice, newCollectionID, 'NFT');162      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);163      164      await expect(executeTransaction(165        api, 166        bob, 167        api.tx.unique.setTokenProperties(newCollectionID, token, [{key: 'key1', value: 'v2'}]), 168      )).to.be.rejected;169    });170  });171172  it('Adding more than 64 prps', async () => {173    await usingApi(async api => {174      const createMode = 'NFT';175176      const prps = [];177178      for (let i = 0; i < 65; i++) {179        prps.push({key: `key${i}`, value: `value${i}`});180      }181182      const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});183      184      await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(newCollectionID, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);185    });186  });187188  it('Trying to add bigger property than allowed', async () => {189    await usingApi(async api => {190      const createMode = 'NFT';191      const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});192      193      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/);194    });195  });196});