From 3ce311c312ce436d8fc3c24aca4c19cc6746786b Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 29 Sep 2022 15:46:10 +0000 Subject: [PATCH] test: query properties rpc --- --- 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", --- /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 . + +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); + }); +}); --- 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 { - return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, ...(propertyKeys === null ? [] : [propertyKeys])])).toHuman(); + async getProperties(collectionId: number, propertyKeys?: string[] | null): Promise { + 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 { - 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 { + 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); } -- gitstuff