123456import {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 58 const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 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 71 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.address);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.address);116 await addToWhiteListExpectSuccess(bob, collectionId, charlie.address);117118 119 await enableWhiteListExpectSuccess(alice, collectionId);120 await enablePublicMintingExpectSuccess(alice, collectionId);121122 await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);123 });124});