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

difftreelog

source

tests/src/setPublicAccessMode.test.ts4.1 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/>.1617// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {itSub, usingPlaygrounds} from './util/playgrounds';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Integration Test setPublicAccessMode(): ', () => {27  let alice: IKeyringPair;28  let bob: IKeyringPair;29  30  before(async () => {31    await usingPlaygrounds(async (helper, privateKey) => {32      const donor = privateKey('//Alice');33      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);34    });35  });3637  itSub('Runs extrinsic with collection id parameters, sets the allowlist mode for the collection', async ({helper}) => {38    const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-1', tokenPrefix: 'TF'});39    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});40    await collection.addToAllowList(alice, {Substrate: bob.address});41    42    await expect(collection.mintToken(bob, {Substrate: bob.address})).to.be.not.rejected;43  });4445  itSub('Allowlisted collection limits', async ({helper}) => {46    const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-2', tokenPrefix: 'TF'});47    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});48    49    await expect(collection.mintToken(bob, {Substrate: bob.address}))50      .to.be.rejectedWith(/common\.AddressNotInAllowlist/);51  });5253  itSub('setPublicAccessMode by collection admin', async ({helper}) => {54    const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-4', tokenPrefix: 'TF'});55    await collection.addAdmin(alice, {Substrate: bob.address});5657    await expect(collection.setPermissions(bob, {access: 'AllowList'})).to.be.not.rejected;58  });59});6061describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {62  let alice: IKeyringPair;63  let bob: IKeyringPair;64  65  before(async () => {66    await usingPlaygrounds(async (helper, privateKey) => {67      const donor = privateKey('//Alice');68      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);69    });70  });7172  itSub('Sets a non-existent collection', async ({helper}) => {73    const collectionId = (1 << 32) - 1;74    await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList'}))75      .to.be.rejectedWith(/common\.CollectionNotFound/);76  });7778  itSub('Sets the collection that has been deleted', async ({helper}) => {79    const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-1', tokenPrefix: 'TF'});80    await collection.burn(alice);8182    await expect(collection.setPermissions(alice, {access: 'AllowList'}))83      .to.be.rejectedWith(/common\.CollectionNotFound/);84  });8586  itSub('Re-sets the list mode already set in quantity', async ({helper}) => {87    const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-2', tokenPrefix: 'TF'});88    await collection.setPermissions(alice, {access: 'AllowList'});89    await collection.setPermissions(alice, {access: 'AllowList'});90  });9192  itSub('Executes method as a malefactor', async ({helper}) => {93    const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-3', tokenPrefix: 'TF'});9495    await expect(collection.setPermissions(bob, {access: 'AllowList'}))96      .to.be.rejectedWith(/common\.NoPermission/);97  });98});