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

difftreelog

Merge pull request #377 from UniqueNetwork/feature/CORE-302-ss58Format

kozyrevdev2022-06-09parents: #0f16e44 #bd269a2.patch.diff
in: master
test(ss58Format): more test fixes

3 files changed

modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
after · tests/src/addCollectionAdmin.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {27  it('Add collection admin.', async () => {28    await usingApi(async (api, privateKeyWrapper) => {29      const collectionId = await createCollectionExpectSuccess();30      const alice = privateKeyWrapper('//Alice');31      const bob = privateKeyWrapper('//Bob');3233      const collection = await queryCollectionExpectSuccess(api, collectionId);34      expect(collection.owner.toString()).to.be.equal(alice.address);3536      const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));37      await submitTransactionAsync(alice, changeAdminTx);3839      const adminListAfterAddAdmin = await getAdminList(api, collectionId);40      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));41    });42  });43});4445describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {46  it("Not owner can't add collection admin.", async () => {47    await usingApi(async (api, privateKeyWrapper) => {48      const collectionId = await createCollectionExpectSuccess();49      const alice = privateKeyWrapper('//Alice');50      const bob = privateKeyWrapper('//Bob');51      const charlie = privateKeyWrapper('//CHARLIE');5253      const collection = await queryCollectionExpectSuccess(api, collectionId);54      expect(collection.owner.toString()).to.be.equal(alice.address);5556      const adminListAfterAddAdmin = await getAdminList(api, collectionId);57      expect(adminListAfterAddAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address));5859      const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));60      await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;61     62      const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);63      expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address));64      expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));65    });66  });6768  it("Admin can't add collection admin.", async () => {69    await usingApi(async (api, privateKeyWrapper) => {70      const collectionId = await createCollectionExpectSuccess();71      const alice = privateKeyWrapper('//Alice');72      const bob = privateKeyWrapper('//Bob');73      const charlie = privateKeyWrapper('//CHARLIE');7475      const collection = await queryCollectionExpectSuccess(api, collectionId);76      expect(collection.owner.toString()).to.be.equal(alice.address);7778      const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));79      await submitTransactionAsync(alice, changeAdminTx);8081      const adminListAfterAddAdmin = await getAdminList(api, collectionId);82      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));8384      const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));85      await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;86     87      const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);88      expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));89      expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));90    });91  });9293  it("Can't add collection admin of not existing collection.", async () => {94    await usingApi(async (api, privateKeyWrapper) => {95      // tslint:disable-next-line: no-bitwise96      const collectionId = (1 << 32) - 1;97      const alice = privateKeyWrapper('//Alice');98      const bob = privateKeyWrapper('//Bob');99100      const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));101      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;102103      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)104      await createCollectionExpectSuccess();105    });106  });107108  it("Can't add an admin to a destroyed collection.", async () => {109    await usingApi(async (api, privateKeyWrapper) => {110      const collectionId = await createCollectionExpectSuccess();111      const alice = privateKeyWrapper('//Alice');112      const bob = privateKeyWrapper('//Bob');113      await destroyCollectionExpectSuccess(collectionId);114      const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));115      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;116117      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)118      await createCollectionExpectSuccess();119    });120  });121122  it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {123    await usingApi(async (api: ApiPromise, privateKeyWrapper) => {124      const alice = privateKeyWrapper('//Alice');125      const accounts = [126        privateKeyWrapper('//AdminTest/1').address,127        privateKeyWrapper('//AdminTest/2').address,128        privateKeyWrapper('//AdminTest/3').address,129        privateKeyWrapper('//AdminTest/4').address,130        privateKeyWrapper('//AdminTest/5').address,131        privateKeyWrapper('//AdminTest/6').address,132        privateKeyWrapper('//AdminTest/7').address,133      ];134      const collectionId = await createCollectionExpectSuccess();135136      const chainAdminLimit = (api.consts.common.collectionAdminsLimit as any).toNumber();137      expect(chainAdminLimit).to.be.equal(5);138139      for (let i = 0; i < chainAdminLimit; i++) {140        await addCollectionAdminExpectSuccess(alice, collectionId, accounts[i]);141        const adminListAfterAddAdmin = await getAdminList(api, collectionId);142        expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(accounts[i]));143      }144145      const tx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));146      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;147    });148  });149});
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -16,7 +16,6 @@
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
 import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
 import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
 
@@ -95,11 +94,11 @@
   });
 
   it('Regular user can\'t remove collection admin', async () => {
-    await usingApi(async (api) => {
+    await usingApi(async (api, privateKeyWrapper) => {
       const collectionId = await createCollectionExpectSuccess();
-      const alice = privateKey('//Alice');
-      const bob = privateKey('//Bob');
-      const charlie = privateKey('//Charlie');
+      const alice = privateKeyWrapper('//Alice');
+      const bob = privateKeyWrapper('//Bob');
+      const charlie = privateKeyWrapper('//Charlie');
 
       const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
       await submitTransactionAsync(alice, addAdminTx);
@@ -113,11 +112,11 @@
   });
 
   it('Admin can\'t remove collection admin.', async () => {
-    await usingApi(async (api) => {
+    await usingApi(async (api, privateKeyWrapper) => {
       const collectionId = await createCollectionExpectSuccess();
-      const alice = privateKey('//Alice');
-      const bob = privateKey('//Bob');
-      const charlie = privateKey('//Charlie');
+      const alice = privateKeyWrapper('//Alice');
+      const bob = privateKeyWrapper('//Bob');
+      const charlie = privateKeyWrapper('//Charlie');
 
       const adminListAfterAddAdmin = await getAdminList(api, collectionId);
       expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
modifiedtests/src/scheduler.test.tsdiffbeforeafterboth
--- a/tests/src/scheduler.test.ts
+++ b/tests/src/scheduler.test.ts
@@ -16,7 +16,6 @@
 
 import chai, {expect} from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
 import {
   default as usingApi, 
   submitTransactionAsync,