git.delta.rocks / unique-network / refs/commits / ade4bc204310

difftreelog

source

js-packages/tests/src/getPropertiesRpc.test.ts5.5 KiBsourcehistory
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 type {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/index.js';19import {UniqueHelper, UniqueNFTCollection} from '@unique/playgrounds/src/unique.js';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) => await helper.nft.mintCollection(alice, {52    tokenPrefix: 'prps',53    properties: collectionProps,54    tokenPropertyPermissions: tokenPropPermissions,55  });5657  const mintToken = async (collection: UniqueNFTCollection) => await collection.mintToken(alice, {Substrate: alice.address}, tokenProps);585960  before(async () => {61    await usingPlaygrounds(async (_, privateKey) => {62      alice = await privateKey({url: import.meta.url});63    });64  });6566  itSub('query empty collection key set', async ({helper}) => {67    const collection = await mintCollection(helper);68    const props = await collection.getProperties([]);69    expect(props).to.be.empty;70  });7172  itSub('query empty token key set', async ({helper}) => {73    const collection = await mintCollection(helper);74    const token = await mintToken(collection);75    const props = await token.getProperties([]);76    expect(props).to.be.empty;77  });7879  itSub('query empty token key permissions set', async ({helper}) => {80    const collection = await mintCollection(helper);81    const propPermissions = await collection.getPropertyPermissions([]);82    expect(propPermissions).to.be.empty;83  });8485  itSub('query all collection props by null arg', async ({helper}) => {86    const collection = await mintCollection(helper);87    const props = await collection.getProperties(null);88    expect(props).to.be.deep.equal(collectionProps);89  });9091  itSub('query all token props by null arg', async ({helper}) => {92    const collection = await mintCollection(helper);93    const token = await mintToken(collection);94    const props = await token.getProperties(null);95    expect(props).to.be.deep.equal(tokenProps);96  });9798  itSub('query empty token key permissions by null arg', async ({helper}) => {99    const collection = await mintCollection(helper);100    const propPermissions = await collection.getPropertyPermissions(null);101    expect(propPermissions).to.be.deep.equal(tokenPropPermissions);102  });103104  itSub('query all collection props by undefined arg', async ({helper}) => {105    const collection = await mintCollection(helper);106    const props = await collection.getProperties();107    expect(props).to.be.deep.equal(collectionProps);108  });109110  itSub('query all token props by undefined arg', async ({helper}) => {111    const collection = await mintCollection(helper);112    const token = await mintToken(collection);113    const props = await token.getProperties();114    expect(props).to.be.deep.equal(tokenProps);115  });116117  itSub('query empty token key permissions by undefined arg', async ({helper}) => {118    const collection = await mintCollection(helper);119    const propPermissions = await collection.getPropertyPermissions();120    expect(propPermissions).to.be.deep.equal(tokenPropPermissions);121  });122});123124[125  {mode: 'nft' as const},126  {mode: 'rft' as const},127].map(testCase =>128  describe('negative properties', () => {129    let alice: IKeyringPair;130131    before(async () => {132      await usingPlaygrounds(async (_, privateKey) => {133        alice = await privateKey({url: import.meta.url});134      });135    });136137    itSub(`[${testCase.mode}] set token property for non-existent token`, async ({helper}) => {138      const collection = await helper[testCase.mode].mintCollection(alice);139      await collection.setTokenPropertyPermissions(alice, [{key: 'key', permission: {mutable: true, tokenOwner: true, collectionAdmin: true}}]);140      await expect(collection.setTokenProperties(alice, 1, [{key: 'key', value: 'value'}])).to.be.rejectedWith('common.TokenNotFound');141      expect(await collection.getTokenProperties(1, ['key'])).to.be.empty;142    });143144    itSub(`[${testCase.mode}] delete token property for non-existent token`, async ({helper}) => {145      const collection = await helper[testCase.mode].mintCollection(alice);146      await collection.setTokenPropertyPermissions(alice, [{key: 'key', permission: {mutable: true, tokenOwner: true, collectionAdmin: true}}]);147      await expect(collection.deleteTokenProperties(alice, 1, ['key'])).to.be.rejectedWith('common.TokenNotFound');148      expect(await collection.getTokenProperties(1, ['key'])).to.be.empty;149    });150  }));