git.delta.rocks / unique-network / refs/commits / 7495d2ae3303

difftreelog

tests(maintenance)

Fahrrader2022-11-07parent: #e9b69c5.patch.diff
in: master

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
before · tests/package.json
1{2  "name": "unique-tests",3  "version": "1.0.0",4  "description": "Unique Chain Tests",5  "main": "",6  "devDependencies": {7    "@polkadot/typegen": "9.5.2",8    "@types/chai": "^4.3.3",9    "@types/chai-as-promised": "^7.1.5",10    "@types/chai-like": "^1.1.1",11    "@types/mocha": "^10.0.0",12    "@types/node": "^18.11.2",13    "@typescript-eslint/eslint-plugin": "^5.40.1",14    "@typescript-eslint/parser": "^5.40.1",15    "chai": "^4.3.6",16    "eslint": "^8.25.0",17    "eslint-plugin-mocha": "^10.1.0",18    "mocha": "^10.1.0",19    "ts-node": "^10.9.1",20    "typescript": "^4.8.4"21  },22  "mocha": {23    "timeout": 9999999,24    "require": [25      "ts-node/register"26    ]27  },28  "scripts": {29    "lint": "eslint --ext .ts,.js src/",30    "fix": "eslint --ext .ts,.js src/ --fix",31    "setup": "ts-node ./src/util/globalSetup.ts",32    "test": "yarn setup && mocha --timeout 9999999 -r ts-node/register './src/**/*.*test.ts'",33    "testParallelFull": "yarn testParallel && yarn testSequential",34    "testParallel": "yarn setup && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",35    "testSequential": "yarn setup && mocha --timeout 9999999 -r ts-node/register './src/**/*.seqtest.ts'",36    "testStructure": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/nesting/*.*test.ts",37    "testEth": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.*test.ts'",38    "testEthNesting": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.*test.ts'",39    "testEthFractionalizer": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.*test.ts'",40    "testEthMarketplace": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.*test.ts'",41    "testEvent": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.*test.ts",42    "testRmrk": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/rmrk/*.*test.ts",43    "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",44    "testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",45    "testEvmCoder": "mocha --timeout 9999999 -r ts-node/register './**/eth/evmCoder.test.ts'",46    "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",47    "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",48    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",49    "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",50    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",51    "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",52    "testChangeCollectionOwner": "mocha --timeout 9999999 -r ts-node/register ./**/change-collection-owner.test.ts",53    "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",54    "testConfirmSponsorship": "mocha --timeout 9999999 --parallel -r ts-node/register ./**/confirmSponsorship.test.ts",55    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",56    "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",57    "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",58    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",59    "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",60    "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",61    "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",62    "testCreateMultipleItemsEx": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItemsEx.test.ts",63    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",64    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",65    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",66    "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",67    "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",68    "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",69    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",70    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",71    "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",72    "testSetPermissions": "mocha --timeout 9999999 -r ts-node/register ./**/setPermissions.test.ts",73    "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",74    "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/eth/contractSponsoring.test.ts",75    "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",76    "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",77    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",78    "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",79    "testNextSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/nextSponsoring.test.ts",80    "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",81    "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",82    "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",83    "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",84    "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",85    "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",86    "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",87    "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",88    "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",89    "testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",90    "testEthNFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/nonFungible.test.ts",91    "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",92    "testEthRFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/reFungible.test.ts ./**/eth/reFungibleToken.test.ts",93    "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",94    "testEthFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/fungible.test.ts",95    "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",96    "testPromotion": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",97    "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",98    "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",99    "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",100    "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",101    "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",102    "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",103    "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",104    "loadTransfer": "ts-node src/transfer.nload.ts",105    "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",106    "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",107    "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",108    "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"109  },110  "author": "",111  "license": "SEE LICENSE IN ../LICENSE",112  "homepage": "",113  "dependencies": {114    "@polkadot/api": "9.5.2",115    "@polkadot/util-crypto": "10.1.11",116    "chai-as-promised": "^7.1.1",117    "chai-like": "^1.1.1",118    "find-process": "^1.4.7",119    "solc": "0.8.17",120    "web3": "^1.8.0"121  }122}
addedtests/src/maintenanceMode.seqtest.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/maintenanceMode.seqtest.ts
@@ -0,0 +1,264 @@
+// 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, usingPlaygrounds} from './util';
+import {itEth} from './eth/util';
+
+async function maintenanceEnabled(api: ApiPromise): Promise<boolean> {
+  return (await api.query.maintenance.enabled()).toJSON() as boolean;
+}
+
+describe('Integration Test: Maintenance Mode', () => {
+  let superuser: IKeyringPair;
+  let donor: IKeyringPair;
+  let bob: IKeyringPair;
+
+  before(async () => {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      superuser = await privateKey('//Alice');
+      donor = await privateKey({filename: __filename});
+      [bob] = await helper.arrange.createAccounts([100n], donor);
+
+      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('Allows superuser to enable and disable maintenance mode - and disallows anyone else', async ({helper}) => {
+    // Make sure non-sudo can't enable maintenance mode
+    await expect(helper.executeExtrinsic(superuser, 'api.tx.maintenance.enable', []), 'on commoner enabling MM').to.be.rejected; //With(/NoPermission/);
+
+    // Set maintenance mode
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    // Make sure non-sudo can't disable maintenance mode
+    await expect(helper.executeExtrinsic(bob, 'api.tx.maintenance.disable', []), 'on commoner disabling MM').to.be.rejected; //With(/NoPermission/);
+
+    // Disable maintenance mode
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+  });
+
+  itSub('MM blocks unique pallet calls', async ({helper}) => {
+    // Can create an NFT collection before enabling the MM
+    const nftCollection = await helper.nft.mintCollection(bob, {
+      tokenPropertyPermissions: [{key: 'test', permission: {
+        collectionAdmin: true,
+        tokenOwner: true,
+        mutable: true,
+      }}],
+    });
+
+    // Can mint an NFT before enabling the MM
+    const nft = await nftCollection.mintToken(bob);
+
+    // Can create an FT collection before enabling the MM
+    const ftCollection = await helper.ft.mintCollection(superuser);
+
+    // Can mint an FT before enabling the MM
+    await expect(ftCollection.mint(superuser)).to.be.fulfilled;
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    // Unable to create a collection when the MM is enabled
+    await expect(helper.nft.mintCollection(superuser), 'cudo forbidden stuff').to.be.rejected;
+
+    // Unable to set token properties when the MM is enabled
+    await expect(nft.setProperties(
+      bob,
+      [{key: 'test', value: 'test-val'}],
+    )).to.be.rejected;
+
+    // Unable to mint an NFT when the MM is enabled
+    await expect(nftCollection.mintToken(superuser)).to.be.rejected;
+
+    // Unable to mint an FT when the MM is enabled
+    await expect(ftCollection.mint(superuser)).to.be.rejected;
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+
+    // Can create a collection after disabling the MM
+    await expect(helper.nft.mintCollection(bob), 'MM is disabled, the collection should be created').to.be.fulfilled;
+
+    // Can set token properties after disabling the MM
+    await nft.setProperties(bob, [{key: 'test', value: 'test-val'}]);
+
+    // Can mint an NFT after disabling the MM
+    await nftCollection.mintToken(bob);
+
+    // Can mint an FT after disabling the MM
+    await ftCollection.mint(superuser);
+  });
+
+  itSub.ifWithPallets('MM blocks unique pallet calls (Re-Fungible)', [Pallets.ReFungible], async ({helper}) => {
+    // Can create an RFT collection before enabling the MM
+    const rftCollection = await helper.rft.mintCollection(superuser);
+
+    // Can mint an RFT before enabling the MM
+    await expect(rftCollection.mintToken(superuser)).to.be.fulfilled;
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    // Unable to mint an RFT when the MM is enabled
+    await expect(rftCollection.mintToken(superuser)).to.be.rejected;
+    
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+
+    // Can mint an RFT after disabling the MM
+    await rftCollection.mintToken(superuser);
+  });
+
+  itSub('MM allows native token transfers and RPC calls', async ({helper}) => {
+    // We can use RPC before the MM is enabled
+    const totalCount = await helper.collection.getTotalCount();
+
+    // We can transfer funds before the MM is enabled
+    await expect(helper.balance.transferToSubstrate(superuser, bob.address, 2n)).to.be.fulfilled;
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    // RPCs work while in maintenance
+    expect(await helper.collection.getTotalCount()).to.be.deep.equal(totalCount);
+
+    // We still able to transfer funds
+    await expect(helper.balance.transferToSubstrate(bob, superuser.address, 1n)).to.be.fulfilled;
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+
+    // RPCs work after maintenance
+    expect(await helper.collection.getTotalCount()).to.be.deep.equal(totalCount);
+
+    // Transfers work after maintenance
+    await expect(helper.balance.transferToSubstrate(bob, superuser.address, 1n)).to.be.fulfilled;
+  });
+
+  itSub.ifWithPallets('MM blocks scheduled calls and the scheduler itself', [Pallets.Scheduler], async ({helper}) => {
+    const collection = await helper.nft.mintCollection(bob);
+
+    const nftBeforeMM = await collection.mintToken(bob);
+    const nftDuringMM = await collection.mintToken(bob);
+    const nftAfterMM = await collection.mintToken(bob);
+
+    const scheduledIdBeforeMM = '0x' + '0'.repeat(31) + '0';
+    const scheduledIdDuringMM = '0x' + '0'.repeat(31) + '1';
+    const scheduledIdBunkerThroughMM = '0x' + '0'.repeat(31) + '2';
+    const scheduledIdAttemptDuringMM = '0x' + '0'.repeat(31) + '3';
+    const scheduledIdAfterMM = '0x' + '0'.repeat(31) + '4';
+
+    const blocksToWait = 6;
+
+    // Scheduling works before the maintenance
+    await nftBeforeMM.scheduleAfter(scheduledIdBeforeMM, blocksToWait)
+      .transfer(bob, {Substrate: superuser.address});
+
+    await helper.wait.newBlocks(blocksToWait + 1);
+    expect(await nftBeforeMM.getOwner()).to.be.deep.equal({Substrate: superuser.address});
+
+    // Schedule a transaction that should occur *during* the maintenance
+    await nftDuringMM.scheduleAfter(scheduledIdDuringMM, blocksToWait)
+      .transfer(bob, {Substrate: superuser.address});
+    
+    // Schedule a transaction that should occur *after* the maintenance
+    await nftDuringMM.scheduleAfter(scheduledIdBunkerThroughMM, blocksToWait * 2)
+      .transfer(bob, {Substrate: superuser.address});
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    await helper.wait.newBlocks(blocksToWait + 1);
+    // The owner should NOT change since the scheduled transaction should be rejected
+    expect(await nftDuringMM.getOwner()).to.be.deep.equal({Substrate: bob.address});
+
+    // Any attempts to schedule a tx during the MM should be rejected
+    await expect(nftDuringMM.scheduleAfter(scheduledIdAttemptDuringMM, blocksToWait)
+      .transfer(bob, {Substrate: superuser.address})).to.be.rejected;
+
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+
+    // Scheduling works after the maintenance
+    await nftAfterMM.scheduleAfter(scheduledIdAfterMM, blocksToWait)
+      .transfer(bob, {Substrate: superuser.address});
+    
+    await helper.wait.newBlocks(blocksToWait + 1);
+
+    expect(await nftAfterMM.getOwner()).to.be.deep.equal({Substrate: superuser.address});
+    // The owner of the token scheduled for transaction *before* maintenance should now change *after* maintenance
+    expect(await nftDuringMM.getOwner()).to.be.deep.equal({Substrate: superuser.address});
+  });
+
+  itEth('Disallows Ethereum transactions to execute while in maintenance', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const receiver = helper.eth.createAccount();
+    
+    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'A', 'B', 'C', '');
+
+    // Set maintenance mode
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+    const tokenId = await contract.methods.nextTokenId().call();
+    expect(tokenId).to.be.equal('1');
+
+    /*const result = */
+    await contract.methods.mintWithTokenURI(
+      receiver,
+      'Test URI',
+    ).send();
+    /*const expectedTokenId = result.events.Transfer.returnValues.tokenId;
+    expect(expectedTokenId).to.be.equal(tokenId);*/
+
+    await expect(contract.methods.ownerOf(tokenId).call()).rejectedWith(/token not found/);
+
+    // Disable maintenance mode
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+  });
+
+  itSub('Allows to enable and disable MM repeatedly', async ({helper}) => {
+    // Set maintenance mode
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.enable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is OFF when it should be ON').to.be.true;
+
+    // Disable maintenance mode
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+    expect(await maintenanceEnabled(helper.getApi()), 'MM is ON when it should be OFF').to.be.false;
+  });
+
+  afterEach(async () => {
+    await usingPlaygrounds(async helper => {
+      if (await maintenanceEnabled(helper.getApi())) {
+        console.warn('\tMaintenance mode was left enabled AFTER a test has finished! Be careful. Disabling it now.');
+        await helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.disable', []);
+      }
+      expect(await maintenanceEnabled(helper.getApi()), 'Disastrous! Exited the test suite with maintenance mode on.').to.be.false;
+    });
+  });
+});
\ No newline at end of file
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -86,6 +86,10 @@
           extrinsic: {},
           payload: {},
         },
+        CheckMaintenance: {
+          extrinsic: {},
+          payload: {},
+        },
         FakeTransactionFinalizer: {
           extrinsic: {},
           payload: {},