1234567891011121314151617import {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 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});