difftreelog
test SilentConsole cls instead of multiple decorations
in: master
4 files changed
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth6import config from '../../../config';6import config from '../../../config';778import {EthUniqueHelper} from './unique.dev';8import {EthUniqueHelper} from './unique.dev';9import {SilentLogger} from '../../../util/playgrounds/unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';101011export {EthUniqueHelper} from './unique.dev';11export {EthUniqueHelper} from './unique.dev';121216export const expect = chai.expect;16export const expect = chai.expect;171718export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {18export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {19 // TODO: Remove, this is temporary: Filter unneeded API output20 // (Jaco promised it will be removed in the next version)21 const consoleErr = console.error;22 const consoleLog = console.log;23 const consoleWarn = console.warn;2425 const outFn = (printer: any) => (...args: any[]) => {19 const silentConsole = new SilentConsole();26 for (const arg of args) {27 if (typeof arg !== 'string')28 continue;29 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')30 return;31 }32 printer(...args);33 };3435 console.error = outFn(consoleErr.bind(console));20 silentConsole.enable();36 console.log = outFn(consoleLog.bind(console));2137 console.warn = outFn(consoleWarn.bind(console));38 const helper = new EthUniqueHelper(new SilentLogger());22 const helper = new EthUniqueHelper(new SilentLogger());392340 try {24 try {47 finally {31 finally {48 await helper.disconnect();32 await helper.disconnect();49 await helper.disconnectWeb3();33 await helper.disconnectWeb3();50 console.error = consoleErr;34 silentConsole.disable();51 console.log = consoleLog;52 console.warn = consoleWarn;53 }35 }54}36}55 37 tests/src/substrate/substrate-api.tsdiffbeforeafterboth25import privateKey from './privateKey';25import privateKey from './privateKey';26import promisifySubstrate from './promisify-substrate';26import promisifySubstrate from './promisify-substrate';2728import {SilentConsole} from '../util/playgrounds/unique.dev';27292830293175 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;7778 // TODO: Remove, this is temporary: Filter unneeded API output79 // (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;837984 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 };9394 console.error = outFn(consoleErr.bind(console));81 silentConsole.enable();95 console.log = outFn(consoleLog.bind(console));96 console.warn = outFn(consoleWarn.bind(console));978298 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}tests/src/util/playgrounds/index.tsdiffbeforeafterboth4import {IKeyringPair} from '@polkadot/types/types';4import {IKeyringPair} from '@polkadot/types/types';5import config from '../../config';5import config from '../../config';6import '../../interfaces/augment-api-events';6import '../../interfaces/augment-api-events';7import {DevUniqueHelper} from './unique.dev';7import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';889class SilentLogger {10 log(msg: any, level: any): void { }11 level = {12 ERROR: 'ERROR' as const,13 WARNING: 'WARNING' as const,14 INFO: 'INFO' as const,15 };16}17918export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {10export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {19 // TODO: Remove, this is temporary: Filter unneeded API output20 // (Jaco promised it will be removed in the next version)21 const consoleErr = console.error;22 const consoleLog = console.log;23 const consoleWarn = console.warn;2425 const outFn = (printer: any) => (...args: any[]) => {11 const silentConsole = new SilentConsole();26 for (const arg of args) {27 if (typeof arg !== 'string')28 continue;29 if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))30 return;31 }32 printer(...args);33 };3435 console.error = outFn(consoleErr.bind(console));12 silentConsole.enable();36 console.log = outFn(consoleLog.bind(console));1337 console.warn = outFn(consoleWarn.bind(console));38 const helper = new DevUniqueHelper(new SilentLogger());14 const helper = new DevUniqueHelper(new SilentLogger());391540 try {16 try {45 }21 }46 finally {22 finally {47 await helper.disconnect();23 await helper.disconnect();48 console.error = consoleErr;24 silentConsole.disable();49 console.log = consoleLog;50 console.warn = consoleWarn;51 }25 }52};26};tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth5import {UniqueHelper} from './unique';5import {UniqueHelper} from './unique';6import {ApiPromise, WsProvider} from '@polkadot/api';6import {ApiPromise, WsProvider} from '@polkadot/api';7import * as defs from '../../interfaces/definitions';7import * as defs from '../../interfaces/definitions';8import {TSigner} from './types';9import {IKeyringPair} from '@polkadot/types/types';8import {IKeyringPair} from '@polkadot/types/types';91011export class SilentLogger {12 log(msg: any, level: any): void { }13 level = {14 ERROR: 'ERROR' as const,15 WARNING: 'WARNING' as const,16 INFO: 'INFO' as const,17 };18}192021export class SilentConsole {22 // TODO: Remove, this is temporary: Filter unneeded API output23 // (Jaco promised it will be removed in the next version)24 consoleErr: any;25 consoleLog: any;26 consoleWarn: any;2728 constructor() {29 this.consoleErr = console.error;30 this.consoleLog = console.log;31 this.consoleWarn = console.warn;32 }3334 enable() { 35 const outFn = (printer: any) => (...args: any[]) => {36 for (const arg of args) {37 for (const arg of args) {38 if (typeof arg !== 'string')39 continue;40 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')41 return;42 }43 }44 printer(...args);45 };46 47 console.error = outFn(this.consoleErr.bind(console));48 console.log = outFn(this.consoleLog.bind(console));49 console.warn = outFn(this.consoleWarn.bind(console));50 }5152 disable() {53 console.error = this.consoleErr;54 console.log = this.consoleLog;55 console.warn = this.consoleWarn;56 }57}1058115912export class DevUniqueHelper extends UniqueHelper {60export class DevUniqueHelper extends UniqueHelper {