123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi} from './substrate/substrate-api';9import {10 createCollectionExpectSuccess,11 destroyCollectionExpectSuccess,12 enableWhiteListExpectSuccess,13 addToWhiteListExpectSuccess,14 removeFromWhiteListExpectSuccess,15 isWhitelisted,16 findNotExistingCollection,17 removeFromWhiteListExpectFailure,18 disableWhiteListExpectSuccess,19 normalizeAccountId,20 addCollectionAdminExpectSuccess,21} from './util/helpers';22import {IKeyringPair} from '@polkadot/types/types';23import privateKey from './substrate/privateKey';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728describe('Integration Test removeFromWhiteList', () => {29 let alice: IKeyringPair;30 let bob: IKeyringPair;3132 before(async () => {33 await usingApi(async () => {34 alice = privateKey('//Alice');35 bob = privateKey('//Bob');36 });37 });3839 it('ensure bob is not in whitelist after removal', async () => {40 await usingApi(async () => {41 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});42 await enableWhiteListExpectSuccess(alice, collectionId);43 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);4445 await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));46 expect(await isWhitelisted(collectionId, bob.address)).to.be.false;47 });48 });4950 it('allows removal from collection with unset whitelist status', async () => {51 await usingApi(async () => {52 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();53 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);54 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);55 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);5657 await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, normalizeAccountId(bob.address));58 });59 });60});6162describe('Negative Integration Test removeFromWhiteList', () => {63 let alice: IKeyringPair;64 let bob: IKeyringPair;6566 before(async () => {67 await usingApi(async () => {68 alice = privateKey('//Alice');69 bob = privateKey('//Bob');70 });71 });7273 it('fails on removal from not existing collection', async () => {74 await usingApi(async (api) => {75 const collectionId = await findNotExistingCollection(api);7677 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));78 });79 });8081 it('fails on removal from removed collection', async () => {82 await usingApi(async () => {83 const collectionId = await createCollectionExpectSuccess();84 await enableWhiteListExpectSuccess(alice, collectionId);85 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);86 await destroyCollectionExpectSuccess(collectionId);8788 await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));89 });90 });91});9293describe('Integration Test removeFromWhiteList with collection admin permissions', () => {94 let alice: IKeyringPair;95 let bob: IKeyringPair;96 let charlie: IKeyringPair;9798 before(async () => {99 await usingApi(async () => {100 alice = privateKey('//Alice');101 bob = privateKey('//Bob');102 charlie = privateKey('//Charlie');103 });104 });105106 it('ensure address is not in whitelist after removal', async () => {107 await usingApi(async () => {108 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});109 await enableWhiteListExpectSuccess(alice, collectionId);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);111 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);112 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));113 expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;114 });115 });116117 it('Collection admin allowed to remove from whitelist with unset whitelist status', async () => {118 await usingApi(async () => {119 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();120 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);121 await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);122 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);123 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);124 await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));125 });126 });127128 it('Regular user can`t remove from whitelist', async () => {129 await usingApi(async () => {130 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();131 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);132 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);133 await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));134 });135 });136});