git.delta.rocks / unique-network / refs/commits / 78bedc19b952

difftreelog

source

tests/src/removeCollectionAdmin.test.ts4.6 KiBsourcehistory
1import { ApiPromise } from '@polkadot/api';2import BN from 'bn.js';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import privateKey from './substrate/privateKey';6import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';7import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';89chai.use(chaiAsPromised);10const expect = chai.expect;1112describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {13  it('Remove collection admin.', async () => {14    await usingApi(async (api: ApiPromise) => {15      const collectionId = await createCollectionExpectSuccess();16      const Alice = privateKey('//Alice');17      const Bob = privateKey('//Bob');18      const collection: any = (await api.query.nft.collection(collectionId));19      expect(collection.Owner.toString()).to.be.eq(Alice.address);20      // first - add collection admin Bob21      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);22      await submitTransactionAsync(Alice, addAdminTx);2324      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));25      expect(adminListAfterAddAdmin).to.be.contains(Bob.address);2627      // then remove bob from admins of collection28      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);29      await submitTransactionAsync(Alice, removeAdminTx);3031      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));32      expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);33    });34  });35});3637describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {38  it('Can\'t remove collection admin from not existing collection', async () => {39    await usingApi(async (api: ApiPromise) => {40      // tslint:disable-next-line: no-bitwise41      const collectionId = (1 << 32) - 1;42      const alice = privateKey('//Alice');43      const bob = privateKey('//Bob');4445      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);46      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;4748      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)49      await createCollectionExpectSuccess();50    });51  });5253  it('Can\'t remove collection admin from deleted collection', async () => {54    await usingApi(async (api: ApiPromise) => {55      // tslint:disable-next-line: no-bitwise56      const collectionId = await createCollectionExpectSuccess();57      const Alice = privateKey('//Alice');58      const Bob = privateKey('//Bob');5960      await destroyCollectionExpectSuccess(collectionId);6162      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);63      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;6465      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)66      await createCollectionExpectSuccess();67    });68  });6970  it('Remove admin from collection that has reached the maximum number of admins limit', async () => {71    await usingApi(async (api: ApiPromise) => {72      const Alice = privateKey('//Alice');73      const accounts = [74        'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',75        'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',76        'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',77        'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',78        'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',79        'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',80        'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',81        'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',82      ];83      const collectionId = await createCollectionExpectSuccess();8485      const chainLimit = await api.query.nft.chainLimit() as unknown as { collections_admins_limit: BN };86      const chainLimitNumber = chainLimit.collections_admins_limit.toNumber();87      expect(chainLimitNumber).to.be.equal(5);8889      for (let i = 0; i < chainLimitNumber - 1; i++) {90        const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, accounts[i]);91        await submitTransactionAsync(Alice, changeAdminTx);92        const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));93        expect(adminListAfterAddAdmin).to.be.contains(accounts[i]);94      }9596      const tx = api.tx.nft.removeCollectionAdmin(collectionId, accounts[1]);97      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;98    });99  });100});