git.delta.rocks / unique-network / refs/commits / 3ce311c312ce

difftreelog

test query properties rpc

Daniel Shiposha2022-09-29parent: #e899eee.patch.diff
in: master

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
38 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",38 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
39 "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",39 "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
40 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",40 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
41 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",41 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",
42 "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",42 "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
43 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",43 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
44 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",44 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
addedtests/src/getPropertiesRpc.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/getPropertiesRpc.test.ts
@@ -0,0 +1,126 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from './util/playgrounds';
+import {UniqueHelper, UniqueBaseCollection, UniqueNFTCollection, UniqueNFToken} from './util/playgrounds/unique';
+
+const collectionProps = [
+  {key: 'col-0', value: 'col-0-value'},
+  {key: 'col-1', value: 'col-1-value'},
+];
+
+const tokenProps = [
+  {key: 'tok-0', value: 'tok-0-value'},
+  {key: 'tok-1', value: 'tok-1-value'},
+];
+
+const tokPropPermission = {
+  mutable: false,
+  tokenOwner: true,
+  collectionAdmin: false,
+};
+
+const tokenPropPermissions = [
+  {
+    key: 'tok-0',
+    permission: tokPropPermission,
+  },
+  {
+    key: 'tok-1',
+    permission: tokPropPermission,
+  },
+];
+
+describe('query properties RPC', () => {
+  let alice: IKeyringPair;
+
+  const mintCollection = async (helper: UniqueHelper) => {
+    return await helper.nft.mintCollection(alice, {
+      tokenPrefix: 'prps',
+      properties: collectionProps,
+      tokenPropertyPermissions: tokenPropPermissions,
+    });
+  };
+
+  const mintToken = async (collection: UniqueNFTCollection) => {
+    return await collection.mintToken(alice, {Substrate: alice.address}, tokenProps);
+  };
+
+
+  before(async () => {
+    await usingPlaygrounds(async (_, privateKey) => {
+      alice = privateKey('//Alice');
+    });
+  });
+
+  itSub('query empty collection key set', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const props = await collection.getProperties([]);
+    expect(props).to.be.empty;
+  });
+
+  itSub('query empty token key set', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const token = await mintToken(collection);
+    const props = await token.getProperties([]);
+    expect(props).to.be.empty;
+  });
+
+  itSub('query empty token key permissions set', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const propPermissions = await collection.getPropertyPermissions([]);
+    expect(propPermissions).to.be.empty;
+  });
+
+  itSub('query all collection props by null arg', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const props = await collection.getProperties(null);
+    expect(props).to.be.deep.equal(collectionProps);
+  });
+
+  itSub('query all token props by null arg', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const token = await mintToken(collection);
+    const props = await token.getProperties(null);
+    expect(props).to.be.deep.equal(tokenProps);
+  });
+
+  itSub('query empty token key permissions by null arg', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const propPermissions = await collection.getPropertyPermissions(null);
+    expect(propPermissions).to.be.deep.equal(tokenPropPermissions);
+  });
+
+  itSub('query all collection props by undefined arg', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const props = await collection.getProperties();
+    expect(props).to.be.deep.equal(collectionProps);
+  });
+
+  itSub('query all token props by undefined arg', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const token = await mintToken(collection);
+    const props = await token.getProperties();
+    expect(props).to.be.deep.equal(tokenProps);
+  });
+
+  itSub('query empty token key permissions by undefined arg', async ({helper}) => {
+    const collection = await mintCollection(helper);
+    const propPermissions = await collection.getPropertyPermissions();
+    expect(propPermissions).to.be.deep.equal(tokenPropPermissions);
+  });
+});
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -926,8 +926,8 @@
    * @example getProperties(1219, ['location', 'date', 'time', 'isParadise']);
    * @returns array of key-value pairs
    */
-  async getProperties(collectionId: number, propertyKeys: string[] | null = null): Promise<IProperty[]> {
-    return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, ...(propertyKeys === null ? [] : [propertyKeys])])).toHuman();
+  async getProperties(collectionId: number, propertyKeys?: string[] | null): Promise<IProperty[]> {
+    return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, propertyKeys])).toHuman();
   }
 
   /**
@@ -1208,8 +1208,8 @@
    * @example getTokenProperties(1219, ['location', 'date', 'time', 'isParadise']);
    * @returns array of key-value pairs
    */
-  async getTokenProperties(collectionId: number, tokenId: number, propertyKeys: string[] | null = null): Promise<IProperty[]> {
-    return (await this.helper.callRpc('api.rpc.unique.tokenProperties', [collectionId, tokenId, ...(propertyKeys === null ? [] : [propertyKeys])])).toHuman();
+  async getTokenProperties(collectionId: number, tokenId: number, propertyKeys?: string[] | null): Promise<IProperty[]> {
+    return (await this.helper.callRpc('api.rpc.unique.tokenProperties', [collectionId, tokenId, propertyKeys])).toHuman();
   }
 
   /**
@@ -2265,7 +2265,7 @@
     return await this.helper.collection.getEffectiveLimits(this.collectionId);
   }
 
-  async getProperties(propertyKeys: string[] | null = null) {
+  async getProperties(propertyKeys?: string[] | null) {
     return await this.helper.collection.getProperties(this.collectionId, propertyKeys);
   }
 
@@ -2364,7 +2364,7 @@
     return await this.helper.nft.getPropertyPermissions(this.collectionId, propertyKeys);
   }
 
-  async getTokenProperties(tokenId: number, propertyKeys: string[] | null = null) {
+  async getTokenProperties(tokenId: number, propertyKeys?: string[] | null) {
     return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
   }
 
@@ -2455,7 +2455,7 @@
     return await this.helper.rft.getPropertyPermissions(this.collectionId, propertyKeys);
   }
 
-  async getTokenProperties(tokenId: number, propertyKeys: string[] | null = null) {
+  async getTokenProperties(tokenId: number, propertyKeys?: string[] | null) {
     return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
   }
 
@@ -2567,7 +2567,7 @@
     return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);
   }
 
-  async getProperties(propertyKeys: string[] | null = null) {
+  async getProperties(propertyKeys?: string[] | null) {
     return await this.collection.getTokenProperties(this.tokenId, propertyKeys);
   }