git.delta.rocks / unique-network / refs/commits / 38fabb78bb57

difftreelog

Hide unneeded debug output

Greg Zaitsev2021-02-01parent: #0379d3a.patch.diff
in: master

2 files changed

modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
before · tests/src/setSchemaVersion.test.ts
1// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion2import { ApiPromise, Keyring } from '@polkadot/api';3import { IKeyringPair } from '@polkadot/types/types';4import BN from 'bn.js';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';8import { ICollectionInterface } from './types';9import {10  createCollectionExpectSuccess,11  destroyCollectionExpectSuccess,12  getCreatedCollectionCount,13  getCreateItemResult,14  getDetailedCollectionInfo,15} from './util/helpers';1617chai.use(chaiAsPromised);18const expect = chai.expect;1920let alice: IKeyringPair;21let collectionIdForTesting: number;2223/*241. We create collection.252. Save just created collection id.263. Use this id for setSchemaVersion.27*/2829describe('hooks', () => {30  before(async () => {31    await usingApi(async () => {32      const keyring = new Keyring({ type: 'sr25519' });33      alice = keyring.addFromUri('//Alice');34    });35  });36  it('choose or create collection for testing', async () => {37    await usingApi(async () => {38      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});39    });40  });41});4243describe('setSchemaVersion positive', () => {44  let tx;45  before(async () => {46    await usingApi(async () => {47      const keyring = new Keyring({ type: 'sr25519' });48      alice = keyring.addFromUri('//Alice');49    });50  });51  it('execute setSchemaVersion with image url and unique ', async () => {52    await usingApi(async (api: ApiPromise) => {53      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');54      const events = await submitTransactionAsync(alice, tx);55      const result = getCreateItemResult(events);56      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;57      // tslint:disable-next-line:no-unused-expression58      expect(result.success).to.be.true;59      // tslint:disable-next-line:no-unused-expression60      expect(collectionInfo).to.be.exist;61      // tslint:disable-next-line:no-unused-expression62      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');63    });64  });6566  it('validate schema version with just entered data', async () => {67    await usingApi(async (api: ApiPromise) => {68      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');69      const events = await submitTransactionAsync(alice, tx);70      const result = getCreateItemResult(events);71      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;72      // tslint:disable-next-line:no-unused-expression73      expect(result.success).to.be.true;74      // tslint:disable-next-line:no-unused-expression75      expect(collectionInfo).to.be.exist;76      // tslint:disable-next-line:no-unused-expression77      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');78    });79  });80});8182describe('setSchemaVersion negative', () => {83  let tx;84  before(async () => {85    await usingApi(async () => {86      const keyring = new Keyring({ type: 'sr25519' });87      alice = keyring.addFromUri('//Alice');88    });89  });90  it('execute setSchemaVersion for not exists collection', async () => {91    await usingApi(async (api: ApiPromise) => {92      const collectionCount = await getCreatedCollectionCount(api);93      const nonExistedCollectionId = collectionCount + 1;94      tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');95      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;96    });97  });9899  it('execute setSchemaVersion with not correct schema version', async () => {100    await usingApi(async (api: ApiPromise) => {101      try {102        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');103        await submitTransactionAsync(alice, tx);104      } catch (e) {105        // tslint:disable-next-line:no-unused-expression106        expect(e).to.be.exist;107      }108    });109  });110111  it('execute setSchemaVersion for deleted collection', async () => {112    await usingApi(async (api: ApiPromise) => {113      await destroyCollectionExpectSuccess(collectionIdForTesting);114      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');115      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;116    });117  });118});
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -24,12 +24,17 @@
 
   // TODO: Remove, this is temporary: Filter unneeded API output 
   // (Jaco promised it will be removed in the next version)
-  // const consoleLog = console.log;
-  // console.log = (message: string) => {
-  //   if (!(message.includes("API/INIT: Capabilities detected") || message.includes("2021-"))) {
-  //     consoleLog(message);
-  //   }
-  // };
+  const consoleLog = console.log;
+  console.log = (message: string) => {
+    if (message.includes("API/INIT: Capabilities detected") || message.includes("2021-")) {}
+    else if (message.includes("StorageChangeSet:: WebSocket is not connected") || message.includes("2021-")) {}
+    else consoleLog(message);
+  };
+  const consoleErr = console.error;
+  console.error = (message: string) => {
+    if (message.includes("StorageChangeSet:: WebSocket is not connected") || message.includes("2021-")) {}
+    else consoleErr(message);
+  };
 
   try {
     await promisifySubstrate(api, async () => {
@@ -40,7 +45,8 @@
     })();
   } finally {
     await api.disconnect();
-    // console.log = consoleLog;
+    console.log = consoleLog;
+    console.error = consoleErr;
   }
 }
 
@@ -115,7 +121,7 @@
       await transaction.signAndSend(sender, ({ events = [], status }) => {
         const transactionStatus = getTransactionStatus(events, status);
 
-        console.log('transactionStatus', transactionStatus, 'events', events);
+        // console.log('transactionStatus', transactionStatus, 'events', events);
 
         if (transactionStatus == TransactionStatus.Success) {
           resolve(events);