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 enum SponsoringMode {22 Disabled = 0,23 Allowlisted = 1,24 Generous = 2,25}2627export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {28 const silentConsole = new SilentConsole();29 silentConsole.enable();3031 const helper = new EthUniqueHelper(new SilentLogger());3233 try {34 await helper.connect(config.substrateUrl);35 await helper.connectWeb3(config.substrateUrl);36 const ss58Format = helper.chain.getChainProperties().ss58Format;37 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);38 await code(helper, privateKey);39 }40 finally {41 await helper.disconnect();42 await helper.disconnectWeb3();43 silentConsole.disable();44 }45};46 47export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {48 (opts.only ? it.only : 49 opts.skip ? it.skip : it)(name, async function() {50 await usingEthPlaygrounds(async (helper, privateKey) => {51 if (opts.requiredPallets) {52 requirePalletsOrSkip(this, helper, opts.requiredPallets);53 }5455 await cb({helper, privateKey});56 });57 });58}5960export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {61 return itEth(name, cb, {requiredPallets: required, ...opts});62}6364itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});65itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});6667itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});68itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});69itEth.ifWithPallets = itEthIfWithPallet;