git.delta.rocks / unique-network / refs/commits / 32c79dfc15ed

difftreelog

Increase app-promotion periods for full node

Max Andreev2022-12-16parent: #4b5ba1b.patch.diff
in: master
It works fine on dev node but fails on regular

3 files changed

modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -15,7 +15,9 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util';
+import {
+  itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip, LOCKING_PERIOD, UNLOCKING_PERIOD,
+} from './util';
 import {DevUniqueHelper} from './util/playgrounds/unique.dev';
 import {itEth, expect, SponsoringMode} from './eth/util';
 
@@ -24,8 +26,9 @@
 let nominal: bigint;
 let palletAddress: string;
 let accounts: IKeyringPair[];
-const LOCKING_PERIOD = 8n; // 8 blocks of relay
-const UNLOCKING_PERIOD = 4n; // 4 blocks of parachain
+// App promotion periods:
+// LOCKING_PERIOD = 12n; // 8 blocks of relay
+// UNLOCKING_PERIOD = 6n; // 4 blocks of parachain
 
 describe('App promotion', () => {
   before(async function () {
@@ -192,7 +195,7 @@
       expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(0n);
     });
   
-    itSub('should keep different unlocking block for each unlocking stake', async ({helper}) => {
+    itSub('should keep different unlocking block for each unlocking stake', async ({ helper }) => {
       const staker = accounts.pop()!;
       await helper.staking.stake(staker, 100n * nominal);
       await helper.staking.unstake(staker);
modifiedtests/src/util/globalSetup.tsdiffbeforeafterboth
--- a/tests/src/util/globalSetup.ts
+++ b/tests/src/util/globalSetup.ts
@@ -1,7 +1,9 @@
 // Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
 // SPDX-License-Identifier: Apache-2.0
 
-import {usingPlaygrounds, Pallets, DONOR_FUNDING, MINIMUM_DONOR_FUND} from './index';
+import {
+  usingPlaygrounds, Pallets, DONOR_FUNDING, MINIMUM_DONOR_FUND, LOCKING_PERIOD, UNLOCKING_PERIOD,
+} from './index';
 import * as path from 'path';
 import {promises as fs} from 'fs';
 
@@ -21,10 +23,6 @@
       // 3. Configure App Promotion 
       const missingPallets = helper.fetchMissingPalletNames([Pallets.AppPromotion]);
       if (missingPallets.length === 0) {
-        // TODO: move to config file
-        const LOCKING_PERIOD = 8n; // 8 blocks of relay
-        const UNLOCKING_PERIOD = 4n; // 4 blocks of parachain
-
         const superuser = await privateKey('//Alice');
         const palletAddress = helper.arrange.calculatePalletAddress('appstake');
         const palletAdmin = await privateKey('//PromotionAdmin');
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/interfaces';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import {Context} from 'mocha';10import config from '../config';11import {ChainHelperBase} from './playgrounds/unique';12import {ILogger} from './playgrounds/types';13import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';1415chai.use(chaiAsPromised);16export const expect = chai.expect;1718const getTestHash = (filename: string) => {19  return crypto.createHash('md5').update(filename).digest('hex');20};2122export const getTestSeed = (filename: string) => {23  return `//Alice+${getTestHash(filename)}`;24};2526async function usingPlaygroundsGeneral<T extends ChainHelperBase>(helperType: new(logger: ILogger) => T, url: string, code: (helper: T, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>) {27  const silentConsole = new SilentConsole();28  silentConsole.enable();2930  const helper = new helperType(new SilentLogger());3132  try {33    await helper.connect(url);34    const ss58Format = helper.chain.getChainProperties().ss58Format;35    const privateKey = async (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => {36      if (typeof seed === 'string') {37        return helper.util.fromSeed(seed, ss58Format);38      }39      else {40        const actualSeed = getTestSeed(seed.filename);41        let account = helper.util.fromSeed(actualSeed, ss58Format);42        // here's to hoping that no 43        if (!seed.ignoreFundsPresence && ((helper as any)['balance'] == undefined || await (helper as any).balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND)) {44          console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);45          account = helper.util.fromSeed('//Alice', ss58Format);46        }47        return account;48      }49    };50    await code(helper, privateKey);51  }52  finally {53    await helper.disconnect();54    silentConsole.disable();55  }56}5758export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {59  return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);60};6162export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {63  return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);64};6566export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {67  return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);68};6970export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {71  return usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);72};7374export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {75  return usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);76};7778export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {79  return usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);80};8182export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {83  return usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);84};8586export const MINIMUM_DONOR_FUND = 100_000n;87export const DONOR_FUNDING = 1_000_000n;8889export enum Pallets {90  Inflation = 'inflation',91  RmrkCore = 'rmrkcore',92  RmrkEquip = 'rmrkequip',93  ReFungible = 'refungible',94  Fungible = 'fungible',95  NFT = 'nonfungible',96  Scheduler = 'scheduler',97  AppPromotion = 'apppromotion',98  TestUtils = 'testutils',99}100101export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {102  const missingPallets = helper.fetchMissingPalletNames(requiredPallets);103    104  if (missingPallets.length > 0) {105    const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;106    console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);107    test.skip();108  }109}110111export function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {112  (opts.only ? it.only : 113    opts.skip ? it.skip : it)(name, async function () {114    await usingPlaygrounds(async (helper, privateKey) => {115      if (opts.requiredPallets) {116        requirePalletsOrSkip(this, helper, opts.requiredPallets);117      }118      119      await cb({helper, privateKey});120    });121  });122}123export function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {124  return itSub(name, cb, {requiredPallets: required, ...opts});125}126itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});127itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});128129itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});130itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});131itSub.ifWithPallets = itSubIfWithPallet;132133export type SchedKind = 'anon' | 'named';134135export function itSched(136  name: string,137  cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any,138  opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},139) {140  itSub(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);141  itSub(name + ' (named scheduling)', (apis) => cb('named', apis), opts);142}143itSched.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {only: true});144itSched.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {skip: true});145itSched.ifWithPallets = itSchedIfWithPallets;146147function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {148  return itSched(name, cb, {requiredPallets: required, ...opts});149}150151export function describeXCM(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {152  (process.env.RUN_XCM_TESTS && !opts.skip153    ? describe154    : describe.skip)(title, fn);155}156157describeXCM.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeXCM(name, fn, {skip: true});
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/interfaces';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import {Context} from 'mocha';10import config from '../config';11import {ChainHelperBase} from './playgrounds/unique';12import {ILogger} from './playgrounds/types';13import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';1415chai.use(chaiAsPromised);16export const expect = chai.expect;1718const getTestHash = (filename: string) => {19  return crypto.createHash('md5').update(filename).digest('hex');20};2122export const getTestSeed = (filename: string) => {23  return `//Alice+${getTestHash(filename)}`;24};2526async function usingPlaygroundsGeneral<T extends ChainHelperBase>(helperType: new(logger: ILogger) => T, url: string, code: (helper: T, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>) {27  const silentConsole = new SilentConsole();28  silentConsole.enable();2930  const helper = new helperType(new SilentLogger());3132  try {33    await helper.connect(url);34    const ss58Format = helper.chain.getChainProperties().ss58Format;35    const privateKey = async (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => {36      if (typeof seed === 'string') {37        return helper.util.fromSeed(seed, ss58Format);38      }39      else {40        const actualSeed = getTestSeed(seed.filename);41        let account = helper.util.fromSeed(actualSeed, ss58Format);42        // here's to hoping that no 43        if (!seed.ignoreFundsPresence && ((helper as any)['balance'] == undefined || await (helper as any).balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND)) {44          console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);45          account = helper.util.fromSeed('//Alice', ss58Format);46        }47        return account;48      }49    };50    await code(helper, privateKey);51  }52  finally {53    await helper.disconnect();54    silentConsole.disable();55  }56}5758export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {59  return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);60};6162export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {63  return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);64};6566export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {67  return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);68};6970export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {71  return usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);72};7374export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {75  return usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);76};7778export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {79  return usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);80};8182export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {83  return usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);84};8586export const MINIMUM_DONOR_FUND = 100_000n;87export const DONOR_FUNDING = 1_000_000n;8889// App-promotion periods:90export const LOCKING_PERIOD = 12n; // 8 blocks of relay91export const UNLOCKING_PERIOD = 6n; // 4 blocks of parachain929394export enum Pallets {95  Inflation = 'inflation',96  RmrkCore = 'rmrkcore',97  RmrkEquip = 'rmrkequip',98  ReFungible = 'refungible',99  Fungible = 'fungible',100  NFT = 'nonfungible',101  Scheduler = 'scheduler',102  AppPromotion = 'apppromotion',103  TestUtils = 'testutils',104}105106export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {107  const missingPallets = helper.fetchMissingPalletNames(requiredPallets);108    109  if (missingPallets.length > 0) {110    const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;111    console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);112    test.skip();113  }114}115116export function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {117  (opts.only ? it.only : 118    opts.skip ? it.skip : it)(name, async function () {119    await usingPlaygrounds(async (helper, privateKey) => {120      if (opts.requiredPallets) {121        requirePalletsOrSkip(this, helper, opts.requiredPallets);122      }123      124      await cb({helper, privateKey});125    });126  });127}128export function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {129  return itSub(name, cb, {requiredPallets: required, ...opts});130}131itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});132itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});133134itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});135itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});136itSub.ifWithPallets = itSubIfWithPallet;137138export type SchedKind = 'anon' | 'named';139140export function itSched(141  name: string,142  cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any,143  opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},144) {145  itSub(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);146  itSub(name + ' (named scheduling)', (apis) => cb('named', apis), opts);147}148itSched.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {only: true});149itSched.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {skip: true});150itSched.ifWithPallets = itSchedIfWithPallets;151152function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {153  return itSched(name, cb, {requiredPallets: required, ...opts});154}155156export function describeXCM(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {157  (process.env.RUN_XCM_TESTS && !opts.skip158    ? describe159    : describe.skip)(title, fn);160}161162describeXCM.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeXCM(name, fn, {skip: true});