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} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let Alice: IKeyringPair;26let Bob: IKeyringPair;27let Charlie: IKeyringPair;2829describe('Integration Test ext. addToWhiteList()', () => {3031 before(async () => {32 await usingApi(async () => {33 Alice = privateKey('//Alice');34 Bob = privateKey('//Bob');35 });36 });3738 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {39 const collectionId = await createCollectionExpectSuccess();40 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);41 });4243 it('Whitelisted minting: list restrictions', async () => {44 const collectionId = await createCollectionExpectSuccess();45 await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);46 await enableWhiteListExpectSuccess(Alice, collectionId);47 await enablePublicMintingExpectSuccess(Alice, collectionId);48 await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);49 });50});5152describe('Negative Integration Test ext. addToWhiteList()', () => {5354 it('White list an address in the collection that does not exist', async () => {55 await usingApi(async (api) => {56 57 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;58 const Bob = privateKey('//Bob');5960 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));61 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;62 });63 });6465 it('White list an address in the collection that was destroyed', async () => {66 await usingApi(async (api) => {67 const Alice = privateKey('//Alice');68 const Bob = privateKey('//Bob');69 70 const collectionId = await createCollectionExpectSuccess();71 await destroyCollectionExpectSuccess(collectionId);72 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));73 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;74 });75 });7677 it('White list an address in the collection that does not have white list access enabled', async () => {78 await usingApi(async (api) => {79 const Alice = privateKey('//Alice');80 const Ferdie = privateKey('//Ferdie');81 const collectionId = await createCollectionExpectSuccess();82 await enableWhiteListExpectSuccess(Alice, collectionId);83 await enablePublicMintingExpectSuccess(Alice, collectionId);84 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');85 await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;86 });87 });8889});9091describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {9293 before(async () => {94 await usingApi(async () => {95 Alice = privateKey('//Alice');96 Bob = privateKey('//Bob');97 Charlie = privateKey('//Charlie');98 });99 });100101 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {102 const collectionId = await createCollectionExpectSuccess();103 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);104 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);105 });106107 it('Whitelisted minting: list restrictions', async () => {108 const collectionId = await createCollectionExpectSuccess();109 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);110 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);111112 113 await enableWhiteListExpectSuccess(Alice, collectionId);114 await enablePublicMintingExpectSuccess(Alice, collectionId);115116 await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);117 });118});