git.delta.rocks / unique-network / refs/commits / 807186d3ad53

difftreelog

Merge pull request #950 from UniqueNetwork/tests/move-maintenance-to-seq

Yaroslav Bolyukin2023-06-14parents: #6c9848e #ca7b4bb.patch.diff
in: master
Move maintenance tests to seqtest

6 files changed

modifiedtests/src/maintenance.seqtest.tsdiffbeforeafterboth
--- a/tests/src/maintenance.seqtest.ts
+++ b/tests/src/maintenance.seqtest.ts
@@ -19,6 +19,7 @@
 import {expect, itSched, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
 import {itEth} from './eth/util';
 import {UniqueHelper} from './util/playgrounds/unique';
+import {main as correctState} from './migrations/correctStateAfterMaintenance';
 
 async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {
   return (await api.query.maintenance.enabled()).toJSON() as boolean;
@@ -367,4 +368,59 @@
       });
     });
   });
+
+  describe('Integration Test: Maintenance mode & App Promo', () => {
+    let superuser: IKeyringPair;
+
+    before(async function() {
+      await usingPlaygrounds(async (helper, privateKey) => {
+        requirePalletsOrSkip(this, helper, [Pallets.Maintenance]);
+        superuser = await privateKey('//Alice');
+      });
+    });
+
+    describe('Test AppPromo script for check state after Maintenance mode', () => {
+      before(async function () {
+        await usingPlaygrounds(async (helper) => {
+          if(await maintenanceEnabled(helper.getApi())) {
+            console.warn('\tMaintenance mode was left enabled BEFORE the test suite! Disabling it now.');
+            await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', [])).to.be.fulfilled;
+          }
+        });
+      });
+      itSub('Can find and fix inconsistent state', async ({helper}) => {
+        const api = helper.getApi();
+
+        await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [api.tx.system.setStorage([
+          // pendingUnstake(1 -> [superuser.address, 100UNQ])
+          ['0x42b67acb8bd223c60d0c8f621ffefc0ae280fa2db99bd3827aac976de75af95f5153cb1f00942ff401000000',
+            '0x04d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000010632d5ec76b0500000000000000'],
+          // pendingUnstake(2 -> [superuser.address, 100UNQ])
+          ['0x42b67acb8bd223c60d0c8f621ffefc0ae280fa2db99bd3827aac976de75af95f9eb2dcce60f37a2702000000',
+            '0x04d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000010632d5ec76b0500000000000000'],
+          // Balances.freezes(superuser.address -> freeze with app promo id and 200 UNQ )
+          ['0xc2261276cc9d1f8598ea4b6a74b15c2fb1c0eb12e038e5c7f91e120ed4b7ebf1de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
+            '0x046170707374616b656170707374616b65000020c65abc8ed70a00000000000000'],
+        ])]);
+
+        expect((await api.query.appPromotion.pendingUnstake(1)).toJSON()).to.be.deep.equal([[superuser.address, '0x00000000000000056bc75e2d63100000']]);
+        expect((await api.query.appPromotion.pendingUnstake(2)).toJSON()).to.be.deep.equal([[superuser.address, '0x00000000000000056bc75e2d63100000']]);
+        expect((await api.query.balances.freezes(superuser.address))
+          .map(lock => ({id: lock.id.toUtf8(), amount: lock.amount.toBigInt()})))
+          .to.be.deep.equal([{id: 'appstakeappstake', amount: 200000000000000000000n}]);
+        await correctState();
+
+        expect((await api.query.appPromotion.pendingUnstake(1)).toJSON()).to.be.deep.equal([]);
+        expect((await api.query.appPromotion.pendingUnstake(2)).toJSON()).to.be.deep.equal([]);
+        expect((await api.query.balances.freezes(superuser.address)).toJSON()).to.be.deep.equal([]);
+
+      });
+
+      itSub('(!negative test!) Only works when Maintenance mode is disabled', async({helper}) => {
+        await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', [])).to.be.fulfilled;
+        await expect(correctState()).to.be.rejectedWith('The network is still in maintenance mode');
+        await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', [])).to.be.fulfilled;
+      });
+    });
+  });
 });
deletedtests/src/migrations/942057-appPromotion/afterMaintenance.test.tsdiffbeforeafterboth
--- a/tests/src/migrations/942057-appPromotion/afterMaintenance.test.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {IKeyringPair} from '@polkadot/types/types';
-import {ApiPromise} from '@polkadot/api';
-import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../../util';
-import {main as testedScript} from './correctStateAfterMaintenance';
-
-async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {
-  return (await api.query.maintenance.enabled()).toJSON() as boolean;
-}
-
-
-
-describe('Integration Test: Maintenance mode & App Promo', () => {
-  let superuser: IKeyringPair;
-
-  before(async function() {
-    await usingPlaygrounds(async (helper, privateKey) => {
-      requirePalletsOrSkip(this, helper, [Pallets.Maintenance]);
-      superuser = await privateKey('//Alice');
-    });
-  });
-
-  describe('Test AppPromo script for check state after Maintenance mode', () => {
-    before(async function () {
-      await usingPlaygrounds(async (helper) => {
-        if(await maintenanceEnabled(helper.getApi())) {
-          console.warn('\tMaintenance mode was left enabled BEFORE the test suite! Disabling it now.');
-          await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', [])).to.be.fulfilled;
-        }
-      });
-    });
-    itSub('Can find and fix inconsistent state', async({helper}) => {
-      const api = helper.getApi();
-
-      await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [api.tx.system.setStorage([
-        ['0x42b67acb8bd223c60d0c8f621ffefc0ae280fa2db99bd3827aac976de75af95f5153cb1f00942ff401000000',
-          '0x04d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000010632d5ec76b0500000000000000'],
-        ['0x42b67acb8bd223c60d0c8f621ffefc0ae280fa2db99bd3827aac976de75af95f9eb2dcce60f37a2702000000',
-          '0x04d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000010632d5ec76b0500000000000000'],
-        ['0xc2261276cc9d1f8598ea4b6a74b15c2fb1c0eb12e038e5c7f91e120ed4b7ebf1de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
-          '0x046170707374616b656170707374616b65000020c65abc8ed70a00000000000000'],
-      ])]);
-
-      // const pendingUnstaked = await helper.staking.getPendingUnstakePerBlock()
-      expect((await api.query.appPromotion.pendingUnstake(1)).toJSON()).to.be.deep.equal([[helper.address.normalizeSubstrateToChainFormat('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'), '0x00000000000000056bc75e2d63100000']]);
-      expect((await api.query.appPromotion.pendingUnstake(2)).toJSON()).to.be.deep.equal([[helper.address.normalizeSubstrateToChainFormat('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'), '0x00000000000000056bc75e2d63100000']]);
-      await testedScript();
-
-      expect((await api.query.appPromotion.pendingUnstake(1)).toJSON()).to.be.deep.equal([]);
-      expect((await api.query.appPromotion.pendingUnstake(2)).toJSON()).to.be.deep.equal([]);
-
-    });
-
-    itSub('(!negative test!) Only works when Maintenance mode is disabled', async({helper}) => {
-      await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', [])).to.be.fulfilled;
-      await expect(testedScript()).to.be.rejectedWith('The network is still in maintenance mode');
-      await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', [])).to.be.fulfilled;
-    });
-  });
-});
deletedtests/src/migrations/942057-appPromotion/correctStateAfterMaintenance.tsdiffbeforeafterboth
--- a/tests/src/migrations/942057-appPromotion/correctStateAfterMaintenance.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import {usingPlaygrounds} from '../../util';
-
-
-
-const WS_ENDPOINT = 'ws://localhost:9944';
-const DONOR_SEED = '//Alice';
-
-export const main = async(options: { wsEndpoint: string; donorSeed: string } = {
-  wsEndpoint: WS_ENDPOINT,
-  donorSeed: DONOR_SEED,
-}) => {
-  await usingPlaygrounds(async (helper, privateKey) => {
-    const api = helper.getApi();
-
-    if((await api.query.maintenance.enabled()).valueOf()) {
-      throw Error('The network is still in maintenance mode');
-    }
-
-    const pendingBlocks = (
-      await api.query.appPromotion.pendingUnstake.entries()
-    ).map(([k, _v]) =>
-      k.args[0]);
-
-    const currentBlock = await api.query.system.number();
-
-    const filteredBlocks = pendingBlocks.filter((b) => currentBlock.gt(b));
-
-    if(filteredBlocks.length != 0) {
-      console.log(
-        'During maintenance mode, %d block(s) were not processed',
-        filteredBlocks.length,
-      );
-    } else {
-      console.log('Nothing to change');
-      return;
-    }
-
-    const skippedBlocks = chunk(filteredBlocks, 10);
-
-    const signer = await privateKey(options.donorSeed);
-
-    const txs = skippedBlocks.map((b) =>
-      api.tx.sudo.sudo(api.tx.appPromotion.forceUnstake(b)));
-
-
-    const promises = txs.map((tx) => () => helper.signTransaction(signer, tx));
-
-    await Promise.allSettled(promises.map((p) => p()));
-
-    const failedBlocks: bigint[] = [];
-    let isSuccess = true;
-
-    for(const b of filteredBlocks) {
-      if(((await api.query.appPromotion.pendingUnstake(b)).toJSON() as any[]).length != 0) {
-        failedBlocks.push(b.toBigInt());
-        isSuccess = false;
-      }
-    }
-
-    if(isSuccess) {
-      console.log('Done. %d block(s) were processed.', filteredBlocks.length);
-    } else {
-      throw new Error(`Something went wrong. Block(s) have not been processed: ${failedBlocks}`);
-    }
-
-
-  }, options.wsEndpoint);
-};
-
-const chunk = <T>(arr: T[], size: number) =>
-  Array.from({length: Math.ceil(arr.length / size)}, (_: any, i: number) =>
-    arr.slice(i * size, i * size + size));
\ No newline at end of file
deletedtests/src/migrations/942057-appPromotion/runCheckState.tsdiffbeforeafterboth
--- a/tests/src/migrations/942057-appPromotion/runCheckState.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import {main} from './correctStateAfterMaintenance';
-
-
-
-
-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
addedtests/src/migrations/correctStateAfterMaintenance.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/migrations/correctStateAfterMaintenance.ts
@@ -0,0 +1,72 @@
+import {usingPlaygrounds} from '../util';
+
+
+
+const WS_ENDPOINT = 'ws://localhost:9944';
+const DONOR_SEED = '//Alice';
+
+export const main = async(options: { wsEndpoint: string; donorSeed: string } = {
+  wsEndpoint: WS_ENDPOINT,
+  donorSeed: DONOR_SEED,
+}) => {
+  await usingPlaygrounds(async (helper, privateKey) => {
+    const api = helper.getApi();
+
+    if((await api.query.maintenance.enabled()).valueOf()) {
+      throw Error('The network is still in maintenance mode');
+    }
+
+    const pendingBlocks = (
+      await api.query.appPromotion.pendingUnstake.entries()
+    ).map(([k, _v]) =>
+      k.args[0]);
+
+    const currentBlock = await api.query.system.number();
+
+    const filteredBlocks = pendingBlocks.filter((b) => currentBlock.gt(b));
+
+    if(filteredBlocks.length != 0) {
+      console.log(
+        'During maintenance mode, %d block(s) were not processed',
+        filteredBlocks.length,
+      );
+    } else {
+      console.log('Nothing to change');
+      return;
+    }
+
+    const skippedBlocks = chunk(filteredBlocks, 10);
+
+    const signer = await privateKey(options.donorSeed);
+
+    const txs = skippedBlocks.map((b) =>
+      api.tx.sudo.sudo(api.tx.appPromotion.forceUnstake(b)));
+
+
+    const promises = txs.map((tx) => () => helper.signTransaction(signer, tx));
+
+    await Promise.allSettled(promises.map((p) => p()));
+
+    const failedBlocks: bigint[] = [];
+    let isSuccess = true;
+
+    for(const b of filteredBlocks) {
+      if(((await api.query.appPromotion.pendingUnstake(b)).toJSON() as any[]).length != 0) {
+        failedBlocks.push(b.toBigInt());
+        isSuccess = false;
+      }
+    }
+
+    if(isSuccess) {
+      console.log('Done. %d block(s) were processed.', filteredBlocks.length);
+    } else {
+      throw new Error(`Something went wrong. Block(s) have not been processed: ${failedBlocks}`);
+    }
+
+
+  }, options.wsEndpoint);
+};
+
+const chunk = <T>(arr: T[], size: number) =>
+  Array.from({length: Math.ceil(arr.length / size)}, (_: any, i: number) =>
+    arr.slice(i * size, i * size + size));
\ No newline at end of file
addedtests/src/migrations/runCheckState.tsdiffbeforeafterboth

no changes