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