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

difftreelog

add 942057 migration scripts

Max Andreev2023-06-09parent: #cd2a1cb.patch.diff
in: master

5 files changed

addedtests/src/migrations/942057-appPromotion/collect-data.shdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/migrations/942057-appPromotion/collect-data.sh
@@ -0,0 +1 @@
+chainql --tla-str=chainUrl=ws://127.0.0.1:9944 stakersParser.jsonnet > output.json
\ No newline at end of file
addedtests/src/migrations/942057-appPromotion/collectData.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/migrations/942057-appPromotion/collectData.ts
@@ -0,0 +1,3 @@
+import {spawnSync} from 'child_process';
+
+export const collectData = () => spawnSync('sh', ['./collect-data.sh']);
modifiedtests/src/migrations/942057-appPromotion/correctStateAfterMaintenance.tsdiffbeforeafterboth
before · tests/src/migrations/942057-appPromotion/correctStateAfterMaintenance.ts
1import {usingPlaygrounds} from '../../util';2345const WS_ENDPOINT = 'ws://localhost: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(30        'During maintenance mode, %d block(s) were not processed',31        filteredBlocks.length,32      );33    } else {34      console.log('Nothing to change');35      return;36    }3738    const skippedBlocks = chunk(filteredBlocks, 10);3940    const signer = await privateKey(options.donorSeed);4142    const txs = skippedBlocks.map((b) =>43      api.tx.sudo.sudo(api.tx.appPromotion.forceUnstake(b)));444546    const promises = txs.map((tx) => () => helper.signTransaction(signer, tx));4748    await Promise.allSettled(promises.map((p) => p()));4950    const failedBlocks: bigint[] = [];51    let isSuccess = true;52    await helper.wait.newBlocks(1);5354    for(const b of filteredBlocks) {55      if(((await api.query.appPromotion.pendingUnstake(b)).toJSON() as any[]).length != 0) {56        failedBlocks.push(b.toBigInt());57        isSuccess = false;58      }59    }6061    if(isSuccess) {62      console.log('Done. %d block(s) were processed.', filteredBlocks.length);63    } else {64      throw new Error(`Something went wrong. Block(s) have not been processed: ${failedBlocks}`);65    }666768  }, options.wsEndpoint);69};7071const chunk = <T>(arr: T[], size: number) =>72  Array.from({length: Math.ceil(arr.length / size)}, (_: any, i: number) =>73    arr.slice(i * size, i * size + size));
after · tests/src/migrations/942057-appPromotion/correctStateAfterMaintenance.ts
1import {usingPlaygrounds} from '../../util';2345const WS_ENDPOINT = 'ws://localhost: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(30        'During maintenance mode, %d block(s) were not processed',31        filteredBlocks.length,32      );33    } else {34      console.log('Nothing to change');35      return;36    }3738    const skippedBlocks = chunk(filteredBlocks, 10);3940    const signer = await privateKey(options.donorSeed);4142    const txs = skippedBlocks.map((b) =>43      api.tx.sudo.sudo(api.tx.appPromotion.forceUnstake(b)));444546    const promises = txs.map((tx) => () => helper.signTransaction(signer, tx));4748    await Promise.allSettled(promises.map((p) => p()));4950    const failedBlocks: bigint[] = [];51    let isSuccess = true;5253    for(const b of filteredBlocks) {54      if(((await api.query.appPromotion.pendingUnstake(b)).toJSON() as any[]).length != 0) {55        failedBlocks.push(b.toBigInt());56        isSuccess = false;57      }58    }5960    if(isSuccess) {61      console.log('Done. %d block(s) were processed.', filteredBlocks.length);62    } else {63      throw new Error(`Something went wrong. Block(s) have not been processed: ${failedBlocks}`);64    }656667  }, options.wsEndpoint);68};6970const chunk = <T>(arr: T[], size: number) =>71  Array.from({length: Math.ceil(arr.length / size)}, (_: any, i: number) =>72    arr.slice(i * size, i * size + size));
addedtests/src/migrations/942057-appPromotion/index.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/migrations/942057-appPromotion/index.ts
@@ -0,0 +1,12 @@
+import {Migration} from '../../util/frankensteinMigrate';
+import {collectData} from './collectData';
+import {migrateLockedToFreeze} from './lockedToFreeze';
+
+export const migration: Migration = {
+  async before() {
+    await collectData();
+  },
+  async after() {
+    await migrateLockedToFreeze();
+  },
+};
modifiedtests/src/migrations/942057-appPromotion/lockedToFreeze.tsdiffbeforeafterboth
--- a/tests/src/migrations/942057-appPromotion/lockedToFreeze.ts
+++ b/tests/src/migrations/942057-appPromotion/lockedToFreeze.ts
@@ -13,7 +13,7 @@
   return isInteger(value) ? BigInt(value) : parseFloat(value);
 }
 
-const main = async(options: { wsEndpoint: string; donorSeed: string } = {
+export const migrateLockedToFreeze = async(options: { wsEndpoint: string; donorSeed: string } = {
   wsEndpoint: WS_ENDPOINT,
   donorSeed: DONOR_SEED,
 }) => {
@@ -254,12 +254,3 @@
   }
   console.log('Chainql data correct');
 };
-
-main({
-  wsEndpoint: process.env.WS_RPC!,
-  donorSeed: process.env.SUPERUSER_SEED!,
-}).then(() => process.exit(0))
-  .catch((e) => {
-    console.error(e);
-    process.exit(1);
-  });
\ No newline at end of file