1234import {IKeyringPair} from '@polkadot/types/types';56import config from '../../../config';78import {EthUniqueHelper} from './unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';1011export {EthUniqueHelper} from './unique.dev';1213import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15import chaiLike from 'chai-like';16import {requirePalletsOrSkip} from '../../../util/playgrounds';17chai.use(chaiAsPromised);18chai.use(chaiLike);19export const expect = chai.expect;2021export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {22 const silentConsole = new SilentConsole();23 silentConsole.enable();2425 const helper = new EthUniqueHelper(new SilentLogger());2627 try {28 await helper.connect(config.substrateUrl);29 await helper.connectWeb3(config.substrateUrl);30 const ss58Format = helper.chain.getChainProperties().ss58Format;31 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);32 await code(helper, privateKey);33 }34 finally {35 await helper.disconnect();36 await helper.disconnectWeb3();37 silentConsole.disable();38 }39};40 41export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {42 (opts.only ? it.only : 43 opts.skip ? it.skip : it)(name, async function() {44 await usingEthPlaygrounds(async (helper, privateKey) => {45 if (opts.requiredPallets) {46 requirePalletsOrSkip(this, helper, opts.requiredPallets);47 }4849 await cb({helper, privateKey});50 });51 });52}5354export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {55 return itEth(name, cb, {requiredPallets: required, ...opts});56}5758itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});59itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});6061itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});62itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});63itEth.ifWithPallets = itEthIfWithPallet;