git.delta.rocks / unique-network / refs/commits / 8ee00409a037

difftreelog

source

tests/src/util/playgrounds/index.ts1.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import config from '../../config';6import '../../interfaces/augment-api-events';7import {DevUniqueHelper} from './unique.dev';8910class SilentLogger {11  log(msg: any, level: any): void { }12  level = {13    ERROR: 'ERROR' as const,14    WARNING: 'WARNING' as const,15    INFO: 'INFO' as const,16  };17}1819202122export const usingPlaygrounds = async <T = void> (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<T>) => {23  // TODO: Remove, this is temporary: Filter unneeded API output24  // (Jaco promised it will be removed in the next version)25  const consoleErr = console.error;26  const consoleLog = console.log;27  const consoleWarn = console.warn;28  let result: T = null as unknown as T;29  30  const outFn = (printer: any) => (...args: any[]) => {31    for (const arg of args) {32      if (typeof arg !== 'string')33        continue;34      if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))35        return;36    }37    printer(...args);38  };3940  console.error = outFn(consoleErr.bind(console));41  console.log = outFn(consoleLog.bind(console));42  console.warn = outFn(consoleWarn.bind(console));43  const helper = new DevUniqueHelper(new SilentLogger());4445  try {46    await helper.connect(config.substrateUrl);47    const ss58Format = helper.chain.getChainProperties().ss58Format;48    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);49    result = await code(helper, privateKey);50  }51  finally {52    await helper.disconnect();53    console.error = consoleErr;54    console.log = consoleLog;55    console.warn = consoleWarn;56  }57  return result as T;58};