git.delta.rocks / unique-network / refs/commits / 4afa738abcfc

difftreelog

source

tests/src/setPublicAccessMode.test.ts3.6 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  addToWhiteListExpectSuccess,15  createCollectionExpectSuccess,16  createItemExpectSuccess,17  destroyCollectionExpectSuccess,18  enablePublicMintingExpectSuccess,19  enableWhiteListExpectSuccess,20  normalizeAccountId,21} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526let Alice: IKeyringPair;27let Bob: IKeyringPair;2829describe('Integration Test setPublicAccessMode(): ', () => {30  before(async () => {31    await usingApi(async () => {32      Alice = privateKey('//Alice');33      Bob = privateKey('//Bob');34    });35  });3637  it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {38    await usingApi(async () => {39      const collectionId: number = await createCollectionExpectSuccess();40      await enableWhiteListExpectSuccess(Alice, collectionId);41      await enablePublicMintingExpectSuccess(Alice, collectionId);42      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);43      await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);44    });45  });4647  it('Whitelisted collection limits', async () => {48    await usingApi(async (api: ApiPromise) => {49      const collectionId = await createCollectionExpectSuccess();50      await enableWhiteListExpectSuccess(Alice, collectionId);51      await enablePublicMintingExpectSuccess(Alice, collectionId);52      const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Bob.address), 'NFT');53      await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;54    });55  });56});5758describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {59  it('Set a non-existent collection', async () => {60    await usingApi(async (api: ApiPromise) => {61      // tslint:disable-next-line: radix62      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;63      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');64      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;65    });66  });6768  it('Set the collection that has been deleted', async () => {69    await usingApi(async (api: ApiPromise) => {70      // tslint:disable-next-line: no-bitwise71      const collectionId = await createCollectionExpectSuccess();72      await destroyCollectionExpectSuccess(collectionId);73      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');74      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;75    });76  });7778  it('Re-set the list mode already set in quantity', async () => {79    await usingApi(async () => {80      const collectionId: number = await createCollectionExpectSuccess();81      await enableWhiteListExpectSuccess(Alice, collectionId);82      await enableWhiteListExpectSuccess(Alice, collectionId);83    });84  });8586  it('Execute method not on behalf of the collection owner', async () => {87    await usingApi(async (api: ApiPromise) => {88      // tslint:disable-next-line: no-bitwise89      const collectionId = await createCollectionExpectSuccess();90      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');91      await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;92    });93  });94});