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
6import config from '../../../config';6import config from '../../../config';
77
8import {EthUniqueHelper} from './unique.dev';8import {EthUniqueHelper} from './unique.dev';
9import {SilentLogger} from '../../../util/playgrounds/unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';
1010
11export {EthUniqueHelper} from './unique.dev';11export {EthUniqueHelper} from './unique.dev';
1212
16export const expect = chai.expect;16export const expect = chai.expect;
1717
18export 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 output
20 // (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;
24
25 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 };
34
35 console.error = outFn(consoleErr.bind(console));20 silentConsole.enable();
36 console.log = outFn(consoleLog.bind(console));21
37 console.warn = outFn(consoleWarn.bind(console));
38 const helper = new EthUniqueHelper(new SilentLogger());22 const helper = new EthUniqueHelper(new SilentLogger());
3923
40 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
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
4import {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';
88
9class 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}
179
18export 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 output
20 // (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;
24
25 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 };
34
35 console.error = outFn(consoleErr.bind(console));12 silentConsole.enable();
36 console.log = outFn(consoleLog.bind(console));13
37 console.warn = outFn(consoleWarn.bind(console));
38 const helper = new DevUniqueHelper(new SilentLogger());14 const helper = new DevUniqueHelper(new SilentLogger());
3915
40 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};
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
5import {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';
9
10
11export 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}
19
20
21export class SilentConsole {
22 // TODO: Remove, this is temporary: Filter unneeded API output
23 // (Jaco promised it will be removed in the next version)
24 consoleErr: any;
25 consoleLog: any;
26 consoleWarn: any;
27
28 constructor() {
29 this.consoleErr = console.error;
30 this.consoleLog = console.log;
31 this.consoleWarn = console.warn;
32 }
33
34 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 }
51
52 disable() {
53 console.error = this.consoleErr;
54 console.log = this.consoleLog;
55 console.warn = this.consoleWarn;
56 }
57}
1058
1159
12export class DevUniqueHelper extends UniqueHelper {60export class DevUniqueHelper extends UniqueHelper {