git.delta.rocks / unique-network / refs/commits / 23067ec51dc9

difftreelog

tests: adjust minimum donor fund structure + fix app-promotion.seqtest's 'after' if the pallet is not present

Fahrrader2022-10-13parent: #02e004a.patch.diff
in: master

3 files changed

modifiedtests/src/app-promotion.seqtest.tsdiffbeforeafterboth
--- a/tests/src/app-promotion.seqtest.ts
+++ b/tests/src/app-promotion.seqtest.ts
@@ -34,8 +34,9 @@
     });
   });
 
-  after(async () => {
+  after(async function () {
     await usingPlaygrounds(async (helper) => {
+      if (helper.fetchMissingPalletNames([Pallets.AppPromotion]).length != 0) return;
       const api = helper.getApi();
       await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
     });
modifiedtests/src/util/globalSetup.tsdiffbeforeafterboth
--- a/tests/src/util/globalSetup.ts
+++ b/tests/src/util/globalSetup.ts
@@ -1,7 +1,7 @@
 // Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
 // SPDX-License-Identifier: Apache-2.0
 
-import {usingPlaygrounds, Pallets} from './index';
+import {usingPlaygrounds, Pallets, DONOR_FUNDING, MINIMUM_DONOR_FUND} from './index';
 import * as path from 'path';
 import {promises as fs} from 'fs';
 
@@ -67,11 +67,11 @@
         const account = await privateKey({filename: f, ignoreFundsPresence: true});
         const aliceBalance = await helper.balance.getSubstrate(account.address);
 
-        if (aliceBalance < 100_000n * oneToken) {
+        if (aliceBalance < MINIMUM_DONOR_FUND * oneToken) {
           tx.push(helper.executeExtrinsic(
             alice, 
             'api.tx.balances.transfer',
-            [account.address, 1_000_000n * oneToken],
+            [account.address, DONOR_FUNDING * oneToken],
             true,
             {nonce: nonce + balanceGrantedCounter++},
           ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));
modifiedtests/src/util/index.tsdiffbeforeafterboth
before · tests/src/util/index.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import * as path from 'path';5import * as crypto from 'crypto';6import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import {Context} from 'mocha';10import config from '../config';11import '../interfaces/augment-api-events';12import {DevUniqueHelper, SilentLogger, SilentConsole} from './playgrounds/unique.dev';1314chai.use(chaiAsPromised);15export const expect = chai.expect;1617const getTestHash = (filename: string) => {18  return crypto.createHash('md5').update(filename).digest('hex');19};2021export const getTestSeed = (filename: string) => {22  return `//Alice+${getTestHash(filename)}`;23};2425export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {26  const silentConsole = new SilentConsole();27  silentConsole.enable();2829  const helper = new DevUniqueHelper(new SilentLogger());3031  try {32    await helper.connect(url);33    const ss58Format = helper.chain.getChainProperties().ss58Format;34    const privateKey = async (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => {35      if (typeof seed === 'string') {36        return helper.util.fromSeed(seed, ss58Format);37      }38      else {39        const actualSeed = getTestSeed(seed.filename);40        let account = helper.util.fromSeed(actualSeed, ss58Format);41        if (!seed.ignoreFundsPresence && await helper.balance.getSubstrate(account.address) == 0n) {42          console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);43          account = helper.util.fromSeed('//Alice', ss58Format);44        }45        return account;46      }47    };48    await code(helper, privateKey);49  }50  finally {51    await helper.disconnect();52    silentConsole.disable();53  }54};5556export enum Pallets {57  Inflation = 'inflation',58  RmrkCore = 'rmrkcore',59  RmrkEquip = 'rmrkequip',60  ReFungible = 'refungible',61  Fungible = 'fungible',62  NFT = 'nonfungible',63  Scheduler = 'scheduler',64  AppPromotion = 'apppromotion',65}6667export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {68  const missingPallets = helper.fetchMissingPalletNames(requiredPallets);69    70  if (missingPallets.length > 0) {71    const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;72    console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);73    test.skip();74  }75}7677export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {78  (opts.only ? it.only : 79    opts.skip ? it.skip : it)(name, async function () {80    await usingPlaygrounds(async (helper, privateKey) => {81      if (opts.requiredPallets) {82        requirePalletsOrSkip(this, helper, opts.requiredPallets);83      }84      85      await cb({helper, privateKey});86    });87  });88}89export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {90  return itSub(name, cb, {requiredPallets: required, ...opts});91}92itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});93itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});9495itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});96itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});97itSub.ifWithPallets = itSubIfWithPallet;
after · tests/src/util/index.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import * as path from 'path';5import * as crypto from 'crypto';6import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import {Context} from 'mocha';10import config from '../config';11import '../interfaces/augment-api-events';12import {DevUniqueHelper, SilentLogger, SilentConsole} from './playgrounds/unique.dev';1314chai.use(chaiAsPromised);15export const expect = chai.expect;1617const getTestHash = (filename: string) => {18  return crypto.createHash('md5').update(filename).digest('hex');19};2021export const getTestSeed = (filename: string) => {22  return `//Alice+${getTestHash(filename)}`;23};2425export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {26  const silentConsole = new SilentConsole();27  silentConsole.enable();2829  const helper = new DevUniqueHelper(new SilentLogger());3031  try {32    await helper.connect(url);33    const ss58Format = helper.chain.getChainProperties().ss58Format;34    const privateKey = async (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => {35      if (typeof seed === 'string') {36        return helper.util.fromSeed(seed, ss58Format);37      }38      else {39        const actualSeed = getTestSeed(seed.filename);40        let account = helper.util.fromSeed(actualSeed, ss58Format);41        if (!seed.ignoreFundsPresence && await helper.balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND) {42          console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);43          account = helper.util.fromSeed('//Alice', ss58Format);44        }45        return account;46      }47    };48    await code(helper, privateKey);49  }50  finally {51    await helper.disconnect();52    silentConsole.disable();53  }54};5556export const MINIMUM_DONOR_FUND = 100_000n;57export const DONOR_FUNDING = 1_000_000n;5859export enum Pallets {60  Inflation = 'inflation',61  RmrkCore = 'rmrkcore',62  RmrkEquip = 'rmrkequip',63  ReFungible = 'refungible',64  Fungible = 'fungible',65  NFT = 'nonfungible',66  Scheduler = 'scheduler',67  AppPromotion = 'apppromotion',68}6970export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {71  const missingPallets = helper.fetchMissingPalletNames(requiredPallets);72    73  if (missingPallets.length > 0) {74    const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;75    console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);76    test.skip();77  }78}7980export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {81  (opts.only ? it.only : 82    opts.skip ? it.skip : it)(name, async function () {83    await usingPlaygrounds(async (helper, privateKey) => {84      if (opts.requiredPallets) {85        requirePalletsOrSkip(this, helper, opts.requiredPallets);86      }87      88      await cb({helper, privateKey});89    });90  });91}92export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {93  return itSub(name, cb, {requiredPallets: required, ...opts});94}95itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});96itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});9798itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});99itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});100itSub.ifWithPallets = itSubIfWithPallet;