git.delta.rocks / unique-network / refs/commits / f52eddef5fcc

difftreelog

source

tests/src/setPublicAccessMode.test.ts4.4 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion7import {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  addToAllowListExpectSuccess,15  createCollectionExpectSuccess,16  createItemExpectSuccess,17  destroyCollectionExpectSuccess,18  enablePublicMintingExpectSuccess,19  enableAllowListExpectSuccess,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 allowlist mode for the collection', async () => {39    await usingApi(async () => {40      const collectionId: number = await createCollectionExpectSuccess();41      await enableAllowListExpectSuccess(alice, collectionId);42      await enablePublicMintingExpectSuccess(alice, collectionId);43      await addToAllowListExpectSuccess(alice, collectionId, bob.address);44      await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);45    });46  });4748  it('Allowlisted collection limits', async () => {49    await usingApi(async (api: ApiPromise) => {50      const collectionId = await createCollectionExpectSuccess();51      await enableAllowListExpectSuccess(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      // tslint:disable-next-line: radix63      const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;64      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');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      // tslint:disable-next-line: no-bitwise72      const collectionId = await createCollectionExpectSuccess();73      await destroyCollectionExpectSuccess(collectionId);74      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');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 enableAllowListExpectSuccess(alice, collectionId);83      await enableAllowListExpectSuccess(alice, collectionId);84    });85  });8687  it('Execute method not on behalf of the collection owner', async () => {88    await usingApi(async (api: ApiPromise) => {89      // tslint:disable-next-line: no-bitwise90      const collectionId = await createCollectionExpectSuccess();91      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');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      // tslint:disable-next-line: no-bitwise107      const collectionId = await createCollectionExpectSuccess();108      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);109      const tx = api.tx.nft.setPublicAccessMode(collectionId, 'AllowList');110      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;111    });112  });113});