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
--- /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
926 * @example getProperties(1219, ['location', 'date', 'time', 'isParadise']);926 * @example getProperties(1219, ['location', 'date', 'time', 'isParadise']);
927 * @returns array of key-value pairs927 * @returns array of key-value pairs
928 */928 */
929 async getProperties(collectionId: number, propertyKeys: string[] | null = null): Promise<IProperty[]> {929 async getProperties(collectionId: number, propertyKeys?: string[] | null): Promise<IProperty[]> {
930 return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, ...(propertyKeys === null ? [] : [propertyKeys])])).toHuman();930 return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, propertyKeys])).toHuman();
931 }931 }
932932
933 /**933 /**
1208 * @example getTokenProperties(1219, ['location', 'date', 'time', 'isParadise']);1208 * @example getTokenProperties(1219, ['location', 'date', 'time', 'isParadise']);
1209 * @returns array of key-value pairs1209 * @returns array of key-value pairs
1210 */1210 */
1211 async getTokenProperties(collectionId: number, tokenId: number, propertyKeys: string[] | null = null): Promise<IProperty[]> {1211 async getTokenProperties(collectionId: number, tokenId: number, propertyKeys?: string[] | null): Promise<IProperty[]> {
1212 return (await this.helper.callRpc('api.rpc.unique.tokenProperties', [collectionId, tokenId, ...(propertyKeys === null ? [] : [propertyKeys])])).toHuman();1212 return (await this.helper.callRpc('api.rpc.unique.tokenProperties', [collectionId, tokenId, propertyKeys])).toHuman();
1213 }1213 }
12141214
1215 /**1215 /**
2265 return await this.helper.collection.getEffectiveLimits(this.collectionId);2265 return await this.helper.collection.getEffectiveLimits(this.collectionId);
2266 }2266 }
22672267
2268 async getProperties(propertyKeys: string[] | null = null) {2268 async getProperties(propertyKeys?: string[] | null) {
2269 return await this.helper.collection.getProperties(this.collectionId, propertyKeys);2269 return await this.helper.collection.getProperties(this.collectionId, propertyKeys);
2270 }2270 }
22712271
2364 return await this.helper.nft.getPropertyPermissions(this.collectionId, propertyKeys);2364 return await this.helper.nft.getPropertyPermissions(this.collectionId, propertyKeys);
2365 }2365 }
23662366
2367 async getTokenProperties(tokenId: number, propertyKeys: string[] | null = null) {2367 async getTokenProperties(tokenId: number, propertyKeys?: string[] | null) {
2368 return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);2368 return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
2369 }2369 }
23702370
2455 return await this.helper.rft.getPropertyPermissions(this.collectionId, propertyKeys);2455 return await this.helper.rft.getPropertyPermissions(this.collectionId, propertyKeys);
2456 }2456 }
24572457
2458 async getTokenProperties(tokenId: number, propertyKeys: string[] | null = null) {2458 async getTokenProperties(tokenId: number, propertyKeys?: string[] | null) {
2459 return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);2459 return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
2460 }2460 }
24612461
2567 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);2567 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);
2568 }2568 }
25692569
2570 async getProperties(propertyKeys: string[] | null = null) {2570 async getProperties(propertyKeys?: string[] | null) {
2571 return await this.collection.getTokenProperties(this.tokenId, propertyKeys);2571 return await this.collection.getTokenProperties(this.tokenId, propertyKeys);
2572 }2572 }
25732573