123456import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi} from './substrate/substrate-api';9import {10 createCollectionExpectSuccess,11 destroyCollectionExpectSuccess,12 enableAllowListExpectSuccess,13 addToAllowListExpectSuccess,14 removeFromAllowListExpectSuccess,15 isAllowlisted,16 findNotExistingCollection,17 removeFromAllowListExpectFailure,18 disableAllowListExpectSuccess,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 removeFromAllowList', () => {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 allowlist after removal', async () => {40 await usingApi(async () => {41 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});42 await enableAllowListExpectSuccess(alice, collectionId);43 await addToAllowListExpectSuccess(alice, collectionId, bob.address);4445 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));46 expect(await isAllowlisted(collectionId, bob.address)).to.be.false;47 });48 });4950 it('allows removal from collection with unset allowlist status', async () => {51 await usingApi(async () => {52 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();53 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);54 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);55 await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);5657 await removeFromAllowListExpectSuccess(alice, collectionWithoutAllowlistId, normalizeAccountId(bob.address));58 });59 });60});6162describe('Negative Integration Test removeFromAllowList', () => {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 removeFromAllowListExpectFailure(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 enableAllowListExpectSuccess(alice, collectionId);85 await addToAllowListExpectSuccess(alice, collectionId, bob.address);86 await destroyCollectionExpectSuccess(collectionId);8788 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));89 });90 });91});9293describe('Integration Test removeFromAllowList 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 allowlist after removal', async () => {107 await usingApi(async () => {108 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});109 await enableAllowListExpectSuccess(alice, collectionId);110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);111 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);112 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));113 expect(await isAllowlisted(collectionId, charlie.address)).to.be.false;114 });115 });116117 it('Collection admin allowed to remove from allowlist with unset allowlist status', async () => {118 await usingApi(async () => {119 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();120 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);121 await addCollectionAdminExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);122 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);123 await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);124 await removeFromAllowListExpectSuccess(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));125 });126 });127128 it('Regular user can`t remove from allowlist', async () => {129 await usingApi(async () => {130 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();131 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);132 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);133 await removeFromAllowListExpectFailure(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));134 });135 });136});