1234567891011121314151617import {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); 90 });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 args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},150 {Nft: {const_data: '0x32', variable_data: '0x32'}},151 {Nft: {const_data: '0x33', variable_data: '0x33'}}];152 const createMultipleItemsTx = api.tx.unique153 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);154 await submitTransactionAsync(alice, createMultipleItemsTx);155 const itemsListIndexAfter = await getLastTokenId(api, collectionId);156 expect(itemsListIndexAfter).to.be.equal(3);157158 await expect(executeTransaction(159 api, 160 alice, 161 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]), 162 )).to.not.be.rejected;163164 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));165 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));166 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));167168 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);169 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);170 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);171172 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);173 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);174 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);175 });176 });177178 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {179 await usingApi(async (api: ApiPromise) => {180 const collectionId = await createCollectionExpectSuccess();181 const itemsListIndexBefore = await getLastTokenId(api, collectionId);182 expect(itemsListIndexBefore).to.be.equal(0);183 const alice = privateKey('//Alice');184 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},185 {Nft: {const_data: '0x32', variable_data: '0x32'}},186 {Nft: {const_data: '0x33', variable_data: '0x33'}}];187 const createMultipleItemsTx = api.tx.unique188 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);189 await submitTransactionAsync(alice, createMultipleItemsTx);190 const itemsListIndexAfter = await getLastTokenId(api, collectionId);191 expect(itemsListIndexAfter).to.be.equal(3);192193 await expect(executeTransaction(194 api, 195 alice, 196 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]), 197 )).to.not.be.rejected;198199 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));200 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));201 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));202203 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);204 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);205 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);206207 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);208 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);209 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);210 });211 });212213 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {214 await usingApi(async (api: ApiPromise) => {215 const collectionId = await createCollectionExpectSuccess();216 const itemsListIndexBefore = await getLastTokenId(api, collectionId);217 expect(itemsListIndexBefore).to.be.equal(0);218 const alice = privateKey('//Alice');219 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},220 {Nft: {const_data: '0x32', variable_data: '0x32'}},221 {Nft: {const_data: '0x33', variable_data: '0x33'}}];222 const createMultipleItemsTx = api.tx.unique223 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);224 await submitTransactionAsync(alice, createMultipleItemsTx);225 const itemsListIndexAfter = await getLastTokenId(api, collectionId);226 expect(itemsListIndexAfter).to.be.equal(3);227228 await expect(executeTransaction(229 api, 230 alice, 231 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]), 232 )).to.not.be.rejected;233234 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));235 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));236 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));237238 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);239 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);240 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);241242 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);243 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);244 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);245 });246 });247});248249describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {250251 let alice: IKeyringPair;252 let bob: IKeyringPair;253254 before(async () => {255 await usingApi(async () => {256 alice = privateKey('//Alice');257 bob = privateKey('//Bob');258 });259 });260261 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {262 await usingApi(async (api: ApiPromise) => {263 const collectionId = await createCollectionExpectSuccess();264 const itemsListIndexBefore = await getLastTokenId(api, collectionId);265 expect(itemsListIndexBefore).to.be.equal(0);266 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);267 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},268 {Nft: {const_data: '0x32', variable_data: '0x32'}},269 {Nft: {const_data: '0x33', variable_data: '0x33'}}];270 const createMultipleItemsTx = api.tx.unique271 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);272 await submitTransactionAsync(bob, createMultipleItemsTx);273 const itemsListIndexAfter = await getLastTokenId(api, collectionId);274 expect(itemsListIndexAfter).to.be.equal(3);275276 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));277 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));278 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));279280 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);281 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);282 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);283284 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);285 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);286 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);287 });288 });289290 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {291 await usingApi(async (api: ApiPromise) => {292 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});293 const itemsListIndexBefore = await getLastTokenId(api, collectionId);294 expect(itemsListIndexBefore).to.be.equal(0);295 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);296 const args = [297 {Fungible: {value: 1}},298 {Fungible: {value: 2}},299 {Fungible: {value: 3}},300 ];301 const createMultipleItemsTx = api.tx.unique302 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);303 await submitTransactionAsync(bob, createMultipleItemsTx);304 const token1Data = await getBalance(api, collectionId, bob.address, 0);305306 expect(token1Data).to.be.equal(6n); 307 });308 });309310 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {311 await usingApi(async (api: ApiPromise) => {312 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});313 const itemsListIndexBefore = await getLastTokenId(api, collectionId);314 expect(itemsListIndexBefore).to.be.equal(0);315 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);316 const args = [317 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},318 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},319 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},320 ];321 const createMultipleItemsTx = api.tx.unique322 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);323 await submitTransactionAsync(bob, createMultipleItemsTx);324 const itemsListIndexAfter = await getLastTokenId(api, collectionId);325 expect(itemsListIndexAfter).to.be.equal(3);326327 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);328 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);329 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);330331 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);332 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);333 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);334335 expect(await getVariableMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);336 expect(await getVariableMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);337 expect(await getVariableMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);338 });339 });340});341342describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {343344 let alice: IKeyringPair;345 let bob: IKeyringPair;346347 before(async () => {348 await usingApi(async () => {349 alice = privateKey('//Alice');350 bob = privateKey('//Bob');351 });352 });353354 it('Regular user cannot create items in active NFT collection', async () => {355 await usingApi(async (api: ApiPromise) => {356 const collectionId = await createCollectionExpectSuccess();357 const itemsListIndexBefore = await getLastTokenId(api, collectionId);358 expect(itemsListIndexBefore).to.be.equal(0);359 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},360 {Nft: {const_data: '0x32', variable_data: '0x32'}},361 {Nft: {const_data: '0x33', variable_data: '0x33'}}];362 const createMultipleItemsTx = api.tx.unique363 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);364 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;365 });366 });367368 it('Regular user cannot create items in active Fungible collection', async () => {369 await usingApi(async (api: ApiPromise) => {370 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});371 const itemsListIndexBefore = await getLastTokenId(api, collectionId);372 expect(itemsListIndexBefore).to.be.equal(0);373 const args = [374 {Fungible: {value: 1}},375 {Fungible: {value: 2}},376 {Fungible: {value: 3}},377 ];378 const createMultipleItemsTx = api.tx.unique379 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);380 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;381 });382 });383384 it('Regular user cannot create items in active ReFungible collection', async () => {385 await usingApi(async (api: ApiPromise) => {386 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});387 const itemsListIndexBefore = await getLastTokenId(api, collectionId);388 expect(itemsListIndexBefore).to.be.equal(0);389 const args = [390 {ReFungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},391 {ReFungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},392 {ReFungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},393 ];394 const createMultipleItemsTx = api.tx.unique395 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);396 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;397 });398 });399400 it('Create token in not existing collection', async () => {401 await usingApi(async (api: ApiPromise) => {402 const collectionId = await getCreatedCollectionCount(api) + 1;403 const createMultipleItemsTx = api.tx.unique404 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);405 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;406 });407 });408409 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {410 await usingApi(async (api: ApiPromise) => {411 412 const collectionId = await createCollectionExpectSuccess();413 const alice = privateKey('//Alice');414 const args = [415 {NFT: {const_data: 'A'.repeat(2049), variable_data: 'A'.repeat(2049)}},416 {NFT: {const_data: 'B'.repeat(2049), variable_data: 'B'.repeat(2049)}},417 {NFT: {const_data: 'C'.repeat(2049), variable_data: 'C'.repeat(2049)}},418 ];419 const createMultipleItemsTx = api.tx.unique420 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);421 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;422423 424 const collectionIdReFungible =425 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});426 const argsReFungible = [427 {ReFungible: ['1'.repeat(2049), '1'.repeat(2049), 10]},428 {ReFungible: ['2'.repeat(2049), '2'.repeat(2049), 10]},429 {ReFungible: ['3'.repeat(2049), '3'.repeat(2049), 10]},430 ];431 const createMultipleItemsTxFungible = api.tx.unique432 .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);433 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;434 });435 });436437 it('Create tokens with different types', async () => {438 await usingApi(async (api: ApiPromise) => {439 const collectionId = await createCollectionExpectSuccess();440 const createMultipleItemsTx = api.tx.unique441 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);442 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;443 444 await destroyCollectionExpectSuccess(collectionId);445 });446 });447448 it('Create tokens with different data limits <> maximum data limit', async () => {449 await usingApi(async (api: ApiPromise) => {450 const collectionId = await createCollectionExpectSuccess();451 const args = [452 {NFT: {const_data: 'A', variable_data: 'A'}},453 {NFT: {const_data: 'B', variable_data: 'B'.repeat(2049)}},454 {NFT: {const_data: 'C'.repeat(2049), variable_data: 'C'}},455 ];456 const createMultipleItemsTx = await api.tx.unique457 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);458 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;459 });460 });461462 it('Fails when minting tokens exceeds collectionLimits amount', async () => {463 await usingApi(async (api) => {464465 const collectionId = await createCollectionExpectSuccess();466 await setCollectionLimitsExpectSuccess(alice, collectionId, {467 tokenLimit: 1,468 });469 const args = [470 {NFT: {const_data: 'A', variable_data: 'A'}},471 {NFT: {const_data: 'B', variable_data: 'B'}},472 ];473 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);474 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;475 });476 });477478 it('No editing rights', async () => {479 await usingApi(async (api: ApiPromise) => {480 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],481 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});482 const itemsListIndexBefore = await getLastTokenId(api, collectionId);483 expect(itemsListIndexBefore).to.be.equal(0);484 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);485 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},486 {Nft: {const_data: '0x32', variable_data: '0x32'}},487 {Nft: {const_data: '0x33', variable_data: '0x33'}}];488 489 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);490491 const events = await submitTransactionAsync(alice, createMultipleItemsTx);492 const result = getCreateItemsResult(events);493494 for (const elem of result) {495 await expect(executeTransaction(496 api, 497 bob, 498 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]), 499 )).to.be.rejected;500 }501502 503 });504 });505506 it('User doesnt have editing rights', async () => {507 await usingApi(async (api: ApiPromise) => {508 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],509 propPerm: [{key: 'key1', mutable: false, collectionAdmin: false, tokenOwner: false}]});510 const itemsListIndexBefore = await getLastTokenId(api, collectionId);511 expect(itemsListIndexBefore).to.be.equal(0);512 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);513 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},514 {Nft: {const_data: '0x32', variable_data: '0x32'}},515 {Nft: {const_data: '0x33', variable_data: '0x33'}}];516 517 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);518519 const events = await submitTransactionAsync(alice, createMultipleItemsTx);520 const result = getCreateItemsResult(events);521522 for (const elem of result) {523 await expect(executeTransaction(524 api, 525 bob, 526 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]), 527 )).to.be.rejected;528 }529 });530 });531532 it('Adding property without access rights', async () => {533 await usingApi(async (api: ApiPromise) => {534 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});535 const itemsListIndexBefore = await getLastTokenId(api, collectionId);536 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);537 expect(itemsListIndexBefore).to.be.equal(0);538 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},539 {Nft: {const_data: '0x32', variable_data: '0x32'}},540 {Nft: {const_data: '0x33', variable_data: '0x33'}}];541 542 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);543544 const events = await submitTransactionAsync(alice, createMultipleItemsTx);545 const result = getCreateItemsResult(events);546547 for (const elem of result) {548 await expect(executeTransaction(549 api, 550 bob, 551 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'key1', value: 'v2'}]), 552 )).to.be.rejected;553 }554 });555 });556557 it('Adding more than 64 prps', async () => {558 await usingApi(async (api: ApiPromise) => {559 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],560 propPerm: [{key: 'key1', mutable: true, collectionAdmin: true, tokenOwner: false}]});561 const itemsListIndexBefore = await getLastTokenId(api, collectionId);562 expect(itemsListIndexBefore).to.be.equal(0);563 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);564565 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},566 {Nft: {const_data: '0x32', variable_data: '0x32'}},567 {Nft: {const_data: '0x33', variable_data: '0x33'}}];568 569 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);570 const events = await submitTransactionAsync(alice, createMultipleItemsTx);571572 const result = getCreateItemsResult(events);573 574 const prps = [];575 576 for (let i = 0; i < 65; i++) {577 prps.push({key: `key${i}`, value: `value${i}`});578 }579580 await expect(executeTransaction(api, bob, api.tx.unique.setCollectionProperties(collectionId, prps))).to.be.rejectedWith(/common\.PropertyLimitReached/);581 582 for (const elem of result) {583 await expect(executeTransaction(584 api, 585 bob, 586 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, prps), 587 )).to.be.rejected;588 }589 });590 });591592 it('Trying to add bigger property than allowed', async () => {593 await usingApi(async (api: ApiPromise) => {594 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],595 propPerm: [{key: 'key1', mutable: true, collectionAdmin: false, tokenOwner: false}]});596 const itemsListIndexBefore = await getLastTokenId(api, collectionId);597 expect(itemsListIndexBefore).to.be.equal(0);598 const args = [{Nft: {const_data: '0x31', variable_data: '0x31'}},599 {Nft: {const_data: '0x32', variable_data: '0x32'}},600 {Nft: {const_data: '0x33', variable_data: '0x33'}}];601 602 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);603604 const events = await submitTransactionAsync(alice, createMultipleItemsTx);605 const result = getCreateItemsResult(events);606607608 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/);609610 for (const elem of result) {611 await expect(executeTransaction(612 api, 613 bob, 614 api.tx.unique.setTokenProperties(elem.collectionId, elem.itemId, [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]), 615 )).to.be.rejected;616 }617 });618 });619});