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

difftreelog

test SilentConsole cls instead of multiple decorations

Andrey2022-09-04parent: #c9f3344.patch.diff
in: master

4 files changed

modifiedtests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/index.ts
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -6,7 +6,7 @@
 import config from '../../../config';
 
 import {EthUniqueHelper} from './unique.dev';
-import {SilentLogger} from '../../../util/playgrounds/unique.dev';
+import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';
 
 export {EthUniqueHelper} from './unique.dev';
 
@@ -16,25 +16,9 @@
 export const expect = chai.expect;
 
 export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
-  // TODO: Remove, this is temporary: Filter unneeded API output
-  // (Jaco promised it will be removed in the next version)
-  const consoleErr = console.error;
-  const consoleLog = console.log;
-  const consoleWarn = console.warn;
-
-  const outFn = (printer: any) => (...args: any[]) => {
-    for (const arg of args) {
-      if (typeof arg !== 'string')
-        continue;
-      if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis: UniqueApi/2, RmrkApi/1') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
-        return;
-    }
-    printer(...args);
-  };
+  const silentConsole = new SilentConsole();
+  silentConsole.enable();
 
-  console.error = outFn(consoleErr.bind(console));
-  console.log = outFn(consoleLog.bind(console));
-  console.warn = outFn(consoleWarn.bind(console));
   const helper = new EthUniqueHelper(new SilentLogger());
 
   try {
@@ -47,9 +31,7 @@
   finally {
     await helper.disconnect();
     await helper.disconnectWeb3();
-    console.error = consoleErr;
-    console.log = consoleLog;
-    console.warn = consoleWarn;
+    silentConsole.disable();
   }
 }
   
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
25import privateKey from './privateKey';25import privateKey from './privateKey';
26import promisifySubstrate from './promisify-substrate';26import promisifySubstrate from './promisify-substrate';
27
28import {SilentConsole} from '../util/playgrounds/unique.dev';
2729
2830
2931
75 const api: ApiPromise = new ApiPromise(settings);77 const api: ApiPromise = new ApiPromise(settings);
76 let result: T = null as unknown as T;78 let result: T = null as unknown as T;
77
78 // TODO: Remove, this is temporary: Filter unneeded API output
79 // (Jaco promised it will be removed in the next version)
80 const consoleErr = console.error;
81 const consoleLog = console.log;
82 const consoleWarn = console.warn;
8379
84 const outFn = (printer: any) => (...args: any[]) => {80 const silentConsole = new SilentConsole();
85 for (const arg of args) {
86 if (typeof arg !== 'string')
87 continue;
88 if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
89 return;
90 }
91 printer(...args);
92 };
93
94 console.error = outFn(consoleErr.bind(console));81 silentConsole.enable();
95 console.log = outFn(consoleLog.bind(console));
96 console.warn = outFn(consoleWarn.bind(console));
9782
98 try {83 try {
99 await promisifySubstrate(api, async () => {84 await promisifySubstrate(api, async () => {
106 })();91 })();
107 } finally {92 } finally {
108 await api.disconnect();93 await api.disconnect();
109 console.error = consoleErr;94 silentConsole.disable();
110 console.log = consoleLog;
111 console.warn = consoleWarn;
112 }95 }
113 return result as T;96 return result as T;
114}97}
modifiedtests/src/util/playgrounds/index.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -4,37 +4,13 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import config from '../../config';
 import '../../interfaces/augment-api-events';
-import {DevUniqueHelper} from './unique.dev';
+import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';
 
-class SilentLogger {
-  log(msg: any, level: any): void { }
-  level = {
-    ERROR: 'ERROR' as const,
-    WARNING: 'WARNING' as const,
-    INFO: 'INFO' as const,
-  };
-}
 
 export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
-  // TODO: Remove, this is temporary: Filter unneeded API output
-  // (Jaco promised it will be removed in the next version)
-  const consoleErr = console.error;
-  const consoleLog = console.log;
-  const consoleWarn = console.warn;
+  const silentConsole = new SilentConsole();
+  silentConsole.enable();
 
-  const outFn = (printer: any) => (...args: any[]) => {
-    for (const arg of args) {
-      if (typeof arg !== 'string')
-        continue;
-      if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
-        return;
-    }
-    printer(...args);
-  };
-
-  console.error = outFn(consoleErr.bind(console));
-  console.log = outFn(consoleLog.bind(console));
-  console.warn = outFn(consoleWarn.bind(console));
   const helper = new DevUniqueHelper(new SilentLogger());
 
   try {
@@ -45,8 +21,6 @@
   }
   finally {
     await helper.disconnect();
-    console.error = consoleErr;
-    console.log = consoleLog;
-    console.warn = consoleWarn;
+    silentConsole.disable();
   }
 };
\ No newline at end of file
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -5,10 +5,58 @@
 import {UniqueHelper} from './unique';
 import {ApiPromise, WsProvider} from '@polkadot/api';
 import * as defs from '../../interfaces/definitions';
-import {TSigner} from './types';
 import {IKeyringPair} from '@polkadot/types/types';
 
 
+export class SilentLogger {
+  log(msg: any, level: any): void { }
+  level = {
+    ERROR: 'ERROR' as const,
+    WARNING: 'WARNING' as const,
+    INFO: 'INFO' as const,
+  };
+}
+
+
+export class SilentConsole {
+  // TODO: Remove, this is temporary: Filter unneeded API output
+  // (Jaco promised it will be removed in the next version)
+  consoleErr: any;
+  consoleLog: any;
+  consoleWarn: any;
+
+  constructor() {
+    this.consoleErr = console.error;
+    this.consoleLog = console.log;
+    this.consoleWarn = console.warn;
+  }
+
+  enable() {  
+    const outFn = (printer: any) => (...args: any[]) => {
+      for (const arg of args) {
+        for (const arg of args) {
+          if (typeof arg !== 'string')
+            continue;
+          if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis: UniqueApi/2, RmrkApi/1') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
+            return;
+        }
+      }
+      printer(...args);
+    };
+  
+    console.error = outFn(this.consoleErr.bind(console));
+    console.log = outFn(this.consoleLog.bind(console));
+    console.warn = outFn(this.consoleWarn.bind(console));
+  }
+
+  disable() {
+    console.error = this.consoleErr;
+    console.log = this.consoleLog;
+    console.warn = this.consoleWarn;
+  }
+}
+
+
 export class DevUniqueHelper extends UniqueHelper {
   /**
    * Arrange methods for tests