git.delta.rocks / unique-network / refs/commits / 35937ed58884

difftreelog

source

tests/src/addToAllowList.test.ts4.7 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//56import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12  addToAllowListExpectSuccess,13  createCollectionExpectSuccess,14  createItemExpectSuccess,15  destroyCollectionExpectSuccess,16  enablePublicMintingExpectSuccess,17  enableAllowListExpectSuccess,18  normalizeAccountId,19  addCollectionAdminExpectSuccess,20  addToAllowListExpectFail,21} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526let alice: IKeyringPair;27let bob: IKeyringPair;28let charlie: IKeyringPair;2930describe('Integration Test ext. addToAllowList()', () => {3132  before(async () => {33    await usingApi(async () => {34      alice = privateKey('//Alice');35      bob = privateKey('//Bob');36    });37  });3839  it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {40    const collectionId = await createCollectionExpectSuccess();41    await addToAllowListExpectSuccess(alice, collectionId, bob.address);42  });4344  it('Allowlisted minting: list restrictions', async () => {45    const collectionId = await createCollectionExpectSuccess();46    await addToAllowListExpectSuccess(alice, collectionId, bob.address);47    await enableAllowListExpectSuccess(alice, collectionId);48    await enablePublicMintingExpectSuccess(alice, collectionId);49    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);50  });51});5253describe('Negative Integration Test ext. addToAllowList()', () => {5455  it('Allow list an address in the collection that does not exist', async () => {56    await usingApi(async (api) => {57      // tslint:disable-next-line: no-bitwise58      const collectionId = ((await api.query.common.createdCollectionCount()).toNumber()) + 1;59      const bob = privateKey('//Bob');6061      const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));62      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;63    });64  });6566  it('Allow list an address in the collection that was destroyed', async () => {67    await usingApi(async (api) => {68      const alice = privateKey('//Alice');69      const bob = privateKey('//Bob');70      // tslint:disable-next-line: no-bitwise71      const collectionId = await createCollectionExpectSuccess();72      await destroyCollectionExpectSuccess(collectionId);73      const tx = api.tx.nft.addToAllowList(collectionId, normalizeAccountId(bob.address));74      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;75    });76  });7778  it('Allow list an address in the collection that does not have allow list access enabled', async () => {79    await usingApi(async (api) => {80      const alice = privateKey('//Alice');81      const ferdie = privateKey('//Ferdie');82      const collectionId = await createCollectionExpectSuccess();83      await enableAllowListExpectSuccess(alice, collectionId);84      await enablePublicMintingExpectSuccess(alice, collectionId);85      const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');86      await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;87    });88  });8990});9192describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {9394  before(async () => {95    await usingApi(async () => {96      alice = privateKey('//Alice');97      bob = privateKey('//Bob');98      charlie = privateKey('//Charlie');99    });100  });101102  it('Negative. Add to the allow list by regular user', async () => {103    const collectionId = await createCollectionExpectSuccess();104    await addToAllowListExpectFail(bob, collectionId, charlie.address);105  });106107  it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {108    const collectionId = await createCollectionExpectSuccess();109    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);110    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);111  });112113  it('Allowlisted minting: list restrictions', async () => {114    const collectionId = await createCollectionExpectSuccess();115    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);116    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);117118    // allowed only for collection owner119    await enableAllowListExpectSuccess(alice, collectionId);120    await enablePublicMintingExpectSuccess(alice, collectionId);121122    await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);123  });124});