git.delta.rocks / unique-network / refs/commits / 9f5b0cc75e11

difftreelog

source

tests/src/setPermissions.test.ts4.8 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';1920describe('Integration Test: Set Permissions', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;2324  before(async () => {25    await usingPlaygrounds(async (helper, privateKey) => {26      const donor = await privateKey({url: import.meta.url});27      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);28    });29  });3031  itSub('can all be enabled twice', async ({helper}) => {32    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-1', tokenPrefix: 'SP'});33    expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');3435    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});36    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]}});3738    const permissions = (await collection.getData())?.raw.permissions;39    expect(permissions).to.be.deep.equal({40      access: 'AllowList',41      mintMode: true,42      nesting: {collectionAdmin: true, tokenOwner: true, restricted: [1, 2]},43    });44  });4546  itSub('can all be disabled twice', async ({helper}) => {47    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});48    expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');4950    await collection.setPermissions(alice, {access: 'AllowList', nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]}});51    expect((await collection.getData())?.raw.permissions).to.be.deep.equal({52      access: 'AllowList',53      mintMode: false,54      nesting: {collectionAdmin: false, tokenOwner: true, restricted: [1, 2]},55    });5657    await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});58    await collection.setPermissions(alice, {access: 'Normal', mintMode: false, nesting: {}});59    expect((await collection.getData())?.raw.permissions).to.be.deep.equal({60      access: 'Normal',61      mintMode: false,62      nesting: {collectionAdmin: false, tokenOwner: false, restricted: null},63    });64  });6566  itSub('collection admin can set permissions', async ({helper}) => {67    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-2', tokenPrefix: 'SP'});68    await collection.addAdmin(alice, {Substrate: bob.address});69    await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});7071    expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');72    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);73  });74});7576describe('Negative Integration Test: Set Permissions', () => {77  let alice: IKeyringPair;78  let bob: IKeyringPair;7980  before(async () => {81    await usingPlaygrounds(async (helper, privateKey) => {82      const donor = await privateKey({url: import.meta.url});83      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);84    });85  });8687  itSub('fails on not existing collection', async ({helper}) => {88    const collectionId = (1 << 32) - 1;89    await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))90      .to.be.rejectedWith(/common\.CollectionNotFound/);91  });9293  itSub('fails on removed collection', async ({helper}) => {94    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-1', tokenPrefix: 'SP'});95    await collection.burn(alice);9697    await expect(collection.setPermissions(alice, {access: 'AllowList', mintMode: true}))98      .to.be.rejectedWith(/common\.CollectionNotFound/);99  });100101  itSub('fails when non-owner tries to set permissions', async ({helper}) => {102    const collection = await helper.nft.mintCollection(alice, {name: 'SetPermissions-Neg-2', tokenPrefix: 'SP'});103104    await expect(collection.setPermissions(bob, {access: 'AllowList', mintMode: true}))105      .to.be.rejectedWith(/common\.NoPermission/);106  });107});