difftreelog
add Apache-2.0 license identifier
in: master
2 files changed
tests/src/util/playgrounds/index.tsdiffbeforeafterboth1import {IKeyringPair} from '@polkadot/types/types';2import {UniqueHelper} from './unique';3import config from '../../config';4import '../../interfaces/augment-api-events';5import * as defs from '../../interfaces/definitions';6import {ApiPromise, WsProvider} from '@polkadot/api';789class 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}171819class DevUniqueHelper extends UniqueHelper {20 async connect(wsEndpoint: string, listeners?: any): Promise<void> {21 const wsProvider = new WsProvider(wsEndpoint);22 this.api = new ApiPromise({23 provider: wsProvider, 24 signedExtensions: {25 ContractHelpers: {26 extrinsic: {},27 payload: {},28 },29 FakeTransactionFinalizer: {30 extrinsic: {},31 payload: {},32 },33 },34 rpc: {35 unique: defs.unique.rpc,36 rmrk: defs.rmrk.rpc,37 eth: {38 feeHistory: {39 description: 'Dummy',40 params: [],41 type: 'u8',42 },43 maxPriorityFeePerGas: {44 description: 'Dummy',45 params: [],46 type: 'u8',47 },48 },49 },50 });51 await this.api.isReadyOrError;52 this.network = await UniqueHelper.detectNetwork(this.api);53 }54}5556export const usingPlaygrounds = async (code: (helper: UniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {57 // TODO: Remove, this is temporary: Filter unneeded API output58 // (Jaco promised it will be removed in the next version)59 const consoleErr = console.error;60 const consoleLog = console.log;61 const consoleWarn = console.warn;6263 const outFn = (printer: any) => (...args: any[]) => {64 for (const arg of args) {65 if (typeof arg !== 'string')66 continue;67 if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))68 return;69 }70 printer(...args);71 };7273 console.error = outFn(consoleErr.bind(console));74 console.log = outFn(consoleLog.bind(console));75 console.warn = outFn(consoleWarn.bind(console));76 const helper = new DevUniqueHelper(new SilentLogger());7778 try {79 await helper.connect(config.substrateUrl);80 const ss58Format = helper.chain.getChainProperties().ss58Format;81 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);82 await code(helper, privateKey);83 } 84 finally {85 await helper.disconnect();86 console.error = consoleErr;87 console.log = consoleLog;88 console.warn = consoleWarn;89 }90};1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import {UniqueHelper} from './unique';6import config from '../../config';7import '../../interfaces/augment-api-events';8import * as defs from '../../interfaces/definitions';9import {ApiPromise, WsProvider} from '@polkadot/api';101112class SilentLogger {13 log(msg: any, level: any): void {}14 level = {15 ERROR: 'ERROR' as const,16 WARNING: 'WARNING' as const,17 INFO: 'INFO' as const,18 };19}202122class DevUniqueHelper extends UniqueHelper {23 async connect(wsEndpoint: string, listeners?: any): Promise<void> {24 const wsProvider = new WsProvider(wsEndpoint);25 this.api = new ApiPromise({26 provider: wsProvider, 27 signedExtensions: {28 ContractHelpers: {29 extrinsic: {},30 payload: {},31 },32 FakeTransactionFinalizer: {33 extrinsic: {},34 payload: {},35 },36 },37 rpc: {38 unique: defs.unique.rpc,39 rmrk: defs.rmrk.rpc,40 eth: {41 feeHistory: {42 description: 'Dummy',43 params: [],44 type: 'u8',45 },46 maxPriorityFeePerGas: {47 description: 'Dummy',48 params: [],49 type: 'u8',50 },51 },52 },53 });54 await this.api.isReadyOrError;55 this.network = await UniqueHelper.detectNetwork(this.api);56 }57}5859export const usingPlaygrounds = async (code: (helper: UniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {60 // TODO: Remove, this is temporary: Filter unneeded API output61 // (Jaco promised it will be removed in the next version)62 const consoleErr = console.error;63 const consoleLog = console.log;64 const consoleWarn = console.warn;6566 const outFn = (printer: any) => (...args: any[]) => {67 for (const arg of args) {68 if (typeof arg !== 'string')69 continue;70 if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))71 return;72 }73 printer(...args);74 };7576 console.error = outFn(consoleErr.bind(console));77 console.log = outFn(consoleLog.bind(console));78 console.warn = outFn(consoleWarn.bind(console));79 const helper = new DevUniqueHelper(new SilentLogger());8081 try {82 await helper.connect(config.substrateUrl);83 const ss58Format = helper.chain.getChainProperties().ss58Format;84 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);85 await code(helper, privateKey);86 } 87 finally {88 await helper.disconnect();89 console.error = consoleErr;90 console.log = consoleLog;91 console.warn = consoleWarn;92 }93};tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -1,3 +1,6 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable function-call-argument-newline */
/* eslint-disable no-prototype-builtins */