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

difftreelog

Merge pull request #59 from usetech-llc/feature/NFTPAR-245

Greg Zaitsev2021-01-14parents: #3f04d11 #e9dab2d.patch.diff
in: master
Remove collection test

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -20,6 +20,7 @@
     "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",
     "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
     "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
+    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
     "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts"
   },
addedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -0,0 +1,82 @@
+import { ApiPromise } from '@polkadot/api';
+import BN from 'bn.js';
+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} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
+  it('Remove collection admin.', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const collection: any = (await api.query.nft.collection(collectionId));
+      expect(collection.Owner.toString()).to.be.eq(Alice.address);
+      // first - add collection admin Bob
+      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, addAdminTx);
+
+      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListAfterAddAdmin).to.be.contains(Bob.address);
+
+      // then remove bob from admins of collection
+      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, removeAdminTx);
+
+      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);
+    });
+  });
+});
+
+describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
+  it('Can\'t remove collection admin from not existing collection', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      // tslint:disable-next-line: no-bitwise
+      const collectionId = (1 << 32) - 1;
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+
+      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);
+      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
+
+      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+      await createCollectionExpectSuccess();
+    });
+  });
+
+  it('Can\'t remove collection admin from deleted collection', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      // tslint:disable-next-line: no-bitwise
+      const collectionId = await createCollectionExpectSuccess();
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+
+      await destroyCollectionExpectSuccess(collectionId);
+
+      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;
+
+      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+      await createCollectionExpectSuccess();
+    });
+  });
+
+  it('Remove admin from collection that has no admins', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const collectionId = await createCollectionExpectSuccess();
+
+      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
+
+      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
+      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+    });
+  });
+});
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
before · tests/src/setSchemaVersion.test.ts
1// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion2import { ApiPromise, Keyring } from '@polkadot/api';3import { IKeyringPair } from '@polkadot/types/types';4import BN from 'bn.js';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';8import { ICollectionInterface } from './types';9import {10  createCollectionExpectSuccess,11  destroyCollectionExpectSuccess,12  getCreatedCollectionCount,13  getCreateItemResult,14  getDetailedCollectionInfo,15} from './util/helpers';1617chai.use(chaiAsPromised);18const expect = chai.expect;1920let alice: IKeyringPair;21let collectionIdForTesting: number;2223/*241. We create collection.252. Save just created collection id.263. Use this id for setSchemaVersion.27*/2829describe('hooks', () => {30  before(async () => {31    await usingApi(async () => {32      const keyring = new Keyring({ type: 'sr25519' });33      alice = keyring.addFromUri('//Alice');34    });35  });36  it('choose or create collection for testing', async () => {37    await usingApi(async () => {38      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});39    });40  });41});4243describe('setSchemaVersion positive', () => {44  let tx;45  before(async () => {46    await usingApi(async () => {47      const keyring = new Keyring({ type: 'sr25519' });48      alice = keyring.addFromUri('//Alice');49    });50  });51  it('execute setSchemaVersion with image url and unique ', async () => {52    await usingApi(async (api: ApiPromise) => {53      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');54      const events = await submitTransactionAsync(alice, tx);55      const result = getCreateItemResult(events);56      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;57      // tslint:disable-next-line:no-unused-expression58      expect(result.success).to.be.true;59      // tslint:disable-next-line:no-unused-expression60      expect(collectionInfo).to.be.exist;61      // tslint:disable-next-line:no-unused-expression62      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');63    });64  });6566  it('validate schema version with just entered data', async () => {67    await usingApi(async (api: ApiPromise) => {68      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');69      const events = await submitTransactionAsync(alice, tx);70      const result = getCreateItemResult(events);71      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;72      // tslint:disable-next-line:no-unused-expression73      expect(result.success).to.be.true;74      // tslint:disable-next-line:no-unused-expression75      expect(collectionInfo).to.be.exist;76      // tslint:disable-next-line:no-unused-expression77      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');78    });79  });80});8182describe('setSchemaVersion negative', () => {83  let tx;84  before(async () => {85    await usingApi(async () => {86      const keyring = new Keyring({ type: 'sr25519' });87      alice = keyring.addFromUri('//Alice');88    });89  });90  it('execute setSchemaVersion for not exists collection', async () => {91    await usingApi(async (api: ApiPromise) => {92      const collectionCount = await getCreatedCollectionCount(api);93      const nonExistedCollectionId = collectionCount + 1;94      tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');95      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;96      /*try {97        await submitTransactionAsync(alice, tx);98      } catch (e) {99        // tslint:disable-next-line:no-unused-expression100        expect(e).to.be.exist;101      }*/102    });103  });104105  it('execute setSchemaVersion with not correct schema version', async () => {106    await usingApi(async (api: ApiPromise) => {107      try {108        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');109        await submitTransactionAsync(alice, tx);110      } catch (e) {111        // tslint:disable-next-line:no-unused-expression112        expect(e).to.be.exist;113      }114    });115  });116117  it('execute setSchemaVersion for deleted collection', async () => {118    await usingApi(async (api: ApiPromise) => {119      await destroyCollectionExpectSuccess(collectionIdForTesting);120      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');121      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;122      /*try {123        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');124        await submitTransactionAsync(alice, tx);125      } catch (e) {126        // tslint:disable-next-line:no-unused-expression127        expect(e).to.be.exist;128      }*/129    });130  });131});