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
before · tests/src/removeCollectionSponsor.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, submitTransactionExpectFailAsync } from './substrate/substrate-api';9import { 10  createCollectionExpectSuccess, 11  setCollectionSponsorExpectSuccess, 12  destroyCollectionExpectSuccess, 13  confirmSponsorshipExpectSuccess,14  confirmSponsorshipExpectFailure,15  createItemExpectSuccess,16  findUnusedAddress,17  removeCollectionSponsorExpectSuccess,18  removeCollectionSponsorExpectFailure,19  normalizeAccountId,20  addCollectionAdminExpectSuccess,21} from './util/helpers';22import { Keyring } from '@polkadot/api';23import { IKeyringPair } from '@polkadot/types/types';24import { BigNumber } from 'bignumber.js';2526chai.use(chaiAsPromised);27const expect = chai.expect;2829let alice: IKeyringPair;30let bob: IKeyringPair;3132describe('integration test: ext. removeCollectionSponsor():', () => {3334  before(async () => {35    await usingApi(async () => {36      const keyring = new Keyring({ type: 'sr25519' });37      alice = keyring.addFromUri('//Alice');38      bob = keyring.addFromUri('//Bob');39    });40  });4142  it('Removing NFT collection sponsor stops sponsorship', async () => {43    const collectionId = await createCollectionExpectSuccess();44    await setCollectionSponsorExpectSuccess(collectionId, bob.address);45    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');46    await removeCollectionSponsorExpectSuccess(collectionId);4748    await usingApi(async (api) => {49      // Find unused address50      const zeroBalance = await findUnusedAddress(api);5152      // Mint token for unused address53      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);5455      // Transfer this tokens from unused address to Alice - should fail56      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());57      const zeroToAlice = api.tx.nft.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);58      const badTransaction = async function () { 59        await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);60      };61      await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');62      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());6364      expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;65    });66  });6768  it('Remove a sponsor after it was already removed', async () => {69    const collectionId = await createCollectionExpectSuccess();70    await setCollectionSponsorExpectSuccess(collectionId, bob.address);71    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');72    await removeCollectionSponsorExpectSuccess(collectionId);73    await removeCollectionSponsorExpectSuccess(collectionId);74  });7576  it('Remove sponsor in a collection that never had the sponsor set', async () => {77    const collectionId = await createCollectionExpectSuccess();78    await removeCollectionSponsorExpectSuccess(collectionId);79  });8081  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {82    const collectionId = await createCollectionExpectSuccess();83    await setCollectionSponsorExpectSuccess(collectionId, bob.address);84    await removeCollectionSponsorExpectSuccess(collectionId);85  });8687});8889describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {90  before(async () => {91    await usingApi(async () => {92      const keyring = new Keyring({ type: 'sr25519' });93      alice = keyring.addFromUri('//Alice');94      bob = keyring.addFromUri('//Bob');95    });96  });9798  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {99    // Find the collection that never existed100    let collectionId = 0;101    await usingApi(async (api) => {102      collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;103    });104105    await removeCollectionSponsorExpectFailure(collectionId);106  });107108  it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {109    const collectionId = await createCollectionExpectSuccess();110    await setCollectionSponsorExpectSuccess(collectionId, bob.address);111    await addCollectionAdminExpectSuccess(alice, collectionId, bob);112    await removeCollectionSponsorExpectFailure(collectionId, '//Bob');113  });114115  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {116    const collectionId = await createCollectionExpectSuccess();117    await setCollectionSponsorExpectSuccess(collectionId, bob.address);118    await destroyCollectionExpectSuccess(collectionId);119    await removeCollectionSponsorExpectFailure(collectionId);120  });121122  it('Set - remove - confirm: fails', async () => {123    const collectionId = await createCollectionExpectSuccess();124    await setCollectionSponsorExpectSuccess(collectionId, bob.address);125    await removeCollectionSponsorExpectSuccess(collectionId);126    await confirmSponsorshipExpectFailure(collectionId, '//Bob');127  });128129  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {130    const collectionId = await createCollectionExpectSuccess();131    await setCollectionSponsorExpectSuccess(collectionId, bob.address);132    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');133    await removeCollectionSponsorExpectSuccess(collectionId);134    await confirmSponsorshipExpectFailure(collectionId, '//Bob');135  });136137});
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