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';1112chai.use(chaiAsPromised);13export const expect = chai.expect;1415export async function usingPlaygrounds(code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) {16 const silentConsole = new SilentConsole();17 silentConsole.enable();1819 const helper = new DevUniqueHelper(new SilentLogger());2021 try {22 await helper.connect(url);23 const ss58Format = helper.chain.getChainProperties().ss58Format;24 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);25 await code(helper, privateKey);26 }27 finally {28 await helper.disconnect();29 silentConsole.disable();30 }31}3233usingPlaygrounds.atUrl = (url: string, code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {34 return usingPlaygrounds(code, url);35};3637export enum Pallets {38 Inflation = 'inflation',39 RmrkCore = 'rmrkcore',40 RmrkEquip = 'rmrkequip',41 ReFungible = 'refungible',42 Fungible = 'fungible',43 NFT = 'nonfungible',44 Scheduler = 'scheduler',45 AppPromotion = 'apppromotion',46}4748export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {49 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);50 51 if (missingPallets.length > 0) {52 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;53 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);54 test.skip();55 }56}5758export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {59 (opts.only ? it.only : 60 opts.skip ? it.skip : it)(name, async function () {61 await usingPlaygrounds(async (helper, privateKey) => {62 if (opts.requiredPallets) {63 requirePalletsOrSkip(this, helper, opts.requiredPallets);64 }65 66 await cb({helper, privateKey});67 });68 });69}70export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {71 return itSub(name, cb, {requiredPallets: required, ...opts});72}73itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});74itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});7576itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {only: true});77itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});78itSub.ifWithPallets = itSubIfWithPallet;7980export const describeXcm = (81 process.env.RUN_XCM_TESTS82 ? describe83 : describe.skip84);