Skip to content

Commit

Permalink
Update smoke tests for the EVM native assets (#2955)
Browse files Browse the repository at this point in the history
* schedule recurrent build for benchmarks

* fix linting

* fix publish-runtime.yml workflow

* update deprecated set-output

* fix smoke test for foreign assets

* appease linter

* test: update foreign asset consistency test to use xcm-weight-trader

---------

Co-authored-by: Pablo Labarta <pablitolabarta@gmail.com>
  • Loading branch information
noandrea and pLabarta authored Sep 23, 2024
1 parent 241ad74 commit 850be55
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
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})`);
},
});
},
});

0 comments on commit 850be55

Please sign in to comment.