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
--- a/tests/package.json
+++ b/tests/package.json
@@ -38,7 +38,7 @@
     "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
     "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
     "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
-    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",
+    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",
     "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
     "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
     "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
addedtests/src/getPropertiesRpc.test.tsdiffbeforeafterboth
after · tests/src/getPropertiesRpc.test.ts
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 {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from './util/playgrounds';19import {UniqueHelper, UniqueBaseCollection, UniqueNFTCollection, UniqueNFToken} from './util/playgrounds/unique';2021const collectionProps = [22  {key: 'col-0', value: 'col-0-value'},23  {key: 'col-1', value: 'col-1-value'},24];2526const tokenProps = [27  {key: 'tok-0', value: 'tok-0-value'},28  {key: 'tok-1', value: 'tok-1-value'},29];3031const tokPropPermission = {32  mutable: false,33  tokenOwner: true,34  collectionAdmin: false,35};3637const tokenPropPermissions = [38  {39    key: 'tok-0',40    permission: tokPropPermission,41  },42  {43    key: 'tok-1',44    permission: tokPropPermission,45  },46];4748describe('query properties RPC', () => {49  let alice: IKeyringPair;5051  const mintCollection = async (helper: UniqueHelper) => {52    return await helper.nft.mintCollection(alice, {53      tokenPrefix: 'prps',54      properties: collectionProps,55      tokenPropertyPermissions: tokenPropPermissions,56    });57  };5859  const mintToken = async (collection: UniqueNFTCollection) => {60    return await collection.mintToken(alice, {Substrate: alice.address}, tokenProps);61  };626364  before(async () => {65    await usingPlaygrounds(async (_, privateKey) => {66      alice = privateKey('//Alice');67    });68  });6970  itSub('query empty collection key set', async ({helper}) => {71    const collection = await mintCollection(helper);72    const props = await collection.getProperties([]);73    expect(props).to.be.empty;74  });7576  itSub('query empty token key set', async ({helper}) => {77    const collection = await mintCollection(helper);78    const token = await mintToken(collection);79    const props = await token.getProperties([]);80    expect(props).to.be.empty;81  });8283  itSub('query empty token key permissions set', async ({helper}) => {84    const collection = await mintCollection(helper);85    const propPermissions = await collection.getPropertyPermissions([]);86    expect(propPermissions).to.be.empty;87  });8889  itSub('query all collection props by null arg', async ({helper}) => {90    const collection = await mintCollection(helper);91    const props = await collection.getProperties(null);92    expect(props).to.be.deep.equal(collectionProps);93  });9495  itSub('query all token props by null arg', async ({helper}) => {96    const collection = await mintCollection(helper);97    const token = await mintToken(collection);98    const props = await token.getProperties(null);99    expect(props).to.be.deep.equal(tokenProps);100  });101102  itSub('query empty token key permissions by null arg', async ({helper}) => {103    const collection = await mintCollection(helper);104    const propPermissions = await collection.getPropertyPermissions(null);105    expect(propPermissions).to.be.deep.equal(tokenPropPermissions);106  });107108  itSub('query all collection props by undefined arg', async ({helper}) => {109    const collection = await mintCollection(helper);110    const props = await collection.getProperties();111    expect(props).to.be.deep.equal(collectionProps);112  });113114  itSub('query all token props by undefined arg', async ({helper}) => {115    const collection = await mintCollection(helper);116    const token = await mintToken(collection);117    const props = await token.getProperties();118    expect(props).to.be.deep.equal(tokenProps);119  });120121  itSub('query empty token key permissions by undefined arg', async ({helper}) => {122    const collection = await mintCollection(helper);123    const propPermissions = await collection.getPropertyPermissions();124    expect(propPermissions).to.be.deep.equal(tokenPropPermissions);125  });126});
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);
   }