difftreelog
retry maintanence mode and fix tests
in: master
2 files changed
tests/src/migrations/942057-appPromotion/afterMaintenance.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {ApiPromise} from '@polkadot/api';19import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../../util';20import {main as testedScript} from './correctStateAfterMaintenance';2122async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {23 return (await api.query.maintenance.enabled()).toJSON() as boolean;24}25262728describe('Integration Test: Maintenance mode & App Promo', () => {29 let superuser: IKeyringPair;3031 before(async function() {32 await usingPlaygrounds(async (helper, privateKey) => {33 requirePalletsOrSkip(this, helper, [Pallets.Maintenance]);34 superuser = await privateKey('//Alice');35 });36 });3738 describe('Test AppPromo script for check state after Maintenance mode', () => {39 before(async function () {40 await usingPlaygrounds(async (helper) => {41 if(await maintenanceEnabled(helper.getApi())) {42 console.warn('\tMaintenance mode was left enabled BEFORE the test suite! Disabling it now.');43 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', [])).to.be.fulfilled;44 }45 });46 });47 itSub('Can find and fix inconsistent state', async({helper}) => {48 const api = helper.getApi();4950 await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [api.tx.system.setStorage([51 ['0x42b67acb8bd223c60d0c8f621ffefc0ae280fa2db99bd3827aac976de75af95f5153cb1f00942ff401000000',52 '0x04d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000010632d5ec76b0500000000000000'],53 ['0x42b67acb8bd223c60d0c8f621ffefc0ae280fa2db99bd3827aac976de75af95f9eb2dcce60f37a2702000000',54 '0x04d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000010632d5ec76b0500000000000000'],55 ['0xc2261276cc9d1f8598ea4b6a74b15c2fb1c0eb12e038e5c7f91e120ed4b7ebf1de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',56 '0x046170707374616b656170707374616b65000020c65abc8ed70a00000000000000'],57 ])]);5859 // const pendingUnstaked = await helper.staking.getPendingUnstakePerBlock()60 expect((await api.query.appPromotion.pendingUnstake(1)).toJSON()).to.be.deep.equal([[helper.address.normalizeSubstrateToChainFormat('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'), '0x00000000000000056bc75e2d63100000']]);61 expect((await api.query.appPromotion.pendingUnstake(2)).toJSON()).to.be.deep.equal([[helper.address.normalizeSubstrateToChainFormat('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'), '0x00000000000000056bc75e2d63100000']]);62 await testedScript();6364 expect((await api.query.appPromotion.pendingUnstake(1)).toJSON()).to.be.deep.equal([]);65 expect((await api.query.appPromotion.pendingUnstake(2)).toJSON()).to.be.deep.equal([]);6667 });6869 itSub('(!negative test!) Only works when Maintenance mode is disabled', async({helper}) => {70 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', [])).to.be.fulfilled;71 await expect(testedScript()).to.be.rejectedWith('The network is still in maintenance mode');72 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', [])).to.be.fulfilled;73 });74 });75});tests/src/util/frankenstein.tsdiffbeforeafterboth--- a/tests/src/util/frankenstein.ts
+++ b/tests/src/util/frankenstein.ts
@@ -85,17 +85,24 @@
}
// Enable or disable maintenance mode if present on the chain
-async function toggleMaintenanceMode(value: boolean, wsUri: string) {
- await usingPlaygrounds(async (helper, privateKey) => {
- const superuser = await privateKey(SUPERUSER_KEY);
- try {
- const toggle = value ? 'enable' : 'disable';
- await helper.getSudo().executeExtrinsic(superuser, `api.tx.maintenance.${toggle}`, []);
- console.log(`Maintenance mode ${value ? 'engaged' : 'disengaged'}.`);
- } catch (e) {
- console.error('Couldn\'t set maintenance mode. The maintenance pallet probably does not exist. Log:', e);
- }
- }, wsUri);
+async function toggleMaintenanceMode(value: boolean, wsUri: string, retries = 5) {
+ try {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const superuser = await privateKey(SUPERUSER_KEY);
+ try {
+ const toggle = value ? 'enable' : 'disable';
+ await helper.getSudo().executeExtrinsic(superuser, `api.tx.maintenance.${toggle}`, []);
+ console.log(`Maintenance mode ${value ? 'engaged' : 'disengaged'}.`);
+ } catch (e) {
+ console.error('Couldn\'t set maintenance mode. The maintenance pallet probably does not exist. Log:', e);
+ }
+ }, wsUri);
+ } catch (error) {
+ console.error(error);
+ console.log('Trying for retry toggle maintanence mode');
+ await delay(12_000);
+ await toggleMaintenanceMode(value, wsUri, retries - 1);
+ }
}
const raiseZombienet = async (): Promise<void> => {