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
--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -37,6 +37,33 @@
     });
   });
 
+  it('Remove collection admin by admin.', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//Charlie');
+      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+      expect(collection.Owner).to.be.deep.eq(Alice.address);
+      // first - add collection admin Bob
+      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
+      await submitTransactionAsync(Alice, addAdminTx);
+
+      const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));
+      await submitTransactionAsync(Alice, addAdminTx2);
+
+      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();
+      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));
+
+      // then remove bob from admins of collection
+      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
+      await submitTransactionAsync(Charlie, removeAdminTx);
+
+      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;
+      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));
+    });
+  });
+
   it('Remove admin from collection that has no admins', async () => {
     await usingApi(async (api: ApiPromise) => {
       const Alice = privateKey('//Alice');
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
before · tests/src/removeFromWhiteList.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 chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi } from './substrate/substrate-api';9import {10  createCollectionExpectSuccess,11  destroyCollectionExpectSuccess,12  enableWhiteListExpectSuccess,13  addToWhiteListExpectSuccess,14  removeFromWhiteListExpectSuccess,15  isWhitelisted,16  findNotExistingCollection,17  removeFromWhiteListExpectFailure,18  disableWhiteListExpectSuccess,19  normalizeAccountId,20  addCollectionAdminExpectSuccess,21} from './util/helpers';22import { IKeyringPair } from '@polkadot/types/types';23import privateKey from './substrate/privateKey';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728describe('Integration Test removeFromWhiteList', () => {29  let alice: IKeyringPair;30  let bob: IKeyringPair;3132  before(async () => {33    await usingApi(async () => {34      alice = privateKey('//Alice');35      bob = privateKey('//Bob');36    });37  });3839  it('ensure bob is not in whitelist after removal', async () => {40    await usingApi(async () => {41      const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });42      await enableWhiteListExpectSuccess(alice, collectionId);43      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);4445      await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));46      expect(await isWhitelisted(collectionId, bob.address)).to.be.false;47    });48  });4950  it('allows removal from collection with unset whitelist status', async () => {51    await usingApi(async () => {52      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();53      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);54      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);55      await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);5657      await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, normalizeAccountId(bob.address));58    });59  });60});6162describe('Negative Integration Test removeFromWhiteList', () => {63  let alice: IKeyringPair;64  let bob: IKeyringPair;6566  before(async () => {67    await usingApi(async () => {68      alice = privateKey('//Alice');69      bob = privateKey('//Bob');70    });71  });7273  it('fails on removal from not existing collection', async () => {74    await usingApi(async (api) => {75      const collectionId = await findNotExistingCollection(api);7677      await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));78    });79  });8081  it('fails on removal from removed collection', async () => {82    await usingApi(async () => {83      const collectionId = await createCollectionExpectSuccess();84      await enableWhiteListExpectSuccess(alice, collectionId);85      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);86      await destroyCollectionExpectSuccess(collectionId);8788      await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));89    });90  });91});9293describe('Integration Test removeFromWhiteList with collection admin permissions', () => {94  let alice: IKeyringPair;95  let bob: IKeyringPair;96  let charlie: IKeyringPair;9798  before(async () => {99    await usingApi(async () => {100      alice = privateKey('//Alice');101      bob = privateKey('//Bob');102      charlie = privateKey('//Charlie');103    });104  });105106  it('ensure address is not in whitelist after removal', async () => {107    await usingApi(async () => {108      const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });109      await enableWhiteListExpectSuccess(alice, collectionId);110      await addCollectionAdminExpectSuccess(alice, collectionId, bob);111      await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);112      await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));113      expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;114    });115  });116117  it('Collection admin allowed to remove from whitelist with unset whitelist status', async () => {118    await usingApi(async () => {119      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();120      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);121      await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob);122      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);123      await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);124      await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));125    });126  });127});
after · tests/src/removeFromWhiteList.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 chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi } from './substrate/substrate-api';9import {10  createCollectionExpectSuccess,11  destroyCollectionExpectSuccess,12  enableWhiteListExpectSuccess,13  addToWhiteListExpectSuccess,14  removeFromWhiteListExpectSuccess,15  isWhitelisted,16  findNotExistingCollection,17  removeFromWhiteListExpectFailure,18  disableWhiteListExpectSuccess,19  normalizeAccountId,20  addCollectionAdminExpectSuccess,21} from './util/helpers';22import { IKeyringPair } from '@polkadot/types/types';23import privateKey from './substrate/privateKey';2425chai.use(chaiAsPromised);26const expect = chai.expect;2728describe('Integration Test removeFromWhiteList', () => {29  let alice: IKeyringPair;30  let bob: IKeyringPair;3132  before(async () => {33    await usingApi(async () => {34      alice = privateKey('//Alice');35      bob = privateKey('//Bob');36    });37  });3839  it('ensure bob is not in whitelist after removal', async () => {40    await usingApi(async () => {41      const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });42      await enableWhiteListExpectSuccess(alice, collectionId);43      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);4445      await removeFromWhiteListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));46      expect(await isWhitelisted(collectionId, bob.address)).to.be.false;47    });48  });4950  it('allows removal from collection with unset whitelist status', async () => {51    await usingApi(async () => {52      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();53      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);54      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, bob.address);55      await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);5657      await removeFromWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, normalizeAccountId(bob.address));58    });59  });60});6162describe('Negative Integration Test removeFromWhiteList', () => {63  let alice: IKeyringPair;64  let bob: IKeyringPair;6566  before(async () => {67    await usingApi(async () => {68      alice = privateKey('//Alice');69      bob = privateKey('//Bob');70    });71  });7273  it('fails on removal from not existing collection', async () => {74    await usingApi(async (api) => {75      const collectionId = await findNotExistingCollection(api);7677      await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));78    });79  });8081  it('fails on removal from removed collection', async () => {82    await usingApi(async () => {83      const collectionId = await createCollectionExpectSuccess();84      await enableWhiteListExpectSuccess(alice, collectionId);85      await addToWhiteListExpectSuccess(alice, collectionId, bob.address);86      await destroyCollectionExpectSuccess(collectionId);8788      await removeFromWhiteListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));89    });90  });91});9293describe('Integration Test removeFromWhiteList with collection admin permissions', () => {94  let alice: IKeyringPair;95  let bob: IKeyringPair;96  let charlie: IKeyringPair;9798  before(async () => {99    await usingApi(async () => {100      alice = privateKey('//Alice');101      bob = privateKey('//Bob');102      charlie = privateKey('//Charlie');103    });104  });105106  it('ensure address is not in whitelist after removal', async () => {107    await usingApi(async () => {108      const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });109      await enableWhiteListExpectSuccess(alice, collectionId);110      await addCollectionAdminExpectSuccess(alice, collectionId, bob);111      await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);112      await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));113      expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;114    });115  });116117  it('Collection admin allowed to remove from whitelist with unset whitelist status', async () => {118    await usingApi(async () => {119      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();120      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);121      await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob);122      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);123      await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);124      await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));125    });126  });127128  it('Regular user can`t remove from whitelist', async () => {129    await usingApi(async () => {130      const collectionWithoutWhitelistId = await createCollectionExpectSuccess();131      await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);132      await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);133      await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));134    });135  });136});
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