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
--- 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
2424
25let alice: IKeyringPair;25let alice: IKeyringPair;
26let bob: IKeyringPair;26let bob: IKeyringPair;
27let charlie: IKeyringPair;
27let collectionIdForTesting: number;28let collectionIdForTesting: number;
2829
29/*30/*
111 });112 });
112});113});
113114
114describe('setSchemaVersion negative', () => {115describe.only('setSchemaVersion negative', () => {
115 let tx;116 let tx;
116 before(async () => {117 before(async () => {
117 await usingApi(async () => {118 await usingApi(async () => {
118 const keyring = new Keyring({ type: 'sr25519' });119 const keyring = new Keyring({ type: 'sr25519' });
119 alice = keyring.addFromUri('//Alice');120 alice = keyring.addFromUri('//Alice');
121 charlie = keyring.addFromUri('//Charlie');
120 });122 });
121 });123 });
122 it('execute setSchemaVersion for not exists collection', async () => {124 it('execute setSchemaVersion for not exists collection', async () => {
151 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;151 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
152 });152 });
153 });153 });
154 it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {
155 await usingApi(async (api: ApiPromise) => {
156 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
157 await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;
158 });
159 });
154});160});
155161
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