1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/playgrounds';19import {UniqueHelper, UniqueNFTCollection} 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 = await privateKey({filename: __filename});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});