git.delta.rocks / unique-network / refs/commits / 5bd1ef9e8720

difftreelog

source

tests/src/setPublicAccessMode.test.ts4.4 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion7import {ApiPromise} from '@polkadot/api';8import {IKeyringPair} from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import privateKey from './substrate/privateKey';12import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';13import {14  addToAllowListExpectSuccess,15  createCollectionExpectSuccess,16  createItemExpectSuccess,17  destroyCollectionExpectSuccess,18  enablePublicMintingExpectSuccess,19  enableAllowListExpectSuccess,20  normalizeAccountId,21  addCollectionAdminExpectSuccess,22  getCreatedCollectionCount,23} from './util/helpers';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728let alice: IKeyringPair;29let bob: IKeyringPair;3031describe('Integration Test setPublicAccessMode(): ', () => {32  before(async () => {33    await usingApi(async () => {34      alice = privateKey('//Alice');35      bob = privateKey('//Bob');36    });37  });3839  it('Run extrinsic with collection id parameters, set the allowlist mode for the collection', async () => {40    await usingApi(async () => {41      const collectionId: number = await createCollectionExpectSuccess();42      await enableAllowListExpectSuccess(alice, collectionId);43      await enablePublicMintingExpectSuccess(alice, collectionId);44      await addToAllowListExpectSuccess(alice, collectionId, bob.address);45      await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);46    });47  });4849  it('Allowlisted collection limits', async () => {50    await usingApi(async (api: ApiPromise) => {51      const collectionId = await createCollectionExpectSuccess();52      await enableAllowListExpectSuccess(alice, collectionId);53      await enablePublicMintingExpectSuccess(alice, collectionId);54      const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');55      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;56    });57  });58});5960describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {61  it('Set a non-existent collection', async () => {62    await usingApi(async (api: ApiPromise) => {63      // tslint:disable-next-line: radix64      const collectionId = await getCreatedCollectionCount(api) + 1;65      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');66      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;67    });68  });6970  it('Set the collection that has been deleted', async () => {71    await usingApi(async (api: ApiPromise) => {72      // tslint:disable-next-line: no-bitwise73      const collectionId = await createCollectionExpectSuccess();74      await destroyCollectionExpectSuccess(collectionId);75      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');76      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;77    });78  });7980  it('Re-set the list mode already set in quantity', async () => {81    await usingApi(async () => {82      const collectionId: number = await createCollectionExpectSuccess();83      await enableAllowListExpectSuccess(alice, collectionId);84      await enableAllowListExpectSuccess(alice, collectionId);85    });86  });8788  it('Execute method not on behalf of the collection owner', async () => {89    await usingApi(async (api: ApiPromise) => {90      // tslint:disable-next-line: no-bitwise91      const collectionId = await createCollectionExpectSuccess();92      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');93      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;94    });95  });96});9798describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {99  before(async () => {100    await usingApi(async () => {101      alice = privateKey('//Alice');102      bob = privateKey('//Bob');103    });104  });105  it('setPublicAccessMode by collection admin', async () => {106    await usingApi(async (api: ApiPromise) => {107      // tslint:disable-next-line: no-bitwise108      const collectionId = await createCollectionExpectSuccess();109      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);110      const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');111      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;112    });113  });114});