difftreelog
fix EREFUSED due to ws://localhost (?)
in: master
1 file changed
tests/src/migrations/correctStateAfterMaintenance.tsdiffbeforeafterboth1import {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));