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 addToAllowListExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 enablePublicMintingExpectSuccess,17 enableAllowListExpectSuccess,18 normalizeAccountId,19 addCollectionAdminExpectSuccess,20 addToAllowListExpectFail,21 getCreatedCollectionCount,22} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627let alice: IKeyringPair;28let bob: IKeyringPair;29let charlie: IKeyringPair;3031describe('Integration Test ext. addToAllowList()', () => {3233 before(async () => {34 await usingApi(async () => {35 alice = privateKey('//Alice');36 bob = privateKey('//Bob');37 });38 });3940 it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {41 const collectionId = await createCollectionExpectSuccess();42 await addToAllowListExpectSuccess(alice, collectionId, bob.address);43 });4445 it('Allowlisted minting: list restrictions', async () => {46 const collectionId = await createCollectionExpectSuccess();47 await addToAllowListExpectSuccess(alice, collectionId, bob.address);48 await enableAllowListExpectSuccess(alice, collectionId);49 await enablePublicMintingExpectSuccess(alice, collectionId);50 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);51 });52});5354describe('Negative Integration Test ext. addToAllowList()', () => {5556 it('Allow list an address in the collection that does not exist', async () => {57 await usingApi(async (api) => {58 59 const collectionId = await getCreatedCollectionCount(api) + 1;60 const bob = privateKey('//Bob');6162 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));63 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;64 });65 });6667 it('Allow list an address in the collection that was destroyed', async () => {68 await usingApi(async (api) => {69 const alice = privateKey('//Alice');70 const bob = privateKey('//Bob');71 72 const collectionId = await createCollectionExpectSuccess();73 await destroyCollectionExpectSuccess(collectionId);74 const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));75 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;76 });77 });7879 it('Allow list an address in the collection that does not have allow list access enabled', async () => {80 await usingApi(async (api) => {81 const alice = privateKey('//Alice');82 const ferdie = privateKey('//Ferdie');83 const collectionId = await createCollectionExpectSuccess();84 await enableAllowListExpectSuccess(alice, collectionId);85 await enablePublicMintingExpectSuccess(alice, collectionId);86 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');87 await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;88 });89 });9091});9293describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {9495 before(async () => {96 await usingApi(async () => {97 alice = privateKey('//Alice');98 bob = privateKey('//Bob');99 charlie = privateKey('//Charlie');100 });101 });102103 it('Negative. Add to the allow list by regular user', async () => {104 const collectionId = await createCollectionExpectSuccess();105 await addToAllowListExpectFail(bob, collectionId, charlie.address);106 });107108 it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {109 const collectionId = await createCollectionExpectSuccess();110 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);111 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);112 });113114 it('Allowlisted minting: list restrictions', async () => {115 const collectionId = await createCollectionExpectSuccess();116 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);117 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);118119 120 await enableAllowListExpectSuccess(alice, collectionId);121 await enablePublicMintingExpectSuccess(alice, collectionId);122123 await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);124 });125});