git.delta.rocks / unique-network / refs/commits / e105d72c172c

difftreelog

fix use config.ts for endpoints

Daniel Shiposha2023-10-02parent: #57b7f8c.patch.diff
in: master

2 files changed

modifiedtests/src/migrations/942057-appPromotion/lockedToFreeze.tsdiffbeforeafterboth
--- a/tests/src/migrations/942057-appPromotion/lockedToFreeze.ts
+++ b/tests/src/migrations/942057-appPromotion/lockedToFreeze.ts
@@ -4,9 +4,10 @@
 import path, {dirname} from 'path';
 import {isInteger, parse} from 'lossless-json';
 import {fileURLToPath} from 'url';
+import config from '../../config';
 
 
-const WS_ENDPOINT = 'ws://localhost:9944';
+const WS_ENDPOINT = config.substrateUrl;
 const DONOR_SEED = '//Alice';
 const UPDATE_IF_VERSION = 942057;
 
modifiedtests/src/migrations/correctStateAfterMaintenance.tsdiffbeforeafterboth
before · tests/src/migrations/correctStateAfterMaintenance.ts
1import {usingPlaygrounds} from '../util';2345const WS_ENDPOINT = 'ws://127.0.0.1:9944';6const DONOR_SEED = '//Alice';78export const main = async(options: { wsEndpoint: string; donorSeed: string } = {9  wsEndpoint: WS_ENDPOINT,10  donorSeed: DONOR_SEED,11}) => {12  await usingPlaygrounds(async (helper, privateKey) => {13    const api = helper.getApi();1415    if((await api.query.maintenance.enabled()).valueOf()) {16      throw Error('The network is still in maintenance mode');17    }1819    const pendingBlocks = (20      await api.query.appPromotion.pendingUnstake.entries()21    ).map(([k, _v]) =>22      k.args[0]);2324    const currentBlock = await api.query.system.number();2526    const filteredBlocks = pendingBlocks.filter((b) => currentBlock.gt(b));2728    if(filteredBlocks.length != 0) {29      console.log(`During maintenance mode, ${filteredBlocks.length} block(s) were not processed. Number(s): ${filteredBlocks}`);30    } else {31      console.log('Nothing to change');32      return;33    }3435    const skippedBlocks = chunk(filteredBlocks, 10);3637    const signer = await privateKey(options.donorSeed);3839    const txs = skippedBlocks.map((b) =>40      api.tx.sudo.sudo(api.tx.appPromotion.forceUnstake(b)));414243    const promises = txs.map((tx) => () => helper.signTransaction(signer, tx));4445    await Promise.allSettled(promises.map((p) => p()));4647    const failedBlocks: bigint[] = [];48    let isSuccess = true;4950    for(const b of filteredBlocks) {51      if(((await api.query.appPromotion.pendingUnstake(b)).toJSON() as any[]).length != 0) {52        failedBlocks.push(b.toBigInt());53        isSuccess = false;54      }55    }5657    if(isSuccess) {58      console.log('Done. %d block(s) were processed.', filteredBlocks.length);59    } else {60      throw new Error(`Something went wrong. Block(s) have not been processed: ${failedBlocks}`);61    }626364  }, options.wsEndpoint);65};6667const chunk = <T>(arr: T[], size: number) =>68  Array.from({length: Math.ceil(arr.length / size)}, (_: any, i: number) =>69    arr.slice(i * size, i * size + size));
after · tests/src/migrations/correctStateAfterMaintenance.ts
1import config from '../config';2import {usingPlaygrounds} from '../util';3456const WS_ENDPOINT = config.substrateUrl;7const DONOR_SEED = '//Alice';89export const main = async(options: { wsEndpoint: string; donorSeed: string } = {10  wsEndpoint: WS_ENDPOINT,11  donorSeed: DONOR_SEED,12}) => {13  await usingPlaygrounds(async (helper, privateKey) => {14    const api = helper.getApi();1516    if((await api.query.maintenance.enabled()).valueOf()) {17      throw Error('The network is still in maintenance mode');18    }1920    const pendingBlocks = (21      await api.query.appPromotion.pendingUnstake.entries()22    ).map(([k, _v]) =>23      k.args[0]);2425    const currentBlock = await api.query.system.number();2627    const filteredBlocks = pendingBlocks.filter((b) => currentBlock.gt(b));2829    if(filteredBlocks.length != 0) {30      console.log(`During maintenance mode, ${filteredBlocks.length} block(s) were not processed. Number(s): ${filteredBlocks}`);31    } else {32      console.log('Nothing to change');33      return;34    }3536    const skippedBlocks = chunk(filteredBlocks, 10);3738    const signer = await privateKey(options.donorSeed);3940    const txs = skippedBlocks.map((b) =>41      api.tx.sudo.sudo(api.tx.appPromotion.forceUnstake(b)));424344    const promises = txs.map((tx) => () => helper.signTransaction(signer, tx));4546    await Promise.allSettled(promises.map((p) => p()));4748    const failedBlocks: bigint[] = [];49    let isSuccess = true;5051    for(const b of filteredBlocks) {52      if(((await api.query.appPromotion.pendingUnstake(b)).toJSON() as any[]).length != 0) {53        failedBlocks.push(b.toBigInt());54        isSuccess = false;55      }56    }5758    if(isSuccess) {59      console.log('Done. %d block(s) were processed.', filteredBlocks.length);60    } else {61      throw new Error(`Something went wrong. Block(s) have not been processed: ${failedBlocks}`);62    }636465  }, options.wsEndpoint);66};6768const chunk = <T>(arr: T[], size: number) =>69  Array.from({length: Math.ceil(arr.length / size)}, (_: any, i: number) =>70    arr.slice(i * size, i * size + size));