git.delta.rocks / unique-network / refs/commits / ea8fa39bcf35

difftreelog

source

tests/src/eth/util/playgrounds/index.ts2.8 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {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 {requirePalletsOrSkip} from '../../../util/playgrounds';16chai.use(chaiAsPromised);17export const expect = chai.expect;1819export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {20  const silentConsole = new SilentConsole();21  silentConsole.enable();2223  const helper = new EthUniqueHelper(new SilentLogger());2425  try {26    await helper.connect(config.substrateUrl);27    await helper.connectWeb3(config.substrateUrl);28    const ss58Format = helper.chain.getChainProperties().ss58Format;29    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);30    await code(helper, privateKey);31  }32  finally {33    await helper.disconnect();34    await helper.disconnectWeb3();35    silentConsole.disable();36  }37};38  39export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {40  (opts.only ? it.only : 41    opts.skip ? it.skip : it)(name, async function() {42    await usingEthPlaygrounds(async (helper, privateKey) => {43      if (opts.requiredPallets) {44        requirePalletsOrSkip(this, helper, opts.requiredPallets);45      }4647      await cb({helper, privateKey});48    });49  });50}5152export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {53  return itEth(name, cb, {requiredPallets: required, ...opts});54}5556itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});57itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});5859itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});60itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});61itEth.ifWithPallets = itEthIfWithPallet;