1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';21import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';22import {23 addToAllowListExpectSuccess,24 createCollectionExpectSuccess,25 createItemExpectSuccess,26 destroyCollectionExpectSuccess,27 enablePublicMintingExpectSuccess,28 enableAllowListExpectSuccess,29 normalizeAccountId,30 addCollectionAdminExpectSuccess,31 addToAllowListExpectFail,32 getCreatedCollectionCount,33} from './util/helpers';3435chai.use(chaiAsPromised);36const expect = chai.expect;3738let alice: IKeyringPair;39let bob: IKeyringPair;40let charlie: IKeyringPair;4142describe('Integration Test ext. addToAllowList()', () => {4344 before(async () => {45 await usingApi(async () => {46 alice = privateKey('//Alice');47 bob = privateKey('//Bob');48 });49 });5051 it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {52 const collectionId = await createCollectionExpectSuccess();53 await addToAllowListExpectSuccess(alice, collectionId, bob.address);54 });5556 it('Allowlisted minting: list restrictions', async () => {57 const collectionId = await createCollectionExpectSuccess();58 await addToAllowListExpectSuccess(alice, collectionId, bob.address);59 await enableAllowListExpectSuccess(alice, collectionId);60 await enablePublicMintingExpectSuccess(alice, collectionId);61 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);62 });63});6465describe('Negative Integration Test ext. addToAllowList()', () => {6667 it('Allow list an address in the collection that does not exist', async () => {68 await usingApi(async (api) => {69 70 const collectionId = await getCreatedCollectionCount(api) + 1;71 const bob = privateKey('//Bob');7273 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));74 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;75 });76 });7778 it('Allow list an address in the collection that was destroyed', async () => {79 await usingApi(async (api) => {80 const alice = privateKey('//Alice');81 const bob = privateKey('//Bob');82 83 const collectionId = await createCollectionExpectSuccess();84 await destroyCollectionExpectSuccess(collectionId);85 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));86 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;87 });88 });8990 it('Allow list an address in the collection that does not have allow list access enabled', async () => {91 await usingApi(async (api) => {92 const alice = privateKey('//Alice');93 const ferdie = privateKey('//Ferdie');94 const collectionId = await createCollectionExpectSuccess();95 await enableAllowListExpectSuccess(alice, collectionId);96 await enablePublicMintingExpectSuccess(alice, collectionId);97 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');98 await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;99 });100 });101102});103104describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {105106 before(async () => {107 await usingApi(async () => {108 alice = privateKey('//Alice');109 bob = privateKey('//Bob');110 charlie = privateKey('//Charlie');111 });112 });113114 it('Negative. Add to the allow list by regular user', async () => {115 const collectionId = await createCollectionExpectSuccess();116 await addToAllowListExpectFail(bob, collectionId, charlie.address);117 });118119 it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {120 const collectionId = await createCollectionExpectSuccess();121 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);122 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);123 });124125 it('Allowlisted minting: list restrictions', async () => {126 const collectionId = await createCollectionExpectSuccess();127 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);128 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);129130 131 await enableAllowListExpectSuccess(alice, collectionId);132 await enablePublicMintingExpectSuccess(alice, collectionId);133134 await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);135 });136});