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

difftreelog

source

tests/src/setPermissions.test.ts4.9 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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';2021describe('Integration Test: Set Permissions', () => {22  let alice: IKeyringPair;23  let bob: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = await privateKey({url: import.meta.url});28      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);29    });30  });3132  itSub('can all be enabled twice', async ({helper}) => {33    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-1', tokenPrefix: 'SP'});34    expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');3536    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});37    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});3839    const permissions = (await collection.getData())?.raw.permissions;40    expect(permissions).to.be.deep.equal({41      access: 'AllowList',42      mintMode: true,43      nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]},44    });45  });4647  itSub('can all be disabled twice', async ({helper}) => {48    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});49    expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');5051    await collection.setPermissions(alice, {access: 'AllowList', nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]}});52    expect((await collection.getData())?.raw.permissions).to.be.deep.equal({53      access: 'AllowList',54      mintMode: false,55      nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]},56    });5758    await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});59    await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});60    expect((await collection.getData())?.raw.permissions).to.be.deep.equal({61      access: 'Normal',62      mintMode: false,63      nesting: {collectionAdmin: false, tokenOwner: false, restricted: null},64    });65  });6667  itSub('collection admin can set permissions', async ({helper}) => {68    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});69    await collection.addAdmin(alice, {Substrate: bob.address});70    await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});7172    expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');73    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);74  });75});7677describe('Negative Integration Test: Set Permissions', () => {78  let alice: IKeyringPair;79  let bob: IKeyringPair;8081  before(async () => {82    await usingPlaygrounds(async (helper, privateKey) => {83      const donor = await privateKey({url: import.meta.url});84      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);85    });86  });8788  itSub('fails on not existing collection', async ({helper}) => {89    const collectionId = NON_EXISTENT_COLLECTION_ID;90    await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))91      .to.be.rejectedWith(/common\.CollectionNotFound/);92  });9394  itSub('fails on removed collection', async ({helper}) => {95    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-1', tokenPrefix: 'SP'});96    await collection.burn(alice);9798    await expect(collection.setPermissions(alice, {access: 'AllowList', mintMode: true}))99      .to.be.rejectedWith(/common\.CollectionNotFound/);100  });101102  itSub('fails when non-owner tries to set permissions', async ({helper}) => {103    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-2', tokenPrefix: 'SP'});104105    await expect(collection.setPermissions(bob, {access: 'AllowList', mintMode: true}))106      .to.be.rejectedWith(/common\.NoPermission/);107  });108});