Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt xcm-utils to XCM V3 #2304

Merged
merged 16 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"license": "ISC",
"dependencies": {
"@metamask/eth-sig-util": "^4.0.1",
"@moonbeam-network/api-augment": "^0.2201.0",
"@moonbeam-network/api-augment": "^0.2301.0",
"@openzeppelin/contracts": "^4.8.2",
"@polkadot/api": "^10.1.4",
"@polkadot/api-augment": "^10.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const registerXcmTransactorAndContract = async (context: DevTestContext) => {
context.polkadotApi.tx.xcmTransactor.setTransactInfo(
RELAY_V3_SOURCE_LOCATION,
{ refTime: 1, proofSize: 64 * 1024 } as any,
{ refTime: 20000000000, proofSize: 256 * 1024 } as any,
{ refTime: 20_000_000_000, proofSize: 256 * 1024 } as any,
{ refTime: 1, proofSize: 64 * 1024 } as any
)
)
Expand Down
222 changes: 222 additions & 0 deletions tests/tests/test-xcm/test-xcmv3-max-weight-instructions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import "@moonbeam-network/api-augment";
import { expect } from "chai";
import { CHARLETH_ADDRESS } from "../../util/accounts";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import {
XcmFragment,
injectHrmpMessage,
RawXcmMessage,
sovereignAccountOfSibling,
} from "../../util/xcm";
import { expectEVMResult } from "../../util/eth-transactions";
import { ALITH_TRANSACTION_TEMPLATE, createTransaction } from "../../util/transactions";

describeDevMoonbeam(
"XCM V3 - Max Weight Instructions",
(context) => {
let dotAsset: any;
let amount: bigint;
let paraId: number;

before("Set up initial constants", async function () {
paraId = 888;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
const paraSovereign = sovereignAccountOfSibling(context, paraId);
const metadata = await context.polkadotApi.rpc.state.getMetadata();
const balancesPalletIndex = (metadata.asLatest.toHuman().pallets as Array<any>).find(
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
(pallet) => pallet.name === "Balances"
).index;

// Send some native tokens to the sovereign account of paraId (to pay fees)
const { result } = await context.createBlock(
createTransaction(context, {
...ALITH_TRANSACTION_TEMPLATE,
value: 1_000_000_000_000_000_000,
to: paraSovereign,
data: "0x",
})
);
expectEVMResult(result.events, "Succeed");

amount = 1_000_000_000_000_000n;
dotAsset = {
assets: [
{
multilocation: {
parents: 0,
interior: {
X1: { PalletInstance: balancesPalletIndex },
},
},
fungible: amount,
},
],
// weight_limit: new BN(4000000000),
beneficiary: CHARLETH_ADDRESS,
};
});

// WEIGHT::MAX instructions
it("Should not execute UniversalOrigin", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.universal_origin({ Parachain: paraId })
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
});

it("Should not execute ExportMessage", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.export_message("Ethereum", 1, [1, 2, 3])
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
});

it("Should not execute LockAsset", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.lock_asset(0, 1)
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
});

it("Should not execute UnlockAsset", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.unlock_asset()
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
});

it("Should not execute NoteUnlockable", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.note_unlockable()
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
});

it("Should not execute RequestUnlock", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.request_unlock()
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
});

it("Should not execute AliasOrigin", async function () {
const xcmMessage = new XcmFragment(dotAsset)
.withdraw_asset()
.buy_execution()
.alias_origin(1)
.as_v3();

// Mock the reception of the xcm message
await injectHrmpMessage(context, paraId, {
type: "XcmVersionedXcm",
payload: xcmMessage,
} as RawXcmMessage);
await context.createBlock();

// Search for WeightNotComputable error
const records = (await context.polkadotApi.query.system.events()) as any;
const events = records.filter(
({ event }) => event.section == "xcmpQueue" && event.method == "Fail"
);
expect(events).to.have.lengthOf(1);
expect(events[0].toHuman().event.data.error).equals("WeightNotComputable");
});
},
"Legacy",
"moonbase"
);
Loading