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

difftreelog

source

tests/src/addCollectionAdmin.test.ts6.2 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 BN from 'bn.js';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import privateKey from './substrate/privateKey';11import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';12import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, normalizeAccountId} from './util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;1617describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {18  it('Add collection admin.', async () => {19    await usingApi(async (api) => {20      const collectionId = await createCollectionExpectSuccess();21      const alice = privateKey('//Alice');22      const bob = privateKey('//Bob');2324      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();25      expect(collection.Owner).to.be.equal(alice.address);2627      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));28      await submitTransactionAsync(alice, changeAdminTx);2930      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));31      expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(bob.address));32    });33  });3435  it('Add admin using added collection admin.', async () => {36    await usingApi(async (api) => {37      const collectionId = await createCollectionExpectSuccess();38      const Alice = privateKey('//Alice');39      const Bob = privateKey('//Bob');40      const Charlie = privateKey('//CHARLIE');4142      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();43      expect(collection.Owner).to.be.equal(Alice.address);4445      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));46      await submitTransactionAsync(Alice, changeAdminTx);4748      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));49      expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Bob.address));5051      const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));52      await submitTransactionAsync(Bob, changeAdminTxCharlie);53      const adminListAfterAddNewAdmin: any = (await api.query.nft.adminList(collectionId));54      expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Bob.address));55      expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Charlie.address));56    });57  });58});5960describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {61  it("Not owner can't add collection admin.", async () => {62    await usingApi(async (api) => {63      const collectionId = await createCollectionExpectSuccess();64      const alice = privateKey('//Alice');65      const nonOwner = privateKey('//Bob_stash');6667      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));68      await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;6970      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));71      expect(adminListAfterAddAdmin).not.to.be.contains(normalizeAccountId(alice.address));7273      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)74      await createCollectionExpectSuccess();75    });76  });77  it("Can't add collection admin of not existing collection.", async () => {78    await usingApi(async (api) => {79      // tslint:disable-next-line: no-bitwise80      const collectionId = (1 << 32) - 1;81      const alice = privateKey('//Alice');82      const bob = privateKey('//Bob');8384      const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));85      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;8687      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)88      await createCollectionExpectSuccess();89    });90  });9192  it("Can't add an admin to a destroyed collection.", async () => {93    await usingApi(async (api) => {94      const collectionId = await createCollectionExpectSuccess();95      const Alice = privateKey('//Alice');96      const Bob = privateKey('//Bob');97      await destroyCollectionExpectSuccess(collectionId);98      const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));99      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;100101      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)102      await createCollectionExpectSuccess();103    });104  });105106  it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {107    await usingApi(async (api: ApiPromise) => {108      const Alice = privateKey('//Alice');109      const accounts = [110        'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',111        'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',112        'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',113        'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',114        'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',115        'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',116        'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',117      ];118      const collectionId = await createCollectionExpectSuccess();119120      const chainAdminLimit = (api.consts.nft.collectionAdminsLimit as any).toNumber();121      expect(chainAdminLimit).to.be.equal(5);122123      for (let i = 0; i < chainAdminLimit; i++) {124        const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[i]));125        await submitTransactionAsync(Alice, changeAdminTx);126        const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));127        expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(accounts[i]));128      }129130      const tx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));131      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;132    });133  });134});