1234import {IKeyringPair} from '@polkadot/types/types';5import {Context} from 'mocha';6import config from '../../config';7import '../../interfaces/augment-api-events';8import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';91011export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {12 const silentConsole = new SilentConsole();13 silentConsole.enable();1415 const helper = new DevUniqueHelper(new SilentLogger());1617 try {18 await helper.connect(config.substrateUrl);19 const ss58Format = helper.chain.getChainProperties().ss58Format;20 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);21 await code(helper, privateKey);22 }23 finally {24 await helper.disconnect();25 silentConsole.disable();26 }27};2829export enum Pallets {30 Inflation = 'inflation',31 RmrkCore = 'rmrkcore',32 RmrkEquip = 'rmrkequip',33 ReFungible = 'refungible',34 Fungible = 'fungible',35 NFT = 'nonfungible',36 Scheduler = 'scheduler',37}3839export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {40 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);41 42 if (missingPallets.length > 0) {43 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;44 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);45 test.skip();46 }47}4849export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {50 (opts.only ? it.only : 51 opts.skip ? it.skip : it)(name, async function () {52 await usingPlaygrounds(async (helper, privateKey) => {53 if (opts.requiredPallets) {54 requirePalletsOrSkip(this, helper, opts.requiredPallets);55 }56 57 await cb({helper, privateKey});58 });59 });60}61itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});62itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});63itSub.ifWithPallets = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {requiredPallets: required});