1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi} from './substrate/substrate-api';20import {21 createCollectionExpectSuccess,22 destroyCollectionExpectSuccess,23 enableAllowListExpectSuccess,24 addToAllowListExpectSuccess,25 removeFromAllowListExpectSuccess,26 isAllowlisted,27 findNotExistingCollection,28 removeFromAllowListExpectFailure,29 disableAllowListExpectSuccess,30 normalizeAccountId,31 addCollectionAdminExpectSuccess,32} from './util/helpers';33import {IKeyringPair} from '@polkadot/types/types';3435chai.use(chaiAsPromised);36const expect = chai.expect;3738describe('Integration Test removeFromAllowList', () => {39 let alice: IKeyringPair;40 let bob: IKeyringPair;4142 before(async () => {43 await usingApi(async (api, privateKeyWrapper) => {44 alice = privateKeyWrapper('//Alice');45 bob = privateKeyWrapper('//Bob');46 });47 });4849 it('ensure bob is not in allowlist after removal', async () => {50 await usingApi(async api => {51 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});52 await enableAllowListExpectSuccess(alice, collectionId);53 await addToAllowListExpectSuccess(alice, collectionId, bob.address);5455 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));56 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;57 });58 });5960 it('allows removal from collection with unset allowlist status', async () => {61 await usingApi(async () => {62 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();63 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);64 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);65 await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);6667 await removeFromAllowListExpectSuccess(alice, collectionWithoutAllowlistId, normalizeAccountId(bob.address));68 });69 });70});7172describe('Negative Integration Test removeFromAllowList', () => {73 let alice: IKeyringPair;74 let bob: IKeyringPair;7576 before(async () => {77 await usingApi(async (api, privateKeyWrapper) => {78 alice = privateKeyWrapper('//Alice');79 bob = privateKeyWrapper('//Bob');80 });81 });8283 it('fails on removal from not existing collection', async () => {84 await usingApi(async (api) => {85 const collectionId = await findNotExistingCollection(api);8687 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));88 });89 });9091 it('fails on removal from removed collection', async () => {92 await usingApi(async () => {93 const collectionId = await createCollectionExpectSuccess();94 await enableAllowListExpectSuccess(alice, collectionId);95 await addToAllowListExpectSuccess(alice, collectionId, bob.address);96 await destroyCollectionExpectSuccess(collectionId);9798 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));99 });100 });101});102103describe('Integration Test removeFromAllowList with collection admin permissions', () => {104 let alice: IKeyringPair;105 let bob: IKeyringPair;106 let charlie: IKeyringPair;107108 before(async () => {109 await usingApi(async (api, privateKeyWrapper) => {110 alice = privateKeyWrapper('//Alice');111 bob = privateKeyWrapper('//Bob');112 charlie = privateKeyWrapper('//Charlie');113 });114 });115116 it('ensure address is not in allowlist after removal', async () => {117 await usingApi(async api => {118 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});119 await enableAllowListExpectSuccess(alice, collectionId);120 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);121 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);122 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));123 expect(await isAllowlisted(api, collectionId, charlie.address)).to.be.false;124 });125 });126127 it('Collection admin allowed to remove from allowlist with unset allowlist status', async () => {128 await usingApi(async () => {129 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();130 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);131 await addCollectionAdminExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);132 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);133 await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);134 await removeFromAllowListExpectSuccess(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));135 });136 });137138 it('Regular user can`t remove from allowlist', async () => {139 await usingApi(async () => {140 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();141 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);142 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);143 await removeFromAllowListExpectFailure(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));144 });145 });146});