1234import {IKeyringPair} from '@polkadot/types/types';56import config from '../../../config';78import {EthUniqueHelper} from './unique.dev';9import {SilentLogger} from '../../../util/playgrounds/unique.dev';1011export {EthUniqueHelper} from './unique.dev';1213import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15chai.use(chaiAsPromised);16export const expect = chai.expect;1718export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {19 20 21 const consoleErr = console.error;22 const consoleLog = console.log;23 const consoleWarn = console.warn;2425 const outFn = (printer: any) => (...args: any[]) => {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));36 console.log = outFn(consoleLog.bind(console));37 console.warn = outFn(consoleWarn.bind(console));38 const helper = new EthUniqueHelper(new SilentLogger());3940 try {41 await helper.connect(config.substrateUrl);42 await helper.connectWeb3(config.substrateUrl);43 const ss58Format = helper.chain.getChainProperties().ss58Format;44 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);45 await code(helper, privateKey);46 }47 finally {48 await helper.disconnect();49 await helper.disconnectWeb3();50 console.error = consoleErr;51 console.log = consoleLog;52 console.warn = consoleWarn;53 }54}55 56export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {57 let i: any = it;58 if (opts.only) i = i.only;59 else if (opts.skip) i = i.skip;60 i(name, async () => {61 await usingEthPlaygrounds(async (helper, privateKey) => {62 await cb({helper, privateKey});63 });64 });65}66itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});67itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});