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

difftreelog

Fix addToWhiteList tests

Greg Zaitsev2021-01-19parent: #6b02730.patch.diff
in: master

3 files changed

modifiedtests/src/addToWhiteList.test.tsdiffbeforeafterboth
--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -1,3 +1,4 @@
+import { IKeyringPair } from '@polkadot/types/types';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from './substrate/privateKey';
@@ -14,49 +15,38 @@
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
-describe('Integration Test ext. addToWhiteList()', () => {
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
 
-  it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
+describe.only('Integration Test ext. addToWhiteList()', () => {
+
+  before(async () => {
     await usingApi(async (api) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
-      const collectionId = await createCollectionExpectSuccess();
-      const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
-      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
-      const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
-      // tslint:disable-next-line: no-unused-expression
-      expect(whiteListedBefore).to.be.false;
-      // tslint:disable-next-line: no-unused-expression
-      expect(whiteListedAfter).to.be.true;
+      Alice = privateKey('//Alice');
+      Bob = privateKey('//Bob');
     });
   });
 
+  it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
+    const collectionId = await createCollectionExpectSuccess();
+    await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+  });
+
   it('Whitelisted minting: list restrictions', async () => {
-    await usingApi(async (api) => {
-      const Alice = privateKey('//Alice');
-      const Bob = privateKey('//Bob');
-      const collectionId = await createCollectionExpectSuccess();
-      const whiteListedBefore = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
-      await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
-      const whiteListedAfter = (await api.query.nft.whiteList(collectionId, Bob.address)).toJSON();
-      // tslint:disable-next-line: no-unused-expression
-      expect(whiteListedBefore).to.be.false;
-      // tslint:disable-next-line: no-unused-expression
-      expect(whiteListedAfter).to.be.true;
-      await enableWhiteListExpectSuccess(Alice, collectionId);
-      await enablePublicMintingExpectSuccess(Alice, collectionId);
-      await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
-    });
+    const collectionId = await createCollectionExpectSuccess();
+    await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+    await enableWhiteListExpectSuccess(Alice, collectionId);
+    await enablePublicMintingExpectSuccess(Alice, collectionId);
+    await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
   });
 });
 
-describe('Negative Integration Test ext. addToWhiteList()', () => {
+describe.only('Negative Integration Test ext. addToWhiteList()', () => {
 
   it('White list an address in the collection that does not exist', async () => {
     await usingApi(async (api) => {
-      const Alice = privateKey('//Alice');
       // tslint:disable-next-line: no-bitwise
-      const collectionId = (1 << 32) - 1;
+      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
       const Bob = privateKey('//Bob');
 
       const tx = api.tx.nft.addToWhiteList(collectionId, Bob.address);
modifiedtests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth
--- a/tests/src/toggleContractWhiteList.test.ts
+++ b/tests/src/toggleContractWhiteList.test.ts
@@ -33,7 +33,7 @@
     });
   });
 
-  it.only(`Only whitelisted account can call contract`, async () => {
+  it(`Only whitelisted account can call contract`, async () => {
     await usingApi(async api => {
       const bob = privateKey("//Bob");
 
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
550export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {550export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
551 await usingApi(async (api) => {551 await usingApi(async (api) => {
552
553 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();
552554
553 // Run the transaction555 // Run the transaction
554 const tx = api.tx.nft.addToWhiteList(collectionId, address);556 const tx = api.tx.nft.addToWhiteList(collectionId, address);
555 const events = await submitTransactionAsync(sender, tx);557 const events = await submitTransactionAsync(sender, tx);
556 const result = getGenericResult(events);558 const result = getGenericResult(events);
557559
558 // Get the collection
559 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();560 const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();
560561
561 // What to expect562 // What to expect
562 expect(result.success).to.be.true;563 expect(result.success).to.be.true;
564 // tslint:disable-next-line: no-unused-expression
565 expect(whiteListedBefore).to.be.false;
566 // tslint:disable-next-line: no-unused-expression
563 expect(collection.MintMode).to.be.equal(true);567 expect(whiteListedAfter).to.be.true;
564 });568 });
565}569}
566570