From f51a1dd5583a49917eee2342060a82cf5980a549 Mon Sep 17 00:00:00 2001 From: Pablo Labarta Date: Tue, 18 Feb 2025 07:59:25 -0300 Subject: [PATCH 1/2] rm: registerOldFA --- test/helpers/assets.ts | 98 ------------------------------------------ 1 file changed, 98 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 4ca79762a1..a948bf79be 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -279,104 +279,6 @@ export async function addAssetToWeightTrader(asset: any, relativePrice: bigint, } } -// This registers an old foreign asset via the asset-manager pallet. -// DEPRECATED: Please don't use for new tests -export async function registerOldForeignAsset( - context: DevModeContext, - asset: any, - metadata: AssetMetadata, - unitsPerSecond?: number, - numAssetsWeightHint?: number -) { - const { result } = await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo( - context.polkadotJs().tx.assetManager.registerForeignAsset(asset, metadata, new BN(1), true) - ) - ); - - const polkadotJs = await ApiPromise.create({ - provider: new WsProvider(`ws://localhost:${process.env.MOONWALL_RPC_PORT}/`), - ...runtimeApi, - }); - - const WEIGHT_REF_TIME_PER_SECOND = 1_000_000_000_000; - const weight = { - refTime: WEIGHT_REF_TIME_PER_SECOND, - proofSize: 0, - }; - - const nativeAmountPerSecond = await context - .polkadotJs() - .call.transactionPaymentApi.queryWeightToFee(weight); - - const relativePriceDecimals = new BN(18); - const relativePrice = nativeAmountPerSecond - .mul(new BN(10).pow(relativePriceDecimals)) - .div(unitsPerSecond ? new BN(unitsPerSecond) : new BN(1)); - - const assetV4 = patchLocationV4recursively(asset.Xcm); - const { result: result2 } = await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.xcmWeightTrader.addAsset(assetV4, relativePrice)), - { - expectEvents: [context.polkadotJs().events.xcmWeightTrader.SupportedAssetAdded as any], - allowFailures: false, - } - ); - - // If no unitspersecond is provided, we add the asset to the supported assets - // and force-set the relative price to 0 - if (unitsPerSecond == null) { - const module = xxhashAsU8a(new TextEncoder().encode("XcmWeightTrader"), 128); - const method = xxhashAsU8a(new TextEncoder().encode("SupportedAssets"), 128); - - const assetLocationU8a = context - .polkadotJs() - .createType("StagingXcmV4Location", assetV4) - .toU8a(); - - const blake2concatStagingXcmV4Location = new Uint8Array([ - ...blake2AsU8a(assetLocationU8a, 128), - ...assetLocationU8a, - ]); - - const overallAssetKey = new Uint8Array([ - ...module, - ...method, - ...blake2concatStagingXcmV4Location, - ]); - - await context.createBlock( - context.polkadotJs().tx.sudo.sudo( - context.polkadotJs().tx.system.setStorage([ - [ - u8aToHex(overallAssetKey), - "0x0100000000000000000000000000000000", // (enabled bool, 0 u128) - ], - ]) - ) - ); - } - - const registeredAssetId = result!.events - .find(({ event: { section } }) => section.toString() === "assetManager")! - .event.data[0].toHex() - .replace(/,/g, ""); - - // check asset in storage - const registeredAsset = ( - (await context.polkadotJs().query.assets.asset(registeredAssetId)) as any - ).unwrap(); - return { - registeredAssetId, - events: result2!.events, - registeredAsset, - }; -} - /** * * This registers a foreign asset via the moonbeam - foreign - assets pallet. From 1f48d1a0ac837461e0ac871ec23aa818dc629afd Mon Sep 17 00:00:00 2001 From: Pablo Labarta Date: Thu, 20 Feb 2025 10:02:48 -0300 Subject: [PATCH 2/2] refactor: maintenance test dep on old fa --- .../test-maintenance-filter3.ts | 146 +++++++++++------- 1 file changed, 86 insertions(+), 60 deletions(-) diff --git a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter3.ts b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter3.ts index 4a0fb36e7b..b7e9a0f6c2 100644 --- a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter3.ts +++ b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter3.ts @@ -2,58 +2,37 @@ import "@moonbeam-network/api-augment"; import { beforeAll, beforeEach, - customDevRpcRequest, describeSuite, expect, execOpenTechCommitteeProposal, } from "@moonwall/cli"; -import { ALITH_ADDRESS } from "@moonwall/util"; -import { BN } from "@polkadot/util"; -import { addAssetToWeightTrader } from "../../../../helpers"; +import { + expectSystemEvent, + fundAccount, + getPalletIndex, + injectHrmpMessage, + type RawXcmMessage, + sovereignAccountOfSibling, + XcmFragment, +} from "../../../../helpers"; describeSuite({ id: "D012003", title: "Maintenance Mode - Filter2", foundationMethods: "dev", testCases: ({ context, it, log }) => { - let assetId: string; + const assetId = 1; const foreignParaId = 2000; + const assetLocation = { + parents: 1, + interior: { + X3: [{ Parachain: foreignParaId }, { PalletInstance: 1 }, { GeneralIndex: 1 }], + }, + }; beforeAll(async () => { - const assetMetadata = { - name: "FOREIGN", - symbol: "FOREIGN", - decimals: new BN(12), - isFroze: false, - }; - - const sourceLocation = { - Xcm: { parents: 1, interior: { X1: { Parachain: foreignParaId } } }, - }; - - // registerForeignAsset - const { result } = await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo( - context - .polkadotJs() - .tx.assetManager.registerForeignAsset(sourceLocation, assetMetadata, new BN(1), true) - ) - ); - - const events = result?.events.find( - ({ event: { section } }) => section.toString() === "assetManager" - ); - - if (!events) { - throw new Error("Events Not Found!"); - } - - assetId = events.event.data[0].toHex().replace(/,/g, ""); - - // set relative price in xcmWeightTrader - await addAssetToWeightTrader(sourceLocation, 0n, context); + const paraAddress = sovereignAccountOfSibling(context, foreignParaId) as `0x${string}`; + await fundAccount(paraAddress, 1_000_000_000_000_000_000_000n, context); }); beforeEach(async () => { @@ -67,36 +46,83 @@ describeSuite({ id: "T01", title: "should queue XCM messages until resuming operations", test: async () => { - // Send RPC call to inject XCMP message - // You can provide a message, but if you don't a downward transfer is the default - await customDevRpcRequest("xcm_injectHrmpMessage", [foreignParaId, []]); + const createForeignAssetCall = context + .polkadotJs() + .tx.evmForeignAssets.createForeignAsset(assetId, assetLocation, 18, "TEST", "TEST"); - // Create a block in which the XCM should be executed - await context.createBlock(); + const { blockRes } = await sendCallAsParaUnchecked( + createForeignAssetCall, + foreignParaId, + context, + 1_000_000_000_000_000_000n + ); - // Make sure the state does not have ALITH's foreign asset tokens - let alithBalance = (await context - .polkadotJs() - .query.assets.account(assetId, ALITH_ADDRESS)) as any; - // Alith balance is 0 - expect(alithBalance.isNone).to.eq(true); + // Check asset has not been created yet + const assetInfo = await context.polkadotJs().query.evmForeignAssets.assetsById(assetId); + expect(assetInfo.isNone).to.eq(true); - // turn maintenance off + // Turn maintenance off await execOpenTechCommitteeProposal( context, context.polkadotJs().tx.maintenanceMode.resumeNormalOperation() ); - // Create a block in which the XCM will be executed - await context.createBlock(); - - // Make sure the state has ALITH's to foreign assets tokens - alithBalance = ( - await context.polkadotJs().query.assets.account(assetId, ALITH_ADDRESS) - ).unwrap(); - - expect(alithBalance.balance.toBigInt()).to.eq(10000000000000n); + // Expect the asset to be created + const currentBlock = await context.polkadotJs().rpc.chain.getBlock(); + await expectSystemEvent( + currentBlock.block.hash.toString(), + "evmForeignAssets", + "ForeignAssetCreated", + context + ); }, }); }, }); + +const sendCallAsParaUnchecked = async (call, paraId, context, fungible) => { + const encodedCall = call.method.toHex(); + const balancesPalletIndex = await getPalletIndex("Balances", context); + + const xcmMessage = new XcmFragment({ + assets: [ + { + multilocation: { + parents: 0, + interior: { + X1: { PalletInstance: balancesPalletIndex }, + }, + }, + fungible: fungible, + }, + ], + weight_limit: { + refTime: 40_000_000_000n, + proofSize: 150_000n, + }, + }) + .withdraw_asset() + .buy_execution() + .push_any({ + Transact: { + originKind: "Xcm", + requireWeightAtMost: { + refTime: 20_089_165_000n, + proofSize: 80_000n, + }, + call: { + encoded: encodedCall, + }, + }, + }) + .as_v4(); + + await injectHrmpMessage(context, paraId, { + type: "XcmVersionedXcm", + payload: xcmMessage, + } as RawXcmMessage); + + const blockRes = await context.createBlock(); + + return { blockRes }; +};