Skip to content

Commit

Permalink
move xcm maintenance tests to common
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Sep 7, 2023
1 parent e2e20ae commit bb1dd0b
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 164 deletions.
135 changes: 135 additions & 0 deletions test/suites/common/test-maintenance/test-maintenance-mode-xcm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import "@polkadot/api-augment";
import { beforeAll, describeSuite, expect } from "@moonwall/cli";
import { KeyringPair } from "@moonwall/util";
import { ApiPromise } from "@polkadot/api";
import { initializeCustomCreateBlock } from "../../../util/block";
import { MultiLocation } from "../../../util/xcm";

describeSuite({
id: "C0101",
title: "XCM in maintenance mode",
foundationMethods: "dev",
testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;
let alice: KeyringPair;
let chain: string;

beforeAll(() => {
initializeCustomCreateBlock(context);

polkadotJs = context.pjsApi;
chain = polkadotJs.consts.system.version.specName.toString();
alice = context.keyring.alice;
});

it({
id: "E01",
title: "polkadotXcm calls disabled in maintenance mode",
test: async function () {
const tx = polkadotJs.tx.maintenanceMode.enterMaintenanceMode();
await context.createBlock([await polkadotJs.tx.sudo.sudo(tx).signAsync(alice)]);

const enabled = (await polkadotJs.query.maintenanceMode.maintenanceMode()).toJSON();
expect(enabled).to.be.true;

const destMultilocation: MultiLocation = {
parents: 1,
interior: { Here: null },
};

const dest = {
V3: destMultilocation,
};

const message = {
V3: [{ ClearOrigin: null }],
};

const polkadotXcmSend = context.polkadotJs().tx.polkadotXcm.send(dest, message);

if (chain == "frontier-template") {
expect(async () => await context.createBlock(polkadotXcmSend.signAsync(alice))).rejects.toThrowError(
"1010: Invalid Transaction: Transaction call is not expected"
);
} else {
const {result} = await context.createBlock([await polkadotXcmSend.signAsync(alice)]);
expect(result[0].successful).to.be.false;
expect(result[0].error.name).to.eq("CallFiltered");
}
},
});

it({
id: "E02",
title: "polkadotXcm calls enabled with sudo in maintenance mode",
test: async function () {
const tx = polkadotJs.tx.maintenanceMode.enterMaintenanceMode();
await context.createBlock([await polkadotJs.tx.sudo.sudo(tx).signAsync(alice)]);

const enabled = (await polkadotJs.query.maintenanceMode.maintenanceMode()).toJSON();
expect(enabled).to.be.true;

const destMultilocation: MultiLocation = {
parents: 1,
interior: { Here: null },
};

const dest = {
V3: destMultilocation,
};

const message = {
V3: [{ ClearOrigin: null }],
};

const polkadotXcmSend = context.polkadotJs().tx.polkadotXcm.send(dest, message);

const {result} = await context.createBlock([await polkadotJs.tx.sudo.sudo(polkadotXcmSend).signAsync(alice)]);

// Search for ExtrinsicSuccess event
const events = (await context.polkadotJs().query.system.events()).filter(({ event }) =>
context.polkadotJs().events.system.ExtrinsicSuccess.is(event)
);
expect(events.length).toBeGreaterThanOrEqual(1);
expect(result[0].successful).to.be.true;
expect(result[0].error).to.be.undefined;
},
});

it({
id: "E03",
title: "polkadotXcm calls allowed again after disabling maintenance mode",
test: async function () {
const tx = polkadotJs.tx.maintenanceMode.resumeNormalOperation();
await context.createBlock([await polkadotJs.tx.sudo.sudo(tx).signAsync(alice)]);

const enabled = (await polkadotJs.query.maintenanceMode.maintenanceMode()).toJSON();
expect(enabled).to.be.false;

const destMultilocation: MultiLocation = {
parents: 1,
interior: { Here: null },
};

const dest = {
V3: destMultilocation,
};

const message = {
V3: [{ ClearOrigin: null }],
};

const polkadotXcmSend = context.polkadotJs().tx.polkadotXcm.send(dest, message);
const { result } = await context.createBlock([await polkadotXcmSend.signAsync(alice)]);

// Search for ExtrinsicSuccess event
const events = (await context.polkadotJs().query.system.events()).filter(({ event }) =>
context.polkadotJs().events.system.ExtrinsicSuccess.is(event)
);
expect(events.length).toBeGreaterThanOrEqual(1);
expect(result[0].successful).to.be.true;
expect(result[0].error).to.be.undefined;
},
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import "@polkadot/api-augment";
import { beforeAll, describeSuite, expect } from "@moonwall/cli";
import { KeyringPair } from "@moonwall/util";
import { ApiPromise } from "@polkadot/api";
import { initializeCustomCreateBlock } from "../../util/block";
import { initializeCustomCreateBlock } from "../../../util/block";

describeSuite({
id: "C02",
id: "C0102",
title: "Maintenance mode test suite",
foundationMethods: "dev",
testCases: ({ it, context }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/common/xcm/test-mock-dmp-transact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../../../util/xcm.ts";

describeSuite({
id: "C0101",
id: "C0201",
title: "Mock XCM - Succeeds using sovereign accounts",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/common/xcm/test-mock-hrmp-transact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "../../../util/xcm.ts";

describeSuite({
id: "C0102",
id: "C0202",
title: "Mock XCM - Succeeds using sovereign accounts",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit bb1dd0b

Please sign in to comment.