difftreelog
Merge pull request #605 from UniqueNetwork/feature/playgrounds-it-improve
in: master
2 files changed
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth1// 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';15chai.use(chaiAsPromised);16export const expect = chai.expect;1718export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {19 const silentConsole = new SilentConsole();20 silentConsole.enable();2122 const helper = new EthUniqueHelper(new SilentLogger());2324 try {25 await helper.connect(config.substrateUrl);26 await helper.connectWeb3(config.substrateUrl);27 const ss58Format = helper.chain.getChainProperties().ss58Format;28 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);29 await code(helper, privateKey);30 }31 finally {32 await helper.disconnect();33 await helper.disconnectWeb3();34 silentConsole.disable();35 }36};37 38export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {39 let i: any = it;40 if (opts.only) i = i.only;41 else if (opts.skip) i = i.skip;42 i(name, async () => {43 await usingEthPlaygrounds(async (helper, privateKey) => {44 await cb({helper, privateKey});45 });46 });47}48itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});49itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});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;tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -63,6 +63,12 @@
});
});
}
+export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+ return itSub(name, cb, {requiredPallets: required, ...opts});
+}
itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});
itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});
-itSub.ifWithPallets = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {requiredPallets: required});
+
+itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {only: true});
+itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});
+itSub.ifWithPallets = itSubIfWithPallet;