git.delta.rocks / unique-network / refs/commits / 3bccb6bdb53e

difftreelog

feat add usingPlaygrounds.atUrl, move describeXcm

Daniel Shiposha2022-10-06parent: #09b9e64.patch.diff
in: master

2 files changed

modifiedtests/src/deprecated-helpers/helpers.tsdiffbeforeafterboth
--- a/tests/src/deprecated-helpers/helpers.ts
+++ b/tests/src/deprecated-helpers/helpers.ts
@@ -1764,12 +1764,6 @@
   return (await api.rpc.unique.collectionById(collectionId)).unwrap();
 }
 
-export const describe_xcm = (
-  process.env.RUN_XCM_TESTS
-    ? describe
-    : describe.skip
-);
-
 export async function waitNewBlocks(blocksCount = 1): Promise<void> {
   await usingApi(async (api) => {
     const promise = new Promise<void>(async (resolve) => {
modifiedtests/src/util/playgrounds/index.tsdiffbeforeafterboth
before · tests/src/util/playgrounds/index.ts
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';1112chai.use(chaiAsPromised);13export const expect = chai.expect;1415export const usingPlaygrounds = async (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};3233export enum Pallets {34  Inflation = 'inflation',35  RmrkCore = 'rmrkcore',36  RmrkEquip = 'rmrkequip',37  ReFungible = 'refungible',38  Fungible = 'fungible',39  NFT = 'nonfungible',40  Scheduler = 'scheduler',41  AppPromotion = 'apppromotion',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;
after · tests/src/util/playgrounds/index.ts
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';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);