git.delta.rocks / unique-network / refs/commits / 6804826993dd

difftreelog

createMultipeItems migrated

rkv2022-09-13parent: #3404470.patch.diff
in: master

1 file changed

modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {ApiPromise} from '@polkadot/api';
18import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
19import chai from 'chai';18import chai from 'chai';
20import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
21import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync, executeTransaction} from './substrate/substrate-api';
22import {20import {
23 createCollectionExpectSuccess,
24 destroyCollectionExpectSuccess,
25 getGenericResult,
26 normalizeAccountId,21 normalizeAccountId,
27 setCollectionLimitsExpectSuccess,
28 addCollectionAdminExpectSuccess,
29 getBalance,
30 getTokenOwner,
31 getLastTokenId,
32 getCreatedCollectionCount,
33 createCollectionWithPropsExpectSuccess,
34 createMultipleItemsWithPropsExpectSuccess,
35 getTokenProperties,
36 requirePallets,
37 Pallets,
38 checkPalletsPresence,
39} from './util/helpers';22} from './util/helpers';
40import {usingPlaygrounds} from './util/playgrounds';23import {usingPlaygrounds} from './util/playgrounds';
4124
50 });33 });
51});34});
5235
53let alice: IKeyringPair;36describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
54let bob: IKeyringPair;37 let alice: IKeyringPair;
5538
56describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
57 before(async () => {39 before(async () => {
58 await usingPlaygrounds(async (helper) => {40 await usingPlaygrounds(async (helper) => {
59 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);41 [alice] = await helper.arrange.createAccounts([100n], donor);
60 });42 });
61 });43 });
6244
209 });191 });
210});192});
211193
212describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {
213 let alice: IKeyringPair;
214 let bob: IKeyringPair;
215
216 before(async () => {
217 await usingApi(async (api, privateKeyWrapper) => {
218 alice = privateKeyWrapper('//Alice');
219 bob = privateKeyWrapper('//Bob');
220 });
221 });
222
223 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
224 await usingApi(async (api: ApiPromise) => {
225 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'data', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
226 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
227 expect(itemsListIndexBefore).to.be.equal(0);
228 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
229 const args = [
230 {NFT: {properties: [{key: 'data', value: 'v1'}]}},
231 {NFT: {properties: [{key: 'data', value: 'v2'}]}},
232 {NFT: {properties: [{key: 'data', value: 'v3'}]}},
233 ];
234 const createMultipleItemsTx = api.tx.unique
235 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
236 await submitTransactionAsync(bob, createMultipleItemsTx);
237 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
238 expect(itemsListIndexAfter).to.be.equal(3);
239
240 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));
241 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));
242 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));
243
244 expect((await getTokenProperties(api, collectionId, 1, ['data']))[0].value).to.be.equal('v1');
245 expect((await getTokenProperties(api, collectionId, 2, ['data']))[0].value).to.be.equal('v2');
246 expect((await getTokenProperties(api, collectionId, 3, ['data']))[0].value).to.be.equal('v3');
247 });
248 });
249
250 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
251 await usingApi(async (api: ApiPromise) => {
252 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
253 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
254 expect(itemsListIndexBefore).to.be.equal(0);
255 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
256 const args = [
257 {Fungible: {value: 1}},
258 {Fungible: {value: 2}},
259 {Fungible: {value: 3}},
260 ];
261 const createMultipleItemsTx = api.tx.unique
262 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
263 await submitTransactionAsync(bob, createMultipleItemsTx);
264 const token1Data = await getBalance(api, collectionId, bob.address, 0);
265
266 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3
267 });
268 });
269
270 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async function() {
271 await requirePallets(this, [Pallets.ReFungible]);
272
273 await usingApi(async (api: ApiPromise) => {
274 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
275 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
276 expect(itemsListIndexBefore).to.be.equal(0);
277 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
278 const args = [
279 {ReFungible: {pieces: 1}},
280 {ReFungible: {pieces: 2}},
281 {ReFungible: {pieces: 3}},
282 ];
283 const createMultipleItemsTx = api.tx.unique
284 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);
285 await submitTransactionAsync(bob, createMultipleItemsTx);
286 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
287 expect(itemsListIndexAfter).to.be.equal(3);
288
289 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);
290 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(2n);
291 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(3n);
292 });
293 });
294});
295
296describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {194describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
297 let alice: IKeyringPair;195 let alice: IKeyringPair;
421 });319 });
422320
423 it('Create tokens with different data limits <> maximum data limit', async () => {321 it('Create tokens with different data limits <> maximum data limit', async () => {
424 await usingApi(async (api: ApiPromise) => {322 await usingPlaygrounds(async (helper) => {
425 const collectionId = await createCollectionWithPropsExpectSuccess({323 const collection = await helper.nft.mintCollection(alice, {
426 propPerm: [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}],324 name: 'name',
325 description: 'descr',
326 tokenPrefix: 'COL',
327 tokenPropertyPermissions: [
328 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},
329 ],
427 });330 });
428 const args = [331 const args = [
429 {NFT: {properties: [{key: 'key', value: 'A'}]}},332 {properties: [{key: 'data', value: 'A'}]},
430 {NFT: {properties: [{key: 'key', value: 'B'.repeat(32769)}]}},333 {properties: [{key: 'data', value: 'B'.repeat(32769)}]},
431 ];334 ];
432 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);335 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
433 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;336 await expect(mintTx()).to.be.rejected;
434 });337 });
435 });338 });
436339
437 it('Fails when minting tokens exceeds collectionLimits amount', async () => {340 it('Fails when minting tokens exceeds collectionLimits amount', async () => {
438 await usingApi(async (api) => {341 await usingPlaygrounds(async (helper) => {
439 const collectionId = await createCollectionExpectSuccess();342 const collection = await helper.nft.mintCollection(alice, {
440 await setCollectionLimitsExpectSuccess(alice, collectionId, {343 name: 'name',
344 description: 'descr',
345 tokenPrefix: 'COL',
346 tokenPropertyPermissions: [
347 {key: 'data', permission: {tokenOwner: true, mutable: true, collectionAdmin: true}},
441 tokenLimit: 1,348 ],
349 limits: {
350 tokenLimit: 1,
351 },
442 });352 });
443 const args = [353 const args = [
444 {NFT: {}},354 {},
445 {NFT: {}},355 {},
446 ];356 ];
447 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);357 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
448 await expect(executeTransaction(api, alice, createMultipleItemsTx)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);358 await expect(mintTx()).to.be.rejected;
449 });359 });
450 });360 });
451361
452 it('User doesnt have editing rights', async () => {362 it('User doesnt have editing rights', async () => {
453 await usingApi(async (api: ApiPromise) => {363 await usingPlaygrounds(async (helper) => {
454 const collectionId = await createCollectionWithPropsExpectSuccess({364 const collection = await helper.nft.mintCollection(alice, {
455 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}],365 name: 'name',
366 description: 'descr',
367 tokenPrefix: 'COL',
368 tokenPropertyPermissions: [
369 {key: 'data', permission: {tokenOwner: false, mutable: true, collectionAdmin: false}},
370 ],
456 });371 });
457 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
458 expect(itemsListIndexBefore).to.be.equal(0);
459 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
460 const args = [372 const args = [
461 {NFT: {properties: [{key: 'key1', value: 'v2'}]}},373 {properties: [{key: 'data', value: 'A'}]},
462 {NFT: {}},
463 {NFT: {}},
464 ];374 ];
465
466 const tx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(bob.address), args);375 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
467 await expect(executeTransaction(api, bob, tx)).to.be.rejectedWith(/common\.NoPermission/);376 await expect(mintTx()).to.be.rejected;
468 });377 });
469 });378 });
470379
471 it('Adding property without access rights', async () => {380 it('Adding property without access rights', async () => {
472 await usingApi(async (api: ApiPromise) => {381 await usingPlaygrounds(async (helper) => {
473 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'k', value: 'v1'}]});382 const collection = await helper.nft.mintCollection(alice, {
383 name: 'name',
384 description: 'descr',
385 tokenPrefix: 'COL',
386 properties: [
387 {
388 key: 'data',
389 value: 'v',
474 const itemsListIndexBefore = await getLastTokenId(api, collectionId);390 },
475 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);391 ],
476 expect(itemsListIndexBefore).to.be.equal(0);392 });
477 const args = [{NFT: {properties: [{key: 'k', value: 'v'}]}},393 const args = [
394 {properties: [{key: 'data', value: 'A'}]},
478 {NFT: {}},395 ];
479 {NFT: {}}];
480
481 const tx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(bob.address), args);396 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
482 await expect(executeTransaction(api, bob, tx)).to.be.rejectedWith(/common\.NoPermission/);397 await expect(mintTx()).to.be.rejected;
483 });398 });
484 });399 });
485400
486 it('Adding more than 64 prps', async () => {401 it('Adding more than 64 prps', async () => {
487 await usingApi(async (api: ApiPromise) => {402 await usingPlaygrounds(async (helper) => {
488 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];403 const collection = await helper.nft.mintCollection(alice, {
489 for (let i = 0; i < 65; i++) {
490 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});
491 }404 name: 'name',
492
493 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
494
495 const tx1 = api.tx.unique.setTokenPropertyPermissions(collectionId, propPerms);405 description: 'descr',
496 await expect(executeTransaction(api, alice, tx1)).to.be.rejectedWith(/common\.PropertyLimitReached/);406 tokenPrefix: 'COL',
497
498 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
499 expect(itemsListIndexBefore).to.be.equal(0);407 });
500 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
501
502 const prps = [];408 const prps = [];
503409
506 }412 }
507413
508 const args = [414 const args = [
509 {NFT: {properties: prps}},415 {properties: prps},
510 {NFT: {properties: prps}},416 {properties: prps},
511 {NFT: {properties: prps}},417 {properties: prps},
512 ];418 ];
513419
514 // there are no permissions, but will fail anyway because of too much weight for a block420 const mintTx = async () => helper.nft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, args);
515 const tx2 = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
516 await expect(submitTransactionExpectFailAsync(alice, tx2)).to.be.rejected;
517 });
518 });
519
520 it('Trying to add bigger property than allowed', async () => {
521 await usingApi(async (api: ApiPromise) => {
522 const collectionId = await createCollectionWithPropsExpectSuccess({
523 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}],
524 });
525 const itemsListIndexBefore = await getLastTokenId(api, collectionId);
526 expect(itemsListIndexBefore).to.be.equal(0);
527 const args = [{NFT: {properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},
528 {NFT: {properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},
529 {NFT: {properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}}];
530
531 const tx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);
532 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);421 await expect(mintTx()).to.be.rejected;
533 });422 });
534 });423 });
535});424});