1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {22 addToAllowListExpectSuccess,23 createCollectionExpectSuccess,24 createItemExpectSuccess,25 destroyCollectionExpectSuccess,26 enablePublicMintingExpectSuccess,27 enableAllowListExpectSuccess,28 normalizeAccountId,29 addCollectionAdminExpectSuccess,30 addToAllowListExpectFail,31 getCreatedCollectionCount,32} from './util/helpers';3334chai.use(chaiAsPromised);35const expect = chai.expect;3637let alice: IKeyringPair;38let bob: IKeyringPair;39let charlie: IKeyringPair;4041describe('Integration Test ext. addToAllowList()', () => {4243 before(async () => {44 await usingApi(async (api, privateKeyWrapper) => {45 alice = privateKeyWrapper('//Alice');46 bob = privateKeyWrapper('//Bob');47 });48 });4950 it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {51 const collectionId = await createCollectionExpectSuccess();52 await addToAllowListExpectSuccess(alice, collectionId, bob.address);53 });5455 it('Allowlisted minting: list restrictions', async () => {56 const collectionId = await createCollectionExpectSuccess();57 await addToAllowListExpectSuccess(alice, collectionId, bob.address);58 await enableAllowListExpectSuccess(alice, collectionId);59 await enablePublicMintingExpectSuccess(alice, collectionId);60 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);61 });62});6364describe('Negative Integration Test ext. addToAllowList()', () => {6566 it('Allow list an address in the collection that does not exist', async () => {67 await usingApi(async (api, privateKeyWrapper) => {68 69 const collectionId = await getCreatedCollectionCount(api) + 1;70 const bob = privateKeyWrapper('//Bob');7172 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));73 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;74 });75 });7677 it('Allow list an address in the collection that was destroyed', async () => {78 await usingApi(async (api, privateKeyWrapper) => {79 const alice = privateKeyWrapper('//Alice');80 const bob = privateKeyWrapper('//Bob');81 82 const collectionId = await createCollectionExpectSuccess();83 await destroyCollectionExpectSuccess(collectionId);84 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));85 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;86 });87 });8889 it('Allow list an address in the collection that does not have allow list access enabled', async () => {90 await usingApi(async (api, privateKeyWrapper) => {91 const alice = privateKeyWrapper('//Alice');92 const ferdie = privateKeyWrapper('//Ferdie');93 const collectionId = await createCollectionExpectSuccess();94 await enableAllowListExpectSuccess(alice, collectionId);95 await enablePublicMintingExpectSuccess(alice, collectionId);96 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');97 await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;98 });99 });100101});102103describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {104105 before(async () => {106 await usingApi(async (api, privateKeyWrapper) => {107 alice = privateKeyWrapper('//Alice');108 bob = privateKeyWrapper('//Bob');109 charlie = privateKeyWrapper('//Charlie');110 });111 });112113 it('Negative. Add to the allow list by regular user', async () => {114 const collectionId = await createCollectionExpectSuccess();115 await addToAllowListExpectFail(bob, collectionId, charlie.address);116 });117118 it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {119 const collectionId = await createCollectionExpectSuccess();120 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);121 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);122 });123124 it('Allowlisted minting: list restrictions', async () => {125 const collectionId = await createCollectionExpectSuccess();126 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);127 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);128129 130 await enableAllowListExpectSuccess(alice, collectionId);131 await enablePublicMintingExpectSuccess(alice, collectionId);132133 await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);134 });135});