1234567import {ApiPromise} from '@polkadot/api';8import {IKeyringPair} from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import privateKey from './substrate/privateKey';12import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';13import {14 addToWhiteListExpectSuccess,15 createCollectionExpectSuccess,16 createItemExpectSuccess,17 destroyCollectionExpectSuccess,18 enablePublicMintingExpectSuccess,19 enableWhiteListExpectSuccess,20 normalizeAccountId,21 addCollectionAdminExpectSuccess,22} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627let alice: IKeyringPair;28let bob: IKeyringPair;2930describe('Integration Test setPublicAccessMode(): ', () => {31 before(async () => {32 await usingApi(async () => {33 alice = privateKey('//Alice');34 bob = privateKey('//Bob');35 });36 });3738 it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {39 await usingApi(async () => {40 const collectionId: number = await createCollectionExpectSuccess();41 await enableWhiteListExpectSuccess(alice, collectionId);42 await enablePublicMintingExpectSuccess(alice, collectionId);43 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);44 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);45 });46 });4748 it('Whitelisted collection limits', async () => {49 await usingApi(async (api: ApiPromise) => {50 const collectionId = await createCollectionExpectSuccess();51 await enableWhiteListExpectSuccess(alice, collectionId);52 await enablePublicMintingExpectSuccess(alice, collectionId);53 const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');54 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;55 });56 });57});5859describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {60 it('Set a non-existent collection', async () => {61 await usingApi(async (api: ApiPromise) => {62 63 const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;64 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');65 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;66 });67 });6869 it('Set the collection that has been deleted', async () => {70 await usingApi(async (api: ApiPromise) => {71 72 const collectionId = await createCollectionExpectSuccess();73 await destroyCollectionExpectSuccess(collectionId);74 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');75 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;76 });77 });7879 it('Re-set the list mode already set in quantity', async () => {80 await usingApi(async () => {81 const collectionId: number = await createCollectionExpectSuccess();82 await enableWhiteListExpectSuccess(alice, collectionId);83 await enableWhiteListExpectSuccess(alice, collectionId);84 });85 });8687 it('Execute method not on behalf of the collection owner', async () => {88 await usingApi(async (api: ApiPromise) => {89 90 const collectionId = await createCollectionExpectSuccess();91 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');92 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;93 });94 });95});9697describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {98 before(async () => {99 await usingApi(async () => {100 alice = privateKey('//Alice');101 bob = privateKey('//Bob');102 });103 });104 it('setPublicAccessMode by collection admin', async () => {105 await usingApi(async (api: ApiPromise) => {106 107 const collectionId = await createCollectionExpectSuccess();108 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);109 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');110 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;111 });112 });113});