diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 0c981a6592..6dcf116bb1 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -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)) { @@ -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), })); diff --git a/test/suites/smoke/test-foreign-asset-consistency.ts b/test/suites/smoke/test-foreign-asset-consistency.ts index e2ac50813a..7b890a5d7e 100644 --- a/test/suites/smoke/test-foreign-asset-consistency.ts +++ b/test/suites/smoke/test-foreign-asset-consistency.ts @@ -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", @@ -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; @@ -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( @@ -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})` ); }, }); @@ -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 }); } } @@ -121,7 +140,7 @@ describeSuite({ .join(`\n`)}` ).to.equal(0); log( - `Verified ${foreignXcmAcceptedAssets.length} xcm ` + + `Verified ${xcmWeightManagerSupportedAssets.length} xcm ` + `fee payment assets (at #${atBlockNumber})` ); }, @@ -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})`); + }, + }); }, });