1234import {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>) => {17 const silentConsole = new SilentConsole();18 silentConsole.enable();1920 const helper = new DevUniqueHelper(new SilentLogger());2122 try {23 await helper.connect(config.substrateUrl);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});