difftreelog
feat add skip/only/ifWithPallets to itSub/itEth
in: master
2 files changed
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/index.ts
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -12,6 +12,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
+import { requirePalletsOrSkip } from '../../../util/playgrounds';
chai.use(chaiAsPromised);
export const expect = chai.expect;
@@ -35,15 +36,26 @@
}
};
-export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
- let i: any = it;
- if (opts.only) i = i.only;
- else if (opts.skip) i = i.skip;
- i(name, async () => {
+export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+ (opts.only ? it.only :
+ opts.skip ? it.skip : it)(name, async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
+ if (opts.requiredPallets) {
+ requirePalletsOrSkip(this, helper, opts.requiredPallets);
+ }
+
await cb({helper, privateKey});
});
});
}
+
+export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+ return itEth(name, cb, {requiredPallets: required, ...opts});
+}
+
itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});
-itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});
\ No newline at end of file
+itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});
+
+itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});
+itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});
+itEth.ifWithPallets = itEthIfWithPallet;
tests/src/util/playgrounds/index.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import {Context} from 'mocha';8import config from '../../config';9import '../../interfaces/augment-api-events';10import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';111213chai.use(chaiAsPromised);14export const expect = chai.expect;1516export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) => {17 const silentConsole = new SilentConsole();18 silentConsole.enable();1920 const helper = new DevUniqueHelper(new SilentLogger());2122 try {23 await helper.connect(url);24 const ss58Format = helper.chain.getChainProperties().ss58Format;25 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);26 await code(helper, privateKey);27 }28 finally {29 await helper.disconnect();30 silentConsole.disable();31 }32};3334export enum Pallets {35 Inflation = 'inflation',36 RmrkCore = 'rmrkcore',37 RmrkEquip = 'rmrkequip',38 ReFungible = 'refungible',39 Fungible = 'fungible',40 NFT = 'nonfungible',41 Scheduler = 'scheduler',42}4344export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {45 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);46 47 if (missingPallets.length > 0) {48 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;49 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);50 test.skip();51 }52}5354export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {55 (opts.only ? it.only : 56 opts.skip ? it.skip : it)(name, async function () {57 await usingPlaygrounds(async (helper, privateKey) => {58 if (opts.requiredPallets) {59 requirePalletsOrSkip(this, helper, opts.requiredPallets);60 }61 62 await cb({helper, privateKey});63 });64 });65}66itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});67itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});68itSub.ifWithPallets = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {requiredPallets: required});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import {Context} from 'mocha';8import config from '../../config';9import '../../interfaces/augment-api-events';10import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';111213chai.use(chaiAsPromised);14export const expect = chai.expect;1516export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) => {17 const silentConsole = new SilentConsole();18 silentConsole.enable();1920 const helper = new DevUniqueHelper(new SilentLogger());2122 try {23 await helper.connect(url);24 const ss58Format = helper.chain.getChainProperties().ss58Format;25 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);26 await code(helper, privateKey);27 }28 finally {29 await helper.disconnect();30 silentConsole.disable();31 }32};3334export enum Pallets {35 Inflation = 'inflation',36 RmrkCore = 'rmrkcore',37 RmrkEquip = 'rmrkequip',38 ReFungible = 'refungible',39 Fungible = 'fungible',40 NFT = 'nonfungible',41 Scheduler = 'scheduler',42}4344export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {45 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);46 47 if (missingPallets.length > 0) {48 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;49 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);50 test.skip();51 }52}5354export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {55 (opts.only ? it.only : 56 opts.skip ? it.skip : it)(name, async function () {57 await usingPlaygrounds(async (helper, privateKey) => {58 if (opts.requiredPallets) {59 requirePalletsOrSkip(this, helper, opts.requiredPallets);60 }61 62 await cb({helper, privateKey});63 });64 });65}66export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {67 return itSub(name, cb, {requiredPallets: required, ...opts});68}69itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});70itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});7172itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {only: true});73itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});74itSub.ifWithPallets = itSubIfWithPallet;