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

Update smoke tests for the EVM native assets #2955

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions .github/workflows/check-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Check benchmarks

on:
workflow_dispatch:
on:
schedule:
- cron: "0 5 * * 0" # Runs every Sunday at 5:00 AM UTC
- cron: "0 5 * * 3" # Runs every Wednesday at 5:00 AM UTC

jobs:
set-tags:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- id: get-version
run: |
RUST_VERSION=$(cat rust-toolchain | grep channel | grep --only-matching --perl-regexp "(\d+\.){2}\d+(-nightly)?")
echo "::set-output name=rust_version::$RUST_VERSION"
echo "rust_version=$RUST_VERSION" >> $GITHUB_OUTPUT

build-srtool-runtimes:
needs: ["setup-scripts", "read-rust-version"]
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
GH_WORKFLOW_MATRIX_CHAIN: ${{ matrix.chain }}
GH_WORKFLOW_MATRIX_SRTOOL_IMAGE: ${{ matrix.srtool_image }}
GH_WORKFLOW_MATRIX_SRTOOL_IMAGE_TAG: ${{ matrix.srtool_image_tag }}
RUNTIME_BUILD_OPTS: "--features on-chain-release-build"
noandrea marked this conversation as resolved.
Show resolved Hide resolved
RUNTIME_BUILD_OPTS: "--features=on-chain-release-build"
RUNTIME_BUILD_PROFILE: "production"
run: |
# Ensure we have permissions to write to the runtime folder target for the docker user
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function assetContractAddress(assetId: bigint | string): `0x${string}` {
return `0xffffffff${BigInt(assetId).toString(16)}`;
}

const patchLocationV4recursively = (value: any) => {
export const patchLocationV4recursively = (value: any) => {
// e.g. Convert this: { X1: { Parachain: 1000 } } to { X1: [ { Parachain: 1000 } ] }
if (value && typeof value == "object") {
if (Array.isArray(value)) {
Expand All @@ -61,7 +61,7 @@ const patchLocationV4recursively = (value: any) => {
if (k === "Concrete" || k === "Abstract") {
return patchLocationV4recursively(value[k]);
}
if (k.match(/^X\d$/g) && !Array.isArray(value[k])) {
if (k.match(/^[Xx]\d$/g) && !Array.isArray(value[k])) {
value[k] = Object.entries(value[k]).map(([k, v]) => ({
[k]: patchLocationV4recursively(v),
}));
Expand Down
70 changes: 58 additions & 12 deletions test/suites/smoke/test-foreign-asset-consistency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "@moonbeam-network/api-augment";
import { ApiDecoration } from "@polkadot/api/types";
import { describeSuite, expect, beforeAll } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";
import { patchLocationV4recursively } from "../../helpers";

describeSuite({
id: "S12",
Expand All @@ -12,7 +13,7 @@ describeSuite({
let apiAt: ApiDecoration<"promise">;
const foreignAssetIdType: { [assetId: string]: string } = {};
const foreignAssetTypeId: { [assetType: string]: string } = {};
const foreignXcmAcceptedAssets: string[] = [];
const xcmWeightManagerSupportedAssets: string[] = [];
let liveForeignAssets: { [key: string]: boolean };
let specVersion: number;
let paraApi: ApiPromise;
Expand Down Expand Up @@ -40,12 +41,17 @@ describeSuite({
foreignAssetTypeId[assetType] = exposure.unwrap().toString();
});

query = await apiAt.query.assetManager.assetTypeUnitsPerSecond.entries();

query.forEach(([key, _]) => {
const assetType = key.args.toString();
foreignXcmAcceptedAssets.push(assetType);
});
if (specVersion >= 3200) {
query = await apiAt.query.xcmWeightTrader.supportedAssets.entries();
query.forEach(([key, _]) => {
const assetType = key.args.toString();
xcmWeightManagerSupportedAssets.push(assetType);
});
}
// log(`Foreign Xcm Accepted Assets: ${foreignXcmAcceptedAssets}`);
// log(`Foreign AssetId<->AssetType: ${JSON.stringify(foreignAssetIdType)}`);
// foreignAssetTypeId
// log(`Foreign AssetType<->AssetId: ${JSON.stringify(foreignAssetTypeId)}`);

if (specVersion >= 2200) {
liveForeignAssets = (await apiAt.query.assets.asset.entries()).reduce(
Expand All @@ -63,14 +69,14 @@ describeSuite({
title: `should make sure xcm fee assets accepted is <=> than existing assets`,
test: async function () {
expect(
foreignXcmAcceptedAssets.length,
xcmWeightManagerSupportedAssets.length,
`Number of foreign asset deposits does not match the number of foreign assets`
).to.be.lessThanOrEqual(Object.keys(foreignAssetIdType).length);

log(
`Verified FOREIGN asset counter (${
Object.keys(foreignAssetIdType).length
}) >= xcm fee payment assets: (${foreignXcmAcceptedAssets.length})`
}) >= xcm fee payment assets: (${xcmWeightManagerSupportedAssets.length})`
);
},
});
Expand Down Expand Up @@ -108,8 +114,21 @@ describeSuite({
test: async function () {
const failedXcmPaymentAssets: { assetType: string }[] = [];

for (const assetType of foreignXcmAcceptedAssets) {
if (!Object.keys(foreignAssetTypeId).includes(assetType)) {
log(`xcmWeightManagerSupportedAssets: ${xcmWeightManagerSupportedAssets}`);

// Patch the location
const xcmForForeignAssets = Object.values(foreignAssetIdType).map((type) => {
const parents = JSON.parse(type).xcm.parents;
const interior = JSON.parse(type).xcm.interior;
patchLocationV4recursively(interior);
return JSON.stringify({
parents,
interior,
});
});

for (const assetType of xcmWeightManagerSupportedAssets) {
if (!xcmForForeignAssets.includes(assetType)) {
failedXcmPaymentAssets.push({ assetType });
}
}
Expand All @@ -121,7 +140,7 @@ describeSuite({
.join(`\n`)}`
).to.equal(0);
log(
`Verified ${foreignXcmAcceptedAssets.length} xcm ` +
`Verified ${xcmWeightManagerSupportedAssets.length} xcm ` +
`fee payment assets (at #${atBlockNumber})`
);
},
Expand Down Expand Up @@ -180,5 +199,32 @@ describeSuite({
log(`Verified ${liveAssets.length} live assets (at #${atBlockNumber})`);
},
});

it({
id: "C500",
title: "should make sure all live assets are supported by xcmWeightManager",
test: async function () {
if (specVersion < 2200) {
log(`ChainSpec ${specVersion} unsupported, skipping.`);
return;
}

const notLiveAssets: string[] = [];
const liveAssets = Object.keys(liveForeignAssets);
for (const assetId of liveAssets) {
if (!(assetId in foreignAssetIdType)) {
notLiveAssets.push(assetId);
}
}

expect(
notLiveAssets.length,
`Failed not managed live assets - ${notLiveAssets
.map((assetId) => `expected: ${assetId} to be managed`)
.join(`\n`)}`
).to.equal(0);
log(`Verified ${liveAssets.length} live assets (at #${atBlockNumber})`);
},
});
},
});
Loading