git.delta.rocks / unique-network / refs/commits / 599b5140ca91

difftreelog

source

tests/src/createMultipleItems.test.ts30.3 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 {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import privateKey from './substrate/privateKey';22import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync, executeTransaction} from './substrate/substrate-api';23import {24  createCollectionExpectSuccess,25  destroyCollectionExpectSuccess,26  getGenericResult,27  normalizeAccountId,28  setCollectionLimitsExpectSuccess,29  addCollectionAdminExpectSuccess,30  getBalance,31  getTokenOwner,32  getLastTokenId,33  getVariableMetadata,34  getConstMetadata,35  getCreatedCollectionCount,36  createCollectionWithPropsExpectSuccess,37  getCreateItemsResult,38} from './util/helpers';3940chai.use(chaiAsPromised);41const expect = chai.expect;4243describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {44  it('Create  0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {45    await usingApi(async (api: ApiPromise) => {46      const collectionId = await createCollectionExpectSuccess();47      const itemsListIndexBefore = await getLastTokenId(api, collectionId);48      expect(itemsListIndexBefore).to.be.equal(0);49      const alice = privateKey('//Alice');50      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},51        {Nft: {const_data: '0x32', variable_data: '0x32'}},52        {Nft: {const_data: '0x33', variable_data: '0x33'}}];53      const createMultipleItemsTx = api.tx.unique54        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);55      await submitTransactionAsync(alice, createMultipleItemsTx);56      const itemsListIndexAfter = await getLastTokenId(api, collectionId);57      expect(itemsListIndexAfter).to.be.equal(3);5859      expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));60      expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));61      expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));6263      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);64      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);65      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);6667      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);68      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);69      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);70    });71  });7273  it('Create  0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {74    await usingApi(async (api: ApiPromise) => {75      const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});76      const itemsListIndexBefore = await getLastTokenId(api, collectionId);77      expect(itemsListIndexBefore).to.be.equal(0);78      const alice = privateKey('//Alice');79      const args = [80        {Fungible: {value: 1}},81        {Fungible: {value: 2}},82        {Fungible: {value: 3}},83      ];84      const createMultipleItemsTx = api.tx.unique85        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);86      await submitTransactionAsync(alice, createMultipleItemsTx);87      const token1Data = await getBalance(api, collectionId, alice.address, 0);8889      expect(token1Data).to.be.equal(6n); // 1 + 2 + 390    });91  });9293  it('Create  0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {94    await usingApi(async (api: ApiPromise) => {95      const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});96      const itemsListIndexBefore = await getLastTokenId(api, collectionId);97      expect(itemsListIndexBefore).to.be.equal(0);98      const alice = privateKey('//Alice');99      const args = [100        {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},101        {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},102        {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},103      ];104      const createMultipleItemsTx = api.tx.unique105        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);106      await submitTransactionAsync(alice, createMultipleItemsTx);107      const itemsListIndexAfter = await getLastTokenId(api, collectionId);108      expect(itemsListIndexAfter).to.be.equal(3);109110      expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);111      expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(1n);112      expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(1n);113114      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);115      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);116      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);117118      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);119      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);120      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);121    });122  });123124  it('Can mint amount of items equals to collection limits', async () => {125    await usingApi(async (api) => {126      const alice = privateKey('//Alice');127128      const collectionId = await createCollectionExpectSuccess();129      await setCollectionLimitsExpectSuccess(alice, collectionId, {130        tokenLimit: 2,131      });132      const args = [133        {NFT: {const_data: 'A', variable_data: 'A'}},134        {NFT: {const_data: 'B', variable_data: 'B'}},135      ];136      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);137      const events = await submitTransactionAsync(alice, createMultipleItemsTx);138      const result = getGenericResult(events);139      expect(result.success).to.be.true;140    });141  });142143  it('Create  0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {144    await usingApi(async (api: ApiPromise) => {145      const collectionId = await createCollectionExpectSuccess();146      const itemsListIndexBefore = await getLastTokenId(api, collectionId);147      expect(itemsListIndexBefore).to.be.equal(0);148      const alice = privateKey('//Alice');149      const bob = privateKey('//Bob');150      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},151        {Nft: {const_data: '0x32', variable_data: '0x32'}},152        {Nft: {const_data: '0x33', variable_data: '0x33'}}];153      const createMultipleItemsTx = api.tx.unique154        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);155      await submitTransactionAsync(alice, createMultipleItemsTx);156      const itemsListIndexAfter = await getLastTokenId(api, collectionId);157      expect(itemsListIndexAfter).to.be.equal(3);158159      await expect(executeTransaction(160        api, 161        alice, 162        api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]), 163      )).to.not.be.rejected;164165      expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));166      expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));167      expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));168169      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);170      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);171      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);172173      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);174      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);175      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);176    });177  });178179  it('Create  0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {180    await usingApi(async (api: ApiPromise) => {181      const collectionId = await createCollectionExpectSuccess();182      const itemsListIndexBefore = await getLastTokenId(api, collectionId);183      expect(itemsListIndexBefore).to.be.equal(0);184      const alice = privateKey('//Alice');185      const bob = privateKey('//Bob');186      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},187        {Nft: {const_data: '0x32', variable_data: '0x32'}},188        {Nft: {const_data: '0x33', variable_data: '0x33'}}];189      const createMultipleItemsTx = api.tx.unique190        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);191      await submitTransactionAsync(alice, createMultipleItemsTx);192      const itemsListIndexAfter = await getLastTokenId(api, collectionId);193      expect(itemsListIndexAfter).to.be.equal(3);194195      await expect(executeTransaction(196        api, 197        alice, 198        api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]), 199      )).to.not.be.rejected;200201      expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));202      expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));203      expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));204205      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);206      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);207      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);208209      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);210      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);211      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);212    });213  });214215  it('Create  0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {216    await usingApi(async (api: ApiPromise) => {217      const collectionId = await createCollectionExpectSuccess();218      const itemsListIndexBefore = await getLastTokenId(api, collectionId);219      expect(itemsListIndexBefore).to.be.equal(0);220      const alice = privateKey('//Alice');221      const bob = privateKey('//Bob');222      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},223        {Nft: {const_data: '0x32', variable_data: '0x32'}},224        {Nft: {const_data: '0x33', variable_data: '0x33'}}];225      const createMultipleItemsTx = api.tx.unique226        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);227      await submitTransactionAsync(alice, createMultipleItemsTx);228      const itemsListIndexAfter = await getLastTokenId(api, collectionId);229      expect(itemsListIndexAfter).to.be.equal(3);230231      await expect(executeTransaction(232        api, 233        alice, 234        api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]), 235      )).to.not.be.rejected;236237      expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));238      expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));239      expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));240241      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);242      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);243      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);244245      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);246      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);247      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);248    });249  });250});251252describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {253254  let alice: IKeyringPair;255  let bob: IKeyringPair;256257  before(async () => {258    await usingApi(async () => {259      alice = privateKey('//Alice');260      bob = privateKey('//Bob');261    });262  });263264  it('Create  0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {265    await usingApi(async (api: ApiPromise) => {266      const collectionId = await createCollectionExpectSuccess();267      const itemsListIndexBefore = await getLastTokenId(api, collectionId);268      expect(itemsListIndexBefore).to.be.equal(0);269      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);270      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},271        {Nft: {const_data: '0x32', variable_data: '0x32'}},272        {Nft: {const_data: '0x33', variable_data: '0x33'}}];273      const createMultipleItemsTx = api.tx.unique274        .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);275      await submitTransactionAsync(bob, createMultipleItemsTx);276      const itemsListIndexAfter = await getLastTokenId(api, collectionId);277      expect(itemsListIndexAfter).to.be.equal(3);278279      expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));280      expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));281      expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));282283      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);284      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);285      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);286287      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);288      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);289      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);290    });291  });292293  it('Create  0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {294    await usingApi(async (api: ApiPromise) => {295      const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});296      const itemsListIndexBefore = await getLastTokenId(api, collectionId);297      expect(itemsListIndexBefore).to.be.equal(0);298      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);299      const args = [300        {Fungible: {value: 1}},301        {Fungible: {value: 2}},302        {Fungible: {value: 3}},303      ];304      const createMultipleItemsTx = api.tx.unique305        .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);306      await submitTransactionAsync(bob, createMultipleItemsTx);307      const token1Data = await getBalance(api, collectionId, bob.address, 0);308309      expect(token1Data).to.be.equal(6n); // 1 + 2 + 3310    });311  });312313  it('Create  0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {314    await usingApi(async (api: ApiPromise) => {315      const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});316      const itemsListIndexBefore = await getLastTokenId(api, collectionId);317      expect(itemsListIndexBefore).to.be.equal(0);318      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);319      const args = [320        {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},321        {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},322        {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},323      ];324      const createMultipleItemsTx = api.tx.unique325        .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);326      await submitTransactionAsync(bob, createMultipleItemsTx);327      const itemsListIndexAfter = await getLastTokenId(api, collectionId);328      expect(itemsListIndexAfter).to.be.equal(3);329330      expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);331      expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);332      expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);333334      expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);335      expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);336      expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);337338      expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);339      expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);340      expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);341    });342  });343});344345describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {346347  let alice: IKeyringPair;348  let bob: IKeyringPair;349350  before(async () => {351    await usingApi(async () => {352      alice = privateKey('//Alice');353      bob = privateKey('//Bob');354    });355  });356357  it('Regular user cannot create items in active NFT collection', async () => {358    await usingApi(async (api: ApiPromise) => {359      const collectionId = await createCollectionExpectSuccess();360      const itemsListIndexBefore = await getLastTokenId(api, collectionId);361      expect(itemsListIndexBefore).to.be.equal(0);362      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},363        {Nft: {const_data: '0x32', variable_data: '0x32'}},364        {Nft: {const_data: '0x33', variable_data: '0x33'}}];365      const createMultipleItemsTx = api.tx.unique366        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);367      await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;368    });369  });370371  it('Regular user cannot create items in active Fungible collection', async () => {372    await usingApi(async (api: ApiPromise) => {373      const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});374      const itemsListIndexBefore = await getLastTokenId(api, collectionId);375      expect(itemsListIndexBefore).to.be.equal(0);376      const args = [377        {Fungible: {value: 1}},378        {Fungible: {value: 2}},379        {Fungible: {value: 3}},380      ];381      const createMultipleItemsTx = api.tx.unique382        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);383      await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;384    });385  });386387  it('Regular user cannot create items in active ReFungible collection', async () => {388    await usingApi(async (api: ApiPromise) => {389      const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});390      const itemsListIndexBefore = await getLastTokenId(api, collectionId);391      expect(itemsListIndexBefore).to.be.equal(0);392      const args = [393        {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},394        {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},395        {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},396      ];397      const createMultipleItemsTx = api.tx.unique398        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);399      await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;400    });401  });402403  it('Create token in not existing collection', async () => {404    await usingApi(async (api: ApiPromise) => {405      const collectionId = await getCreatedCollectionCount(api) + 1;406      const createMultipleItemsTx = api.tx.unique407        .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);408      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;409    });410  });411412  it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {413    await usingApi(async (api: ApiPromise) => {414      // NFT415      const collectionId = await createCollectionExpectSuccess();416      const alice = privateKey('//Alice');417      const args = [418        {NFT: {const_data: 'A'.repeat(2049), variable_data: 'A'.repeat(2049)}},419        {NFT: {const_data: 'B'.repeat(2049), variable_data: 'B'.repeat(2049)}},420        {NFT: {const_data: 'C'.repeat(2049), variable_data: 'C'.repeat(2049)}},421      ];422      const createMultipleItemsTx = api.tx.unique423        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);424      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;425426      // ReFungible427      const collectionIdReFungible =428        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});429      const argsReFungible = [430        {ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10]},431        {ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10]},432        {ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10]},433      ];434      const createMultipleItemsTxFungible = api.tx.unique435        .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);436      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;437    });438  });439440  it('Create tokens with different types', async () => {441    await usingApi(async (api: ApiPromise) => {442      const collectionId = await createCollectionExpectSuccess();443      const createMultipleItemsTx = api.tx.unique444        .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);445      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;446      // garbage collection :-D447      await destroyCollectionExpectSuccess(collectionId);448    });449  });450451  it('Create tokens with different data limits <> maximum data limit', async () => {452    await usingApi(async (api: ApiPromise) => {453      const collectionId = await createCollectionExpectSuccess();454      const args = [455        {NFT: {const_data: 'A', variable_data: 'A'}},456        {NFT: {const_data: 'B', variable_data: 'B'.repeat(2049)}},457        {NFT: {const_data: 'C'.repeat(2049), variable_data: 'C'}},458      ];459      const createMultipleItemsTx = await api.tx.unique460        .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);461      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;462    });463  });464465  it('Fails when minting tokens exceeds collectionLimits amount', async () => {466    await usingApi(async (api) => {467468      const collectionId = await createCollectionExpectSuccess();469      await setCollectionLimitsExpectSuccess(alice, collectionId, {470        tokenLimit: 1,471      });472      const args = [473        {NFT: {const_data: 'A', variable_data: 'A'}},474        {NFT: {const_data: 'B', variable_data: 'B'}},475      ];476      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);477      await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;478    });479  });480481  it('No editing rights', async () => {482    await usingApi(async (api: ApiPromise) => {483      const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],484        propPerm:   [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});485      const itemsListIndexBefore = await getLastTokenId(api, collectionId);486      expect(itemsListIndexBefore).to.be.equal(0);487      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);488      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},489        {Nft: {const_data: '0x32', variable_data: '0x32'}},490        {Nft: {const_data: '0x33', variable_data: '0x33'}}];491      492      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);493494      const events = await submitTransactionAsync(alice, createMultipleItemsTx);495      const result = getCreateItemsResult(events);496497      for (const elem of result) {498        await expect(executeTransaction(499          api, 500          bob, 501          api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]), 502        )).to.be.rejected;503      }504505      // await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;506    });507  });508509  it('User doesnt have editing rights', async () => {510    await usingApi(async (api: ApiPromise) => {511      const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],512        propPerm:   [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});513      const itemsListIndexBefore = await getLastTokenId(api, collectionId);514      expect(itemsListIndexBefore).to.be.equal(0);515      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);516      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},517        {Nft: {const_data: '0x32', variable_data: '0x32'}},518        {Nft: {const_data: '0x33', variable_data: '0x33'}}];519      520      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);521522      const events = await submitTransactionAsync(alice, createMultipleItemsTx);523      const result = getCreateItemsResult(events);524525      for (const elem of result) {526        await expect(executeTransaction(527          api, 528          bob, 529          api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]), 530        )).to.be.rejected;531      }532    });533  });534535  it('Adding property without access rights', async () => {536    await usingApi(async (api: ApiPromise) => {537      const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});538      const itemsListIndexBefore = await getLastTokenId(api, collectionId);539      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);540      expect(itemsListIndexBefore).to.be.equal(0);541      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},542        {Nft: {const_data: '0x32', variable_data: '0x32'}},543        {Nft: {const_data: '0x33', variable_data: '0x33'}}];544      545      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);546547      const events = await submitTransactionAsync(alice, createMultipleItemsTx);548      const result = getCreateItemsResult(events);549550      for (const elem of result) {551        await expect(executeTransaction(552          api, 553          bob, 554          api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]), 555        )).to.be.rejected;556      }557    });558  });559560  it('Adding more than 64 prps', async () => {561    await usingApi(async (api: ApiPromise) => {562      const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],563        propPerm:   [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});564      const itemsListIndexBefore = await getLastTokenId(api, collectionId);565      expect(itemsListIndexBefore).to.be.equal(0);566      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);567568      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},569        {Nft: {const_data: '0x32', variable_data: '0x32'}},570        {Nft: {const_data: '0x33', variable_data: '0x33'}}];571      572      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);573      const events = await submitTransactionAsync(alice, createMultipleItemsTx);574575      const result = getCreateItemsResult(events);576      577      const prps = [];578      579      for (let i = 0; i < 65; i++) {580        prps.push({key: `key${i}`, value: `value${i}`});581      }582583      await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collectionId, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);584      585      for (const elem of result) {586        await expect(executeTransaction(587          api, 588          bob, 589          api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps), 590        )).to.be.rejected;591      }592    });593  });594595  it('Trying to add bigger property than allowed', async () => {596    await usingApi(async (api: ApiPromise) => {597      const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],598        propPerm:   [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});599      const itemsListIndexBefore = await getLastTokenId(api, collectionId);600      expect(itemsListIndexBefore).to.be.equal(0);601      const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},602        {Nft: {const_data: '0x32', variable_data: '0x32'}},603        {Nft: {const_data: '0x33', variable_data: '0x33'}}];604      605      const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);606607      const events = await submitTransactionAsync(alice, createMultipleItemsTx);608      const result = getCreateItemsResult(events);609610611      await expect(executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collectionId, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]))).to.be.rejectedWith(/common\.NoSpaceForProperty/);612613      for (const elem of result) {614        await expect(executeTransaction(615          api, 616          bob, 617          api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]), 618        )).to.be.rejected;619      }620    });621  });622});