git.delta.rocks / unique-network / refs/commits / 98eaa8fb8e83

difftreelog

source

tests/src/setPublicAccessMode.test.ts5.0 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 {ApiPromise} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';20import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';22import privateKey from './substrate/privateKey';23import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';24import {25  addToAllowListExpectSuccess,26  createCollectionExpectSuccess,27  createItemExpectSuccess,28  destroyCollectionExpectSuccess,29  enablePublicMintingExpectSuccess,30  enableAllowListExpectSuccess,31  normalizeAccountId,32  addCollectionAdminExpectSuccess,33  getCreatedCollectionCount,34} from './util/helpers';3536chai.use(chaiAsPromised);37const expect = chai.expect;3839let alice: IKeyringPair;40let bob: IKeyringPair;4142describe('Integration Test setPublicAccessMode(): ', () => {43  before(async () => {44    await usingApi(async () => {45      alice = privateKey('//Alice');46      bob = privateKey('//Bob');47    });48  });4950  it('Run extrinsic with collection id parameters, set the allowlist mode for the collection', async () => {51    await usingApi(async () => {52      const collectionId: number = await createCollectionExpectSuccess();53      await enableAllowListExpectSuccess(alice, collectionId);54      await enablePublicMintingExpectSuccess(alice, collectionId);55      await addToAllowListExpectSuccess(alice, collectionId, bob.address);56      await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);57    });58  });5960  it('Allowlisted collection limits', async () => {61    await usingApi(async (api: ApiPromise) => {62      const collectionId = await createCollectionExpectSuccess();63      await enableAllowListExpectSuccess(alice, collectionId);64      await enablePublicMintingExpectSuccess(alice, collectionId);65      const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');66      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;67    });68  });69});7071describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {72  it('Set a non-existent collection', async () => {73    await usingApi(async (api: ApiPromise) => {74      // tslint:disable-next-line: radix75      const collectionId = await getCreatedCollectionCount(api) + 1;76      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');77      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;78    });79  });8081  it('Set the collection that has been deleted', async () => {82    await usingApi(async (api: ApiPromise) => {83      // tslint:disable-next-line: no-bitwise84      const collectionId = await createCollectionExpectSuccess();85      await destroyCollectionExpectSuccess(collectionId);86      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');87      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;88    });89  });9091  it('Re-set the list mode already set in quantity', async () => {92    await usingApi(async () => {93      const collectionId: number = await createCollectionExpectSuccess();94      await enableAllowListExpectSuccess(alice, collectionId);95      await enableAllowListExpectSuccess(alice, collectionId);96    });97  });9899  it('Execute method not on behalf of the collection owner', async () => {100    await usingApi(async (api: ApiPromise) => {101      // tslint:disable-next-line: no-bitwise102      const collectionId = await createCollectionExpectSuccess();103      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');104      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;105    });106  });107});108109describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {110  before(async () => {111    await usingApi(async () => {112      alice = privateKey('//Alice');113      bob = privateKey('//Bob');114    });115  });116  it('setPublicAccessMode by collection admin', async () => {117    await usingApi(async (api: ApiPromise) => {118      // tslint:disable-next-line: no-bitwise119      const collectionId = await createCollectionExpectSuccess();120      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);121      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');122      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;123    });124  });125});