git.delta.rocks / unique-network / refs/commits / 536471f73bb3

difftreelog

source

tests/src/addToWhiteList.test.ts4.7 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//56import { IKeyringPair } from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi, { submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {12  addToWhiteListExpectSuccess,13  createCollectionExpectSuccess,14  createItemExpectSuccess,15  destroyCollectionExpectSuccess,16  enablePublicMintingExpectSuccess,17  enableWhiteListExpectSuccess,18  normalizeAccountId,19  addCollectionAdminExpectSuccess,20  addToWhiteListExpectFail,21} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526let Alice: IKeyringPair;27let Bob: IKeyringPair;28let Charlie: IKeyringPair;2930describe('Integration Test ext. addToWhiteList()', () => {3132  before(async () => {33    await usingApi(async () => {34      Alice = privateKey('//Alice');35      Bob = privateKey('//Bob');36    });37  });3839  it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {40    const collectionId = await createCollectionExpectSuccess();41    await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);42  });4344  it('Whitelisted minting: list restrictions', async () => {45    const collectionId = await createCollectionExpectSuccess();46    await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);47    await enableWhiteListExpectSuccess(Alice, collectionId);48    await enablePublicMintingExpectSuccess(Alice, collectionId);49    await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);50  });51});5253describe('Negative Integration Test ext. addToWhiteList()', () => {5455  it('White list an address in the collection that does not exist', async () => {56    await usingApi(async (api) => {57      // tslint:disable-next-line: no-bitwise58      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;59      const Bob = privateKey('//Bob');6061      const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));62      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;63    });64  });6566  it('White list an address in the collection that was destroyed', async () => {67    await usingApi(async (api) => {68      const Alice = privateKey('//Alice');69      const Bob = privateKey('//Bob');70      // tslint:disable-next-line: no-bitwise71      const collectionId = await createCollectionExpectSuccess();72      await destroyCollectionExpectSuccess(collectionId);73      const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));74      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;75    });76  });7778  it('White list an address in the collection that does not have white list access enabled', async () => {79    await usingApi(async (api) => {80      const Alice = privateKey('//Alice');81      const Ferdie = privateKey('//Ferdie');82      const collectionId = await createCollectionExpectSuccess();83      await enableWhiteListExpectSuccess(Alice, collectionId);84      await enablePublicMintingExpectSuccess(Alice, collectionId);85      const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');86      await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;87    });88  });8990});9192describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {9394  before(async () => {95    await usingApi(async () => {96      Alice = privateKey('//Alice');97      Bob = privateKey('//Bob');98      Charlie = privateKey('//Charlie');99    });100  });101102  it('Negative. Add to the white list by regular user', async () => {103    const collectionId = await createCollectionExpectSuccess();104    await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);105  });106107  it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {108    const collectionId = await createCollectionExpectSuccess();109    await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);110    await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);111  });112113  it('Whitelisted minting: list restrictions', async () => {114    const collectionId = await createCollectionExpectSuccess();115    await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);116    await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);117118    // allowed only for collection owner119    await enableWhiteListExpectSuccess(Alice, collectionId);120    await enablePublicMintingExpectSuccess(Alice, collectionId);121122    await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);123  });124});