git.delta.rocks / unique-network / refs/commits / 0066f8178098

difftreelog

Missing tests added

str-mv2021-08-13parent: #a395e0a.patch.diff
in: master

6 files changed

modifiedtests/src/addToWhiteList.test.tsdiffbeforeafterboth
--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -17,6 +17,7 @@
   enableWhiteListExpectSuccess,
   normalizeAccountId,
   addCollectionAdminExpectSuccess,
+  addToWhiteListExpectFail,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
@@ -98,6 +99,11 @@
     });
   });
 
+  it('Add to the white list by regular user', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);
+  });
+
   it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
     const collectionId = await createCollectionExpectSuccess();
     await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
before · tests/src/removeCollectionAdmin.test.ts
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, normalizeAccountId} 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.collectionById(collectionId)).toJSON();23      expect(collection.Owner).to.be.deep.eq(Alice.address);24      // first - add collection admin Bob25      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));26      await submitTransactionAsync(Alice, addAdminTx);2728      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();29      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));3031      // then remove bob from admins of collection32      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));33      await submitTransactionAsync(Alice, removeAdminTx);3435      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;36      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));37    });38  });3940  it('Remove admin from collection that has no admins', async () => {41    await usingApi(async (api: ApiPromise) => {42      const Alice = privateKey('//Alice');43      const collectionId = await createCollectionExpectSuccess();4445      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));46      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);4748      const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Alice.address));49      await submitTransactionAsync(Alice, tx);50    });51  });52});5354describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {55  it('Can\'t remove collection admin from not existing collection', async () => {56    await usingApi(async (api: ApiPromise) => {57      // tslint:disable-next-line: no-bitwise58      const collectionId = (1 << 32) - 1;59      const alice = privateKey('//Alice');60      const bob = privateKey('//Bob');6162      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(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('Can\'t remove collection admin from deleted collection', async () => {71    await usingApi(async (api: ApiPromise) => {72      // tslint:disable-next-line: no-bitwise73      const collectionId = await createCollectionExpectSuccess();74      const Alice = privateKey('//Alice');75      const Bob = privateKey('//Bob');7677      await destroyCollectionExpectSuccess(collectionId);7879      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));80      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;8182      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)83      await createCollectionExpectSuccess();84    });85  });8687  it('Regular user Can\'t remove collection admin', async () => {88    await usingApi(async (api: ApiPromise) => {89      const collectionId = await createCollectionExpectSuccess();90      const Alice = privateKey('//Alice');91      const Bob = privateKey('//Bob');92      const Charlie = privateKey('//Charlie');9394      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));95      await submitTransactionAsync(Alice, addAdminTx);9697      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));98      await expect(submitTransactionExpectFailAsync(Charlie, changeOwnerTx)).to.be.rejected;99100      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)101      await createCollectionExpectSuccess();102    });103  });104});
after · tests/src/removeCollectionAdmin.test.ts
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, normalizeAccountId} 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.collectionById(collectionId)).toJSON();23      expect(collection.Owner).to.be.deep.eq(Alice.address);24      // first - add collection admin Bob25      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));26      await submitTransactionAsync(Alice, addAdminTx);2728      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();29      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));3031      // then remove bob from admins of collection32      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));33      await submitTransactionAsync(Alice, removeAdminTx);3435      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;36      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));37    });38  });3940  it('Remove collection admin by admin.', async () => {41    await usingApi(async (api: ApiPromise) => {42      const collectionId = await createCollectionExpectSuccess();43      const Alice = privateKey('//Alice');44      const Bob = privateKey('//Bob');45      const Charlie = privateKey('//Charlie');46      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();47      expect(collection.Owner).to.be.deep.eq(Alice.address);48      // first - add collection admin Bob49      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));50      await submitTransactionAsync(Alice, addAdminTx);5152      const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));53      await submitTransactionAsync(Alice, addAdminTx2);5455      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();56      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));5758      // then remove bob from admins of collection59      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));60      await submitTransactionAsync(Charlie, removeAdminTx);6162      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;63      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));64    });65  });6667  it('Remove admin from collection that has no admins', async () => {68    await usingApi(async (api: ApiPromise) => {69      const Alice = privateKey('//Alice');70      const collectionId = await createCollectionExpectSuccess();7172      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));73      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);7475      const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Alice.address));76      await submitTransactionAsync(Alice, tx);77    });78  });79});8081describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {82  it('Can\'t remove collection admin from not existing collection', async () => {83    await usingApi(async (api: ApiPromise) => {84      // tslint:disable-next-line: no-bitwise85      const collectionId = (1 << 32) - 1;86      const alice = privateKey('//Alice');87      const bob = privateKey('//Bob');8889      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));90      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;9192      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)93      await createCollectionExpectSuccess();94    });95  });9697  it('Can\'t remove collection admin from deleted collection', async () => {98    await usingApi(async (api: ApiPromise) => {99      // tslint:disable-next-line: no-bitwise100      const collectionId = await createCollectionExpectSuccess();101      const Alice = privateKey('//Alice');102      const Bob = privateKey('//Bob');103104      await destroyCollectionExpectSuccess(collectionId);105106      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));107      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;108109      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)110      await createCollectionExpectSuccess();111    });112  });113114  it('Regular user Can\'t remove collection admin', async () => {115    await usingApi(async (api: ApiPromise) => {116      const collectionId = await createCollectionExpectSuccess();117      const Alice = privateKey('//Alice');118      const Bob = privateKey('//Bob');119      const Charlie = privateKey('//Charlie');120121      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));122      await submitTransactionAsync(Alice, addAdminTx);123124      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));125      await expect(submitTransactionExpectFailAsync(Charlie, changeOwnerTx)).to.be.rejected;126127      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)128      await createCollectionExpectSuccess();129    });130  });131});
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -112,6 +112,12 @@
     await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
   });
 
+  it('(!negative test!) Remove sponsor for a collection by regular user', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
+  });
+
   it('(!negative test!) Remove sponsor in a destroyed collection', async () => {
     const collectionId = await createCollectionExpectSuccess();
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
modifiedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
--- a/tests/src/removeFromWhiteList.test.ts
+++ b/tests/src/removeFromWhiteList.test.ts
@@ -124,4 +124,13 @@
       await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
     });
   });
+
+  it('Regular user can`t remove from whitelist', async () => {
+    await usingApi(async () => {
+      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
+      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
+      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
+      await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
+    });
+  });
 });
\ No newline at end of file
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -24,6 +24,7 @@
 
 let alice: IKeyringPair;
 let bob: IKeyringPair;
+let charlie: IKeyringPair;
 let collectionIdForTesting: number;
 
 /*
@@ -111,12 +112,13 @@
   });
 });
 
-describe('setSchemaVersion negative', () => {
+describe.only('setSchemaVersion negative', () => {
   let tx;
   before(async () => {
     await usingApi(async () => {
       const keyring = new Keyring({ type: 'sr25519' });
       alice = keyring.addFromUri('//Alice');
+      charlie = keyring.addFromUri('//Charlie');
     });
   });
   it('execute setSchemaVersion for not exists collection', async () => {
@@ -127,7 +129,6 @@
       await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
     });
   });
-
   it('execute setSchemaVersion with not correct schema version', async () => {
     await usingApi(async (api: ApiPromise) => {
       const consoleError = console.error;
@@ -143,7 +144,6 @@
       }
     });
   });
-
   it('execute setSchemaVersion for deleted collection', async () => {
     await usingApi(async (api: ApiPromise) => {
       await destroyCollectionExpectSuccess(collectionIdForTesting);
@@ -151,4 +151,10 @@
       await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
     });
   });
+  it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
+      await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;
+    });
+  });
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -1088,6 +1088,19 @@
   });
 }
 
+export async function addToWhiteListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
+  await usingApi(async (api) => {
+    // Run the transaction
+    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
+    const events = await expect(submitTransactionAsync(sender, tx)).to.be.rejected;
+    const result = getGenericResult(events);
+
+    // What to expect
+    // tslint:disable-next-line:no-unused-expression
+    expect(result.success).to.be.false;
+  });
+}
+
 export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {
   await usingApi(async (api) => {
     // Run the transaction