git.delta.rocks / unique-network / refs/commits / 1284e5a1615c

difftreelog

source

tests/src/removeCollectionAdmin.test.ts3.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 { ApiPromise } from '@polkadot/api';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {17  it('Remove collection admin.', async () => {18    await usingApi(async (api: ApiPromise) => {19      const collectionId = await createCollectionExpectSuccess();20      const Alice = privateKey('//Alice');21      const Bob = privateKey('//Bob');22      const collection: any = (await api.query.nft.collection(collectionId));23      expect(collection.Owner.toString()).to.be.eq(Alice.address);24      // first - add collection admin Bob25      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);26      await submitTransactionAsync(Alice, addAdminTx);2728      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));29      expect(adminListAfterAddAdmin).to.be.contains(Bob.address);3031      // then remove bob from admins of collection32      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);33      await submitTransactionAsync(Alice, removeAdminTx);3435      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));36      expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);37    });38  });39});4041describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {42  it('Can\'t remove collection admin from not existing collection', async () => {43    await usingApi(async (api: ApiPromise) => {44      // tslint:disable-next-line: no-bitwise45      const collectionId = (1 << 32) - 1;46      const alice = privateKey('//Alice');47      const bob = privateKey('//Bob');4849      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);50      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;5152      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)53      await createCollectionExpectSuccess();54    });55  });5657  it('Can\'t remove collection admin from deleted collection', async () => {58    await usingApi(async (api: ApiPromise) => {59      // tslint:disable-next-line: no-bitwise60      const collectionId = await createCollectionExpectSuccess();61      const Alice = privateKey('//Alice');62      const Bob = privateKey('//Bob');6364      await destroyCollectionExpectSuccess(collectionId);6566      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);67      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;6869      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)70      await createCollectionExpectSuccess();71    });72  });7374  it('Remove admin from collection that has no admins', async () => {75    await usingApi(async (api: ApiPromise) => {76      const Alice = privateKey('//Alice');77      const collectionId = await createCollectionExpectSuccess();7879      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));80      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);8182      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);83      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;84    });85  });86});