difftreelog
createMultipleItemsEx migrated
in: master
1 file changed
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth1// 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 {expect} from 'chai';18import usingApi, {executeTransaction} from './substrate/substrate-api';19import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets, Pallets} from './util/helpers';2021describe('Integration Test: createMultipleItemsEx', () => {22 it('can initialize multiple NFT with different owners', async () => {23 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});24 await usingApi(async (api, privateKeyWrapper) => {25 const alice = privateKeyWrapper('//Alice');26 const bob = privateKeyWrapper('//Bob');27 const charlie = privateKeyWrapper('//Charlie');28 const data = [29 {30 owner: {substrate: alice.address},31 }, {32 owner: {substrate: bob.address},33 }, {34 owner: {substrate: charlie.address},35 },36 ];3738 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {39 NFT: data,40 }));41 const tokens = await api.query.nonfungible.tokenData.entries(collection);42 const json = tokens.map(([, token]) => token.toJSON());43 expect(json).to.be.deep.equal(data);44 });45 });4647 it('createMultipleItemsEx with property Admin', async () => {48 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});49 await usingApi(async (api, privateKeyWrapper) => {50 const alice = privateKeyWrapper('//Alice');51 const bob = privateKeyWrapper('//Bob');52 const charlie = privateKeyWrapper('//Charlie');53 const data = [54 {55 owner: {substrate: alice.address},56 properties: [{key: 'k', value: 'v1'}],57 }, {58 owner: {substrate: bob.address},59 properties: [{key: 'k', value: 'v2'}],60 }, {61 owner: {substrate: charlie.address},62 properties: [{key: 'k', value: 'v3'}],63 },64 ];6566 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {67 NFT: data,68 }));69 for (let i = 1; i < 4; i++) {70 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;71 }72 });73 });7475 it('createMultipleItemsEx with property AdminConst', async () => {76 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});77 await usingApi(async (api, privateKeyWrapper) => {78 const alice = privateKeyWrapper('//Alice');79 const bob = privateKeyWrapper('//Bob');80 const charlie = privateKeyWrapper('//Charlie');81 const data = [82 {83 owner: {substrate: alice.address},84 properties: [{key: 'k', value: 'v1'}],85 }, {86 owner: {substrate: bob.address},87 properties: [{key: 'k', value: 'v2'}],88 }, {89 owner: {substrate: charlie.address},90 properties: [{key: 'k', value: 'v3'}],91 },92 ];9394 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {95 NFT: data,96 }));97 for (let i = 1; i < 4; i++) {98 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;99 }100 });101 });102103 it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {104 const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});105 await usingApi(async (api, privateKeyWrapper) => {106 const alice = privateKeyWrapper('//Alice');107 const bob = privateKeyWrapper('//Bob');108 const charlie = privateKeyWrapper('//Charlie');109 const data = [110 {111 owner: {substrate: alice.address},112 properties: [{key: 'k', value: 'v1'}],113 }, {114 owner: {substrate: bob.address},115 properties: [{key: 'k', value: 'v2'}],116 }, {117 owner: {substrate: charlie.address},118 properties: [{key: 'k', value: 'v3'}],119 },120 ];121122 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {123 NFT: data,124 }));125 for (let i = 1; i < 4; i++) {126 expect(await api.rpc.unique.tokenProperties(collection, i)).not.to.be.empty;127 }128 });129 });130131 it('can initialize fungible with multiple owners', async () => {132 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});133 await usingApi(async (api, privateKeyWrapper) => {134 const alice = privateKeyWrapper('//Alice');135 const bob = privateKeyWrapper('//Bob');136137 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {138 Fungible: new Map([139 [JSON.stringify({Substrate: alice.address}), 50],140 [JSON.stringify({Substrate: bob.address}), 100],141 ]),142 }));143144 expect(await getBalance(api, collection, alice.address, 0)).to.equal(50n);145 expect(await getBalance(api, collection, bob.address, 0)).to.equal(100n);146 });147 });148149 it('can initialize an RFT with multiple owners', async function() {150 await requirePallets(this, [Pallets.ReFungible]);151152 await usingApi(async (api, privateKeyWrapper) => {153 const alice = privateKeyWrapper('//Alice');154 const bob = privateKeyWrapper('//Bob');155 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});156 await executeTransaction(157 api,158 alice,159 api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'data', permission: {tokenOwner: true}}]),160 );161162 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {163 RefungibleMultipleOwners: {164 users: new Map([165 [JSON.stringify({Substrate: alice.address}), 1],166 [JSON.stringify({Substrate: bob.address}), 2],167 ]),168 properties: [169 {key: 'data', value: 'testValue'},170 ],171 },172 }));173174 const itemsListIndexAfter = await getLastTokenId(api, collection);175 expect(itemsListIndexAfter).to.be.equal(1);176177 expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n);178 expect(await getBalance(api, collection, bob.address, 1)).to.be.equal(2n);179 expect((await getTokenProperties(api, collection, 1, ['data']))[0].value).to.be.equal('testValue');180 });181 });182183 it('can initialize multiple RFTs with the same owner', async function() {184 await requirePallets(this, [Pallets.ReFungible]);185186 await usingApi(async (api, privateKeyWrapper) => {187 const alice = privateKeyWrapper('//Alice');188 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});189 await executeTransaction(190 api,191 alice,192 api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'data', permission: {tokenOwner: true}}]),193 );194195 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {196 RefungibleMultipleItems: [197 {198 user: {Substrate: alice.address}, pieces: 1,199 properties: [200 {key: 'data', value: 'testValue1'},201 ],202 },203 {204 user: {Substrate: alice.address}, pieces: 3,205 properties: [206 {key: 'data', value: 'testValue2'},207 ],208 },209 ],210 }));211212 const itemsListIndexAfter = await getLastTokenId(api, collection);213 expect(itemsListIndexAfter).to.be.equal(2);214215 expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n);216 expect(await getBalance(api, collection, alice.address, 2)).to.be.equal(3n);217 expect((await getTokenProperties(api, collection, 1, ['data']))[0].value).to.be.equal('testValue1');218 expect((await getTokenProperties(api, collection, 2, ['data']))[0].value).to.be.equal('testValue2');219 });220 });221});222223describe('Negative test: createMultipleItemsEx', () => {224 it('No editing rights', async () => {225 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],226 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});227 await usingApi(async (api, privateKeyWrapper) => {228 const alice = privateKeyWrapper('//Alice');229 const bob = privateKeyWrapper('//Bob');230 const charlie = privateKeyWrapper('//Charlie');231 await addCollectionAdminExpectSuccess(alice, collection, bob.address);232 const data = [233 {234 owner: {substrate: alice.address},235 properties: [{key: 'key1', value: 'v2'}],236 }, {237 owner: {substrate: bob.address},238 properties: [{key: 'key1', value: 'v2'}],239 }, {240 owner: {substrate: charlie.address},241 properties: [{key: 'key1', value: 'v2'}],242 },243 ];244245 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});246 // await executeTransaction(api, alice, tx);247248 //await submitTransactionExpectFailAsync(alice, tx);249 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);250 });251 });252253 it('User doesnt have editing rights', async () => {254 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],255 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});256 await usingApi(async (api, privateKeyWrapper) => {257 const alice = privateKeyWrapper('//Alice');258 const bob = privateKeyWrapper('//Bob');259 await addCollectionAdminExpectSuccess(alice, collection, bob.address);260 const data = [261 {262 owner: {substrate: alice.address},263 properties: [{key: 'key1', value: 'v2'}],264 }, {265 owner: {substrate: alice.address},266 properties: [{key: 'key1', value: 'v2'}],267 }, {268 owner: {substrate: alice.address},269 properties: [{key: 'key1', value: 'v2'}],270 },271 ];272273 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});274 // await executeTransaction(api, alice, tx);275276 //await submitTransactionExpectFailAsync(alice, tx);277 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);278 });279 });280281 it('Adding property without access rights', async () => {282 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});283 await usingApi(async (api, privateKeyWrapper) => {284 const alice = privateKeyWrapper('//Alice');285 const bob = privateKeyWrapper('//Bob');286 const charlie = privateKeyWrapper('//Charlie');287 await addCollectionAdminExpectSuccess(alice, collection, bob.address);288 const data = [289 {290 owner: {substrate: alice.address},291 properties: [{key: 'key1', value: 'v2'}],292 }, {293 owner: {substrate: bob.address},294 properties: [{key: 'key1', value: 'v2'}],295 }, {296 owner: {substrate: charlie.address},297 properties: [{key: 'key1', value: 'v2'}],298 },299 ];300301 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});302303 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);304 //await submitTransactionExpectFailAsync(alice, tx);305 });306 });307308 it('Adding more than 64 properties', async () => {309 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];310311 for (let i = 0; i < 65; i++) {312 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});313 }314315 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});316 await usingApi(async (api, privateKeyWrapper) => {317 const alice = privateKeyWrapper('//Alice');318 await expect(executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);319 });320 });321322 it('Trying to add bigger property than allowed', async () => {323 const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});324 await usingApi(async (api, privateKeyWrapper) => {325 const alice = privateKeyWrapper('//Alice');326 const bob = privateKeyWrapper('//Bob');327 const charlie = privateKeyWrapper('//Charlie');328 await addCollectionAdminExpectSuccess(alice, collection, bob.address);329 const data = [330 {331 owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],332 }, {333 owner: {substrate: bob.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],334 }, {335 owner: {substrate: charlie.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],336 },337 ];338339 const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});340341 //await submitTransactionExpectFailAsync(alice, tx);342 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);343 });344 });345346 it('can initialize multiple NFT with different owners', async () => {347 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});348 await usingApi(async (api, privateKeyWrapper) => {349 const alice = privateKeyWrapper('//Alice');350 const bob = privateKeyWrapper('//Bob');351 const charlie = privateKeyWrapper('//Charlie');352 const data = [353 {354 owner: {substrate: alice.address},355 }, {356 owner: {substrate: bob.address},357 }, {358 owner: {substrate: charlie.address},359 },360 ];361362 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {363 NFT: data,364 }));365 const tokens = await api.query.nonfungible.tokenData.entries(collection);366 const json = tokens.map(([, token]) => token.toJSON());367 expect(json).to.be.deep.equal(data);368 });369 });370371 it('can initialize multiple NFT with different owners', async () => {372 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});373 await usingApi(async (api, privateKeyWrapper) => {374 const alice = privateKeyWrapper('//Alice');375 const bob = privateKeyWrapper('//Bob');376 const charlie = privateKeyWrapper('//Charlie');377 const data = [378 {379 owner: {substrate: alice.address},380 }, {381 owner: {substrate: bob.address},382 }, {383 owner: {substrate: charlie.address},384 },385 ];386387 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {388 NFT: data,389 }));390 const tokens = await api.query.nonfungible.tokenData.entries(collection);391 const json = tokens.map(([, token]) => token.toJSON());392 expect(json).to.be.deep.equal(data);393 });394 });395});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 {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds';19import usingApi, {executeTransaction} from './substrate/substrate-api';20import {createCollectionExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets} from './util/helpers';21import {IProperty} from './util/playgrounds/types';2223describe('Integration Test: createMultipleItemsEx', () => {24 let alice: IKeyringPair;25 let bob: IKeyringPair;26 let charlie: IKeyringPair;2728 before(async () => {29 await usingPlaygrounds(async (helper, privateKey) => {30 const donor = privateKey('//Alice');31 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);32 });33 });3435 itSub('can initialize multiple NFT with different owners', async ({helper}) => {36 const collection = await helper.nft.mintCollection(alice, {37 name: 'name',38 description: 'descr',39 tokenPrefix: 'COL',40 });41 const args = [42 {43 owner: {Substrate: alice.address},44 },45 {46 owner: {Substrate: bob.address},47 },48 {49 owner: {Substrate: charlie.address},50 },51 ];5253 const tokens = await collection.mintMultipleTokens(alice, args);54 for (const [i, token] of tokens.entries()) {55 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);56 }57 });5859 itSub('createMultipleItemsEx with property Admin', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {61 name: 'name',62 description: 'descr',63 tokenPrefix: 'COL',64 tokenPropertyPermissions: [65 {66 key: 'k',67 permission: {68 mutable: true,69 collectionAdmin: true,70 tokenOwner: false,71 },72 },73 ],74 });7576 const args = [77 {78 owner: {Substrate: alice.address},79 properties: [{key: 'k', value: 'v1'}],80 },81 {82 owner: {Substrate: bob.address},83 properties: [{key: 'k', value: 'v2'}],84 },85 {86 owner: {Substrate: charlie.address},87 properties: [{key: 'k', value: 'v3'}],88 },89 ];9091 const tokens = await collection.mintMultipleTokens(alice, args);92 for (const [i, token] of tokens.entries()) {93 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);94 expect(await token.getData()).to.not.be.empty;95 }96 });9798 itSub('createMultipleItemsEx with property AdminConst', async ({helper}) => {99 const collection = await helper.nft.mintCollection(alice, {100 name: 'name',101 description: 'descr',102 tokenPrefix: 'COL',103 tokenPropertyPermissions: [104 {105 key: 'k',106 permission: {107 mutable: false,108 collectionAdmin: true,109 tokenOwner: false,110 },111 },112 ],113 });114115 const args = [116 {117 owner: {Substrate: alice.address},118 properties: [{key: 'k', value: 'v1'}],119 },120 {121 owner: {Substrate: bob.address},122 properties: [{key: 'k', value: 'v2'}],123 },124 {125 owner: {Substrate: charlie.address},126 properties: [{key: 'k', value: 'v3'}],127 },128 ];129130 const tokens = await collection.mintMultipleTokens(alice, args);131 for (const [i, token] of tokens.entries()) {132 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);133 expect(await token.getData()).to.not.be.empty;134 }135 });136137 itSub('createMultipleItemsEx with property itemOwnerOrAdmin', async ({helper}) => {138 const collection = await helper.nft.mintCollection(alice, {139 name: 'name',140 description: 'descr',141 tokenPrefix: 'COL',142 tokenPropertyPermissions: [143 {144 key: 'k',145 permission: {146 mutable: false,147 collectionAdmin: true,148 tokenOwner: true,149 },150 },151 ],152 });153154 const args = [155 {156 owner: {Substrate: alice.address},157 properties: [{key: 'k', value: 'v1'}],158 },159 {160 owner: {Substrate: bob.address},161 properties: [{key: 'k', value: 'v2'}],162 },163 {164 owner: {Substrate: charlie.address},165 properties: [{key: 'k', value: 'v3'}],166 },167 ];168169 const tokens = await collection.mintMultipleTokens(alice, args);170 for (const [i, token] of tokens.entries()) {171 expect(await token.getOwner()).to.be.deep.equal(args[i].owner);172 expect(await token.getData()).to.not.be.empty;173 }174 });175176 it.skip('can initialize fungible with multiple owners', async () => {177 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});178 await usingApi(async (api, privateKeyWrapper) => {179 const alice = privateKeyWrapper('//Alice');180 const bob = privateKeyWrapper('//Bob');181182 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {183 Fungible: new Map([184 [JSON.stringify({Substrate: alice.address}), 50],185 [JSON.stringify({Substrate: bob.address}), 100],186 ]),187 }));188189 expect(await getBalance(api, collection, alice.address, 0)).to.equal(50n);190 expect(await getBalance(api, collection, bob.address, 0)).to.equal(100n);191 });192 });193194 it.skip('can initialize an RFT with multiple owners', async function() {195 await requirePallets(this, [Pallets.ReFungible]);196197 await usingApi(async (api, privateKeyWrapper) => {198 const alice = privateKeyWrapper('//Alice');199 const bob = privateKeyWrapper('//Bob');200 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});201 await executeTransaction(202 api,203 alice,204 api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'data', permission: {tokenOwner: true}}]),205 );206207 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {208 RefungibleMultipleOwners: {209 users: new Map([210 [JSON.stringify({Substrate: alice.address}), 1],211 [JSON.stringify({Substrate: bob.address}), 2],212 ]),213 properties: [214 {key: 'data', value: 'testValue'},215 ],216 },217 }));218219 const itemsListIndexAfter = await getLastTokenId(api, collection);220 expect(itemsListIndexAfter).to.be.equal(1);221222 expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n);223 expect(await getBalance(api, collection, bob.address, 1)).to.be.equal(2n);224 expect((await getTokenProperties(api, collection, 1, ['data']))[0].value).to.be.equal('testValue');225 });226 });227228 it.skip('can initialize multiple RFTs with the same owner', async function() {229 await requirePallets(this, [Pallets.ReFungible]);230231 await usingApi(async (api, privateKeyWrapper) => {232 const alice = privateKeyWrapper('//Alice');233 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});234 await executeTransaction(235 api,236 alice,237 api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'data', permission: {tokenOwner: true}}]),238 );239240 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {241 RefungibleMultipleItems: [242 {243 user: {Substrate: alice.address}, pieces: 1,244 properties: [245 {key: 'data', value: 'testValue1'},246 ],247 },248 {249 user: {Substrate: alice.address}, pieces: 3,250 properties: [251 {key: 'data', value: 'testValue2'},252 ],253 },254 ],255 }));256257 const itemsListIndexAfter = await getLastTokenId(api, collection);258 expect(itemsListIndexAfter).to.be.equal(2);259260 expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n);261 expect(await getBalance(api, collection, alice.address, 2)).to.be.equal(3n);262 expect((await getTokenProperties(api, collection, 1, ['data']))[0].value).to.be.equal('testValue1');263 expect((await getTokenProperties(api, collection, 2, ['data']))[0].value).to.be.equal('testValue2');264 });265 });266});267268describe('Negative test: createMultipleItemsEx', () => {269 let alice: IKeyringPair;270 let bob: IKeyringPair;271 let charlie: IKeyringPair;272273 before(async () => {274 await usingPlaygrounds(async (helper, privateKey) => {275 const donor = privateKey('//Alice');276 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);277 });278 });279280 itSub('No editing rights', async ({helper}) => {281 const collection = await helper.nft.mintCollection(alice, {282 name: 'name',283 description: 'descr',284 tokenPrefix: 'COL',285 tokenPropertyPermissions: [286 {287 key: 'k',288 permission: {289 mutable: true,290 collectionAdmin: false,291 tokenOwner: false,292 },293 },294 ],295 });296297 const args = [298 {299 owner: {Substrate: alice.address},300 properties: [{key: 'k', value: 'v1'}],301 },302 {303 owner: {Substrate: bob.address},304 properties: [{key: 'k', value: 'v2'}],305 },306 {307 owner: {Substrate: charlie.address},308 properties: [{key: 'k', value: 'v3'}],309 },310 ];311312 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/);313 });314315 itSub('User doesnt have editing rights', async ({helper}) => {316 const collection = await helper.nft.mintCollection(alice, {317 name: 'name',318 description: 'descr',319 tokenPrefix: 'COL',320 tokenPropertyPermissions: [321 {322 key: 'k',323 permission: {324 mutable: false,325 collectionAdmin: false,326 tokenOwner: false,327 },328 },329 ],330 });331332 const args = [333 {334 owner: {Substrate: alice.address},335 properties: [{key: 'k', value: 'v1'}],336 },337 {338 owner: {Substrate: bob.address},339 properties: [{key: 'k', value: 'v2'}],340 },341 {342 owner: {Substrate: charlie.address},343 properties: [{key: 'k', value: 'v3'}],344 },345 ];346347 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/);348 });349350 itSub('Adding property without access rights', async ({helper}) => {351 const collection = await helper.nft.mintCollection(alice, {352 name: 'name',353 description: 'descr',354 tokenPrefix: 'COL',355 });356357 const args = [358 {359 owner: {Substrate: alice.address},360 properties: [{key: 'k', value: 'v1'}],361 },362 {363 owner: {Substrate: bob.address},364 properties: [{key: 'k', value: 'v2'}],365 },366 {367 owner: {Substrate: charlie.address},368 properties: [{key: 'k', value: 'v3'}],369 },370 ];371372 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith(/common\.NoPermission/);373 });374375 itSub('Adding more than 64 properties', async ({helper}) => {376 const collection = await helper.nft.mintCollection(alice, {377 name: 'name',378 description: 'descr',379 tokenPrefix: 'COL',380 tokenPropertyPermissions: [381 {382 key: 'k',383 permission: {384 mutable: true,385 collectionAdmin: true,386 tokenOwner: true,387 },388 },389 ],390 });391392 const properties: IProperty[] = [];393394 for (let i = 0; i < 65; i++) {395 properties.push({key: `k${i}`, value: `v${i}`});396 }397398 const args = [399 {400 owner: {Substrate: alice.address},401 properties: properties,402 },403 {404 owner: {Substrate: bob.address},405 properties: properties,406 },407 {408 owner: {Substrate: charlie.address},409 properties: properties,410 },411 ];412413 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith('Verification Error');414 });415416 itSub('Trying to add bigger property than allowed', async ({helper}) => {417 const collection = await helper.nft.mintCollection(alice, {418 name: 'name',419 description: 'descr',420 tokenPrefix: 'COL',421 tokenPropertyPermissions: [422 {423 key: 'k',424 permission: {425 mutable: true,426 collectionAdmin: true,427 tokenOwner: true,428 },429 },430 ],431 });432433 const args = [434 {435 owner: {Substrate: alice.address},436 properties: [{key: 'k', value: 'A'.repeat(32769)}],437 },438 {439 owner: {Substrate: bob.address},440 properties: [{key: 'k', value: 'A'.repeat(32769)}],441 },442 {443 owner: {Substrate: charlie.address},444 properties: [{key: 'k', value: 'A'.repeat(32769)}],445 },446 ];447448 await expect(collection.mintMultipleTokens(alice, args)).to.be.rejectedWith('Verification Error');449 });450});