123456789101112131415161718import {ApiPromise} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';20import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';22import privateKey from './substrate/privateKey';23import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';24import {25 addToAllowListExpectSuccess,26 createCollectionExpectSuccess,27 createItemExpectSuccess,28 destroyCollectionExpectSuccess,29 enablePublicMintingExpectSuccess,30 enableAllowListExpectSuccess,31 normalizeAccountId,32 addCollectionAdminExpectSuccess,33 getCreatedCollectionCount,34} from './util/helpers';3536chai.use(chaiAsPromised);37const expect = chai.expect;3839let alice: IKeyringPair;40let bob: IKeyringPair;4142describe('Integration Test setPublicAccessMode(): ', () => {43 before(async () => {44 await usingApi(async () => {45 alice = privateKey('//Alice');46 bob = privateKey('//Bob');47 });48 });4950 it('Run extrinsic with collection id parameters, set the allowlist mode for the collection', async () => {51 await usingApi(async () => {52 const collectionId: number = await createCollectionExpectSuccess();53 await enableAllowListExpectSuccess(alice, collectionId);54 await enablePublicMintingExpectSuccess(alice, collectionId);55 await addToAllowListExpectSuccess(alice, collectionId, bob.address);56 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);57 });58 });5960 it('Allowlisted collection limits', async () => {61 await usingApi(async (api: ApiPromise) => {62 const collectionId = await createCollectionExpectSuccess();63 await enableAllowListExpectSuccess(alice, collectionId);64 await enablePublicMintingExpectSuccess(alice, collectionId);65 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');66 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;67 });68 });69});7071describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {72 it('Set a non-existent collection', async () => {73 await usingApi(async (api: ApiPromise) => {74 75 const collectionId = await getCreatedCollectionCount(api) + 1;76 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');77 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;78 });79 });8081 it('Set the collection that has been deleted', async () => {82 await usingApi(async (api: ApiPromise) => {83 84 const collectionId = await createCollectionExpectSuccess();85 await destroyCollectionExpectSuccess(collectionId);86 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');87 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;88 });89 });9091 it('Re-set the list mode already set in quantity', async () => {92 await usingApi(async () => {93 const collectionId: number = await createCollectionExpectSuccess();94 await enableAllowListExpectSuccess(alice, collectionId);95 await enableAllowListExpectSuccess(alice, collectionId);96 });97 });9899 it('Execute method not on behalf of the collection owner', async () => {100 await usingApi(async (api: ApiPromise) => {101 102 const collectionId = await createCollectionExpectSuccess();103 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');104 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;105 });106 });107});108109describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {110 before(async () => {111 await usingApi(async () => {112 alice = privateKey('//Alice');113 bob = privateKey('//Bob');114 });115 });116 it('setPublicAccessMode by collection admin', async () => {117 await usingApi(async (api: ApiPromise) => {118 119 const collectionId = await createCollectionExpectSuccess();120 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);121 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');122 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;123 });124 });125});