git.delta.rocks / unique-network / refs/commits / 51bba919a075

difftreelog

CORE-410 Adapt collection properties tests for ReFungible collections

Trubnikov Sergey2022-06-29parent: #73d9a3e.patch.diff
in: master

4 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -833,7 +833,7 @@
 				),
 			);
 			<T as Config>::Currency::settle(
-				&owner.as_sub(),
+				owner.as_sub(),
 				imbalance,
 				WithdrawReasons::TRANSFER,
 				ExistenceRequirement::KeepAlive,
modifiedtests/src/nesting/properties.test.tsdiffbeforeafterboth
2import usingApi, {executeTransaction} from '../substrate/substrate-api';2import usingApi, {executeTransaction} from '../substrate/substrate-api';
3import {3import {
4 addCollectionAdminExpectSuccess,4 addCollectionAdminExpectSuccess,
5 CollectionMode,
5 createCollectionExpectSuccess,6 createCollectionExpectSuccess,
6 setCollectionPermissionsExpectSuccess,7 setCollectionPermissionsExpectSuccess,
7 createItemExpectSuccess,8 createItemExpectSuccess,
23 });24 });
24 });25 });
2526
26 it('Makes sure collectionById supplies required fields', async () => {27 async function testMakeSureSuppliesRequired(mode: CollectionMode) {
27 await usingApi(async api => {28 await usingApi(async api => {
28 const collectionId = await createCollectionExpectSuccess();29 const collectionId = await createCollectionExpectSuccess({mode: mode});
2930
30 const collectionOption = await api.rpc.unique.collectionById(collectionId);31 const collectionOption = await api.rpc.unique.collectionById(collectionId);
31 expect(collectionOption.isSome).to.be.true;32 expect(collectionOption.isSome).to.be.true;
57 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);58 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);
58 expect(collection.properties.toHuman()).to.be.deep.equal(collectionProperties);59 expect(collection.properties.toHuman()).to.be.deep.equal(collectionProperties);
59 });60 });
60 });61 }
62
63 it('Makes sure collectionById supplies required fields for NFT', async () => {
64 await testMakeSureSuppliesRequired({type: 'NFT'});
65 });
66
67 it('Makes sure collectionById supplies required fields for ReFungible', async () => {
68 await testMakeSureSuppliesRequired({type: 'ReFungible'});
69 });
61});70});
6271
63// ---------- COLLECTION PROPERTIES72// ---------- COLLECTION PROPERTIES
80 });89 });
90
8191
82 it('Sets properties for a collection', async () => {92 async function testSetsPropertiesForCollection(mode: string) {
83 await usingApi(async api => {93 await usingApi(async api => {
84 const events = await executeTransaction(api, bob, api.tx.unique.createCollectionEx({mode: 'NFT'}));94 const events = await executeTransaction(api, bob, api.tx.unique.createCollectionEx({mode: mode}));
85 const {collectionId} = getCreateCollectionResult(events);95 const {collectionId} = getCreateCollectionResult(events);
8696
87 // As owner97 // As owner
106 {key: 'black_hole', value: ''},116 {key: 'black_hole', value: ''},
107 ]);117 ]);
108 });118 });
109 });119 }
120 it('Sets properties for a NFT collection', async () => {
121 await testSetsPropertiesForCollection('NFT');
122 });
123 it('Sets properties for a ReFungible collection', async () => {
124 await testSetsPropertiesForCollection('ReFungible');
125 });
110126
111 it('Check valid names for collection properties keys', async () => {127 async function testCheckValidNames(mode: string) {
112 await usingApi(async api => {128 await usingApi(async api => {
113 const events = await executeTransaction(api, bob, api.tx.unique.createCollectionEx({mode: 'NFT'}));129 const events = await executeTransaction(api, bob, api.tx.unique.createCollectionEx({mode: mode}));
114 const {collectionId} = getCreateCollectionResult(events);130 const {collectionId} = getCreateCollectionResult(events);
115131
116 // alpha symbols132 // alpha symbols
158 {key: 'build.rs', value: ''},174 {key: 'build.rs', value: ''},
159 ]);175 ]);
160 });176 });
161 });177 }
178 it('Check valid names for NFT collection properties keys', async () => {
179 await testCheckValidNames('NFT');
180 });
181 it('Check valid names for ReFungible collection properties keys', async () => {
182 await testCheckValidNames('ReFungible');
183 });
162184
163 it('Changes properties of a collection', async () => {185 async function testChangesProperties(mode: CollectionMode) {
164 await usingApi(async api => {186 await usingApi(async api => {
165 const collection = await createCollectionExpectSuccess();187 const collection = await createCollectionExpectSuccess({mode: mode});
166188
167 await expect(executeTransaction(189 await expect(executeTransaction(
168 api, 190 api,
183 {key: 'black_hole', value: 'LIGO'},205 {key: 'black_hole', value: 'LIGO'},
184 ]);206 ]);
185 });207 });
186 });208 }
209 it('Changes properties of a NFT collection', async () => {
210 await testChangesProperties({type: 'NFT'});
211 });
212 it('Changes properties of a ReFungible collection', async () => {
213 await testChangesProperties({type: 'ReFungible'});
214 });
187215
188 it('Deletes properties of a collection', async () => {216 async function testDeleteProperties(mode: CollectionMode) {
189 await usingApi(async api => {217 await usingApi(async api => {
190 const collection = await createCollectionExpectSuccess();218 const collection = await createCollectionExpectSuccess({mode: mode});
191219
192 await expect(executeTransaction(220 await expect(executeTransaction(
193 api, 221 api,
206 {key: 'black_hole', value: 'LIGO'},234 {key: 'black_hole', value: 'LIGO'},
207 ]);235 ]);
208 });236 });
209 });237 }
238 it('Deletes properties of a NFT collection', async () => {
239 await testDeleteProperties({type: 'NFT'});
240 });
241 it('Deletes properties of a ReFungible collection', async () => {
242 await testDeleteProperties({type: 'ReFungible'});
243 });
210});244});
211245
212describe('Negative Integration Test: Collection Properties', () => {246describe('Negative Integration Test: Collection Properties', () => {
217 });251 });
218 });252 });
219 253
220 it('Fails to set properties in a collection if not its onwer/administrator', async () => {254 async function testFailsSetPropertiesIfNotOwnerOrAdmin(mode: CollectionMode) {
221 await usingApi(async api => {255 await usingApi(async api => {
222 const collection = await createCollectionExpectSuccess();256 const collection = await createCollectionExpectSuccess({mode: mode});
223257
224 await expect(executeTransaction(258 await expect(executeTransaction(
225 api, 259 api,
231 expect(properties.map).to.be.empty;265 expect(properties.map).to.be.empty;
232 expect(properties.consumedSpace).to.equal(0);266 expect(properties.consumedSpace).to.equal(0);
233 });267 });
234 });268 }
235 269 it('Fails to set properties in a NFT collection if not its onwer/administrator', async () => {
270 await testFailsSetPropertiesIfNotOwnerOrAdmin({type: 'NFT'});
271 });
272 it('Fails to set properties in a ReFungible collection if not its onwer/administrator', async () => {
273 await testFailsSetPropertiesIfNotOwnerOrAdmin({type: 'ReFungible'});
274 });
275
236 it('Fails to set properties that exceed the limits', async () => {276 async function testFailsSetPropertiesThatExeedLimits(mode: CollectionMode) {
237 await usingApi(async api => {277 await usingApi(async api => {
238 const collection = await createCollectionExpectSuccess();278 const collection = await createCollectionExpectSuccess({mode: mode});
239 const spaceLimit = (await api.query.common.collectionProperties(collection)).toJSON().spaceLimit as number; 279 const spaceLimit = (await api.query.common.collectionProperties(collection)).toJSON().spaceLimit as number;
240280
241 // Mute the general tx parsing error, too many bytes to process281 // Mute the general tx parsing error, too many bytes to process
263 properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();303 properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();
264 expect(properties).to.be.empty;304 expect(properties).to.be.empty;
265 });305 });
266 });306 }
267 307 it('Fails to set properties that exceed the limits (NFT)', async () => {
308 await testFailsSetPropertiesThatExeedLimits({type: 'NFT'});
309 });
310 it('Fails to set properties that exceed the limits (ReFungible)', async () => {
311 await testFailsSetPropertiesThatExeedLimits({type: 'ReFungible'});
312 });
313
268 it('Fails to set more properties than it is allowed', async () => {314 async function testFailsSetMorePropertiesThanAllowed(mode: CollectionMode) {
269 await usingApi(async api => {315 await usingApi(async api => {
270 const collection = await createCollectionExpectSuccess();316 const collection = await createCollectionExpectSuccess({mode: mode});
271317
272 const propertiesToBeSet = [];318 const propertiesToBeSet = [];
273 for (let i = 0; i < 65; i++) {319 for (let i = 0; i < 65; i++) {
287 expect(properties.map).to.be.empty;333 expect(properties.map).to.be.empty;
288 expect(properties.consumedSpace).to.equal(0);334 expect(properties.consumedSpace).to.equal(0);
289 });335 });
290 });336 }
291337 it('Fails to set more properties than it is allowed (NFT)', async () => {
338 await testFailsSetMorePropertiesThanAllowed({type: 'NFT'});
339 });
340 it('Fails to set more properties than it is allowed (ReFungible)', async () => {
341 await testFailsSetMorePropertiesThanAllowed({type: 'ReFungible'});
342 });
343
292 it('Fails to set properties with invalid names', async () => {344 async function testFailsSetPropertiesWithInvalidNames(mode: CollectionMode) {
293 await usingApi(async api => {345 await usingApi(async api => {
294 const collection = await createCollectionExpectSuccess();346 const collection = await createCollectionExpectSuccess({mode: mode});
295347
296 const invalidProperties = [348 const invalidProperties = [
297 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],349 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],
336 ), `on trying to delete the non-existent badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);388 ), `on trying to delete the non-existent badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
337 }389 }
338 });390 });
339 });391 }
392 it('Fails to set properties with invalid names (NFT)', async () => {
393 await testFailsSetPropertiesWithInvalidNames({type: 'NFT'});
394 });
395 it('Fails to set properties with invalid names (ReFungible)', async () => {
396 await testFailsSetPropertiesWithInvalidNames({type: 'ReFungible'});
397 });
340});398});
341399
342// ---------- ACCESS RIGHTS400// ---------- ACCESS RIGHTS
357 });415 });
358 });416 });
359 417
360 it('Sets access rights to properties of a collection', async () => {418 async function testSetsAccessRightsToProperties(mode: CollectionMode) {
361 await usingApi(async api => {419 await usingApi(async api => {
362 const collection = await createCollectionExpectSuccess();420 const collection = await createCollectionExpectSuccess({mode: mode});
363421
364 await expect(executeTransaction(422 await expect(executeTransaction(
365 api, 423 api,
381 {key: 'mindgame', permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},439 {key: 'mindgame', permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},
382 ]);440 ]);
383 });441 });
384 });442 }
385 443 it('Sets access rights to properties of a collection (NFT)', async () => {
444 await testSetsAccessRightsToProperties({type: 'NFT'});
445 });
446 it('Sets access rights to properties of a collection (ReFungible)', async () => {
447 await testSetsAccessRightsToProperties({type: 'ReFungible'});
448 });
449
386 it('Changes access rights to properties of a collection', async () => {450 async function testChangesAccessRightsToProperty(mode: CollectionMode) {
387 await usingApi(async api => {451 await usingApi(async api => {
388 const collection = await createCollectionExpectSuccess();452 const collection = await createCollectionExpectSuccess({mode: mode});
389453
390 await expect(executeTransaction(454 await expect(executeTransaction(
391 api, 455 api,
404 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},468 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
405 ]);469 ]);
406 });470 });
407 });471 }
472 it('Changes access rights to properties of a NFT collection', async () => {
473 await testChangesAccessRightsToProperty({type: 'NFT'});
474 });
475 it('Changes access rights to properties of a ReFungible collection', async () => {
476 await testChangesAccessRightsToProperty({type: 'ReFungible'});
477 });
408});478});
409479
410describe('Negative Integration Test: Access Rights to Token Properties', () => {480describe('Negative Integration Test: Access Rights to Token Properties', () => {
415 });485 });
416 });486 });
417487
418 it('Prevents from setting access rights to properties of a collection if not an onwer/admin', async () => {488 async function testPreventsFromSettingAccessRightsNotAdminOrOwner(mode: CollectionMode) {
419 await usingApi(async api => {489 await usingApi(async api => {
420 const collection = await createCollectionExpectSuccess();490 const collection = await createCollectionExpectSuccess({mode: mode});
421491
422 await expect(executeTransaction(492 await expect(executeTransaction(
423 api, 493 api,
428 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();498 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();
429 expect(propertyRights).to.be.empty;499 expect(propertyRights).to.be.empty;
430 });500 });
431 });501 }
502 it('Prevents from setting access rights to properties of a NFT collection if not an onwer/admin', async () => {
503 await testPreventsFromSettingAccessRightsNotAdminOrOwner({type: 'NFT'});
504 });
505 it('Prevents from setting access rights to properties of a ReFungible collection if not an onwer/admin', async () => {
506 await testPreventsFromSettingAccessRightsNotAdminOrOwner({type: 'ReFungible'});
507 });
432508
433 it('Prevents from adding too many possible properties', async () => {509 async function testPreventFromAddingTooManyPossibleProperties(mode: CollectionMode) {
434 await usingApi(async api => {510 await usingApi(async api => {
435 const collection = await createCollectionExpectSuccess();511 const collection = await createCollectionExpectSuccess({mode: mode});
436512
437 const constitution = [];513 const constitution = [];
438 for (let i = 0; i < 65; i++) {514 for (let i = 0; i < 65; i++) {
451 const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();527 const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();
452 expect(propertyRights).to.be.empty;528 expect(propertyRights).to.be.empty;
453 });529 });
454 });530 }
531 it('Prevents from adding too many possible properties (NFT)', async () => {
532 await testPreventFromAddingTooManyPossibleProperties({type: 'NFT'});
533 });
534 it('Prevents from adding too many possible properties (ReFungible)', async () => {
535 await testPreventFromAddingTooManyPossibleProperties({type: 'ReFungible'});
536 });
455537
456 it('Prevents access rights to be modified if constant', async () => {538 async function testPreventAccessRightsModifiedIfConstant(mode: CollectionMode) {
457 await usingApi(async api => {539 await usingApi(async api => {
458 const collection = await createCollectionExpectSuccess();540 const collection = await createCollectionExpectSuccess({mode: mode});
459541
460 await expect(executeTransaction(542 await expect(executeTransaction(
461 api, 543 api,
474 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},556 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},
475 ]);557 ]);
476 });558 });
477 });559 }
560 it('Prevents access rights to be modified if constant (NFT)', async () => {
561 await testPreventAccessRightsModifiedIfConstant({type: 'NFT'});
562 });
563 it('Prevents access rights to be modified if constant (ReFungible)', async () => {
564 await testPreventAccessRightsModifiedIfConstant({type: 'ReFungible'});
565 });
478566
479 it('Prevents adding properties with invalid names', async () => {567 async function testPreventsAddingPropertiesWithInvalidNames(mode: CollectionMode) {
480 await usingApi(async api => {568 await usingApi(async api => {
481 const collection = await createCollectionExpectSuccess();569 const collection = await createCollectionExpectSuccess({mode: mode});
482570
483 const invalidProperties = [571 const invalidProperties = [
484 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],572 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],
516 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},604 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},
517 ]);605 ]);
518 });606 });
519 });607 }
608 it('Prevents adding properties with invalid names (NFT)', async () => {
609 await testPreventsAddingPropertiesWithInvalidNames({type: 'NFT'});
610 });
611 it('Prevents adding properties with invalid names (ReFungible)', async () => {
612 await testPreventsAddingPropertiesWithInvalidNames({type: 'ReFungible'});
613 });
520});614});
521615
522// ---------- TOKEN PROPERTIES616// ---------- TOKEN PROPERTIES
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -211,35 +211,4 @@
       expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);
     });
   });
-
-  it('Set properties for exist collection', async () => {
-    await usingApi(async api => {
-      const collectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},
-      });
-
-      const properties = [
-        {key: 'key1', value: 'val1'},
-        {key: 'key2', value: 'val2'},
-      ];
-      await expect(executeTransaction(
-        api, 
-        alice, 
-        api.tx.unique.setCollectionProperties(collectionId, properties), 
-      )).to.not.be.rejected;
-
-      const propertyPermissions = [
-        {key: 'key1', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},
-        {key: 'key2', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},
-      ];
-      await expect(executeTransaction(
-        api, 
-        alice, 
-        api.tx.unique.setTokenPropertyPermissions(collectionId, propertyPermissions), 
-      )).to.not.be.rejected;
-
-      const collection = (await getDetailedCollectionInfo(api, collectionId))!;
-      expect(collection.properties.toHuman()).to.be.deep.equal(properties);
-      expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);
-    });
-  });
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -284,7 +284,7 @@
   type: 'ReFungible';
 }
 
-type CollectionMode = Nft | Fungible | ReFungible;
+export type CollectionMode = Nft | Fungible | ReFungible;
 
 export type Property = {
   key: any,