From 4c2d0630687510d3529e643821eb73d253734b09 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 21 Nov 2024 10:56:06 +0100 Subject: [PATCH 01/25] added chopsticks folder with set-up and tests --- .../chopsticks/configs/README.md | 6 + .../configs/westend-asset-hub-override.yaml | 32 +++++ .../chopsticks/configs/westend-override.yaml | 21 +++ .../chopsticks/tests/v5-tests/README.md | 18 +++ .../chopsticks/tests/v5-tests/index.ts | 124 ++++++++++++++++++ .../chopsticks/wasms/README.md | 9 ++ 6 files changed, 210 insertions(+) create mode 100644 cumulus/parachains/integration-tests/chopsticks/configs/README.md create mode 100644 cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml create mode 100644 cumulus/parachains/integration-tests/chopsticks/configs/westend-override.yaml create mode 100644 cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md create mode 100644 cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts create mode 100644 cumulus/parachains/integration-tests/chopsticks/wasms/README.md diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/README.md b/cumulus/parachains/integration-tests/chopsticks/configs/README.md new file mode 100644 index 000000000000..12baa4ee2559 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/configs/README.md @@ -0,0 +1,6 @@ +This folder serves as a reference documentation for chopstick tests and the Parity-owned ecosystems. +It provides a working set of configuration files together with the WASM BLOBs, specifically for the Westend ecosystem. +For additional resources and original Acala configuration files, including documentation, refer to the [Acala repository](https://github.com/AcalaNetwork/chopsticks/tree/master/configs) or [Papermoon chopsticks overview](https://papermoonio.github.io/polkadot-ecosystem-docs-draft/dev-tools/chopsticks/overview/#using-a-configuration-file) + +Config files, especially `wasm-override:` fields there, assume that there is a `wasms` folder within the same parent directory, and it contains pre-built WASM BLOBs of the +ecosystem under tests. diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml new file mode 100644 index 000000000000..4b448f0864d4 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml @@ -0,0 +1,32 @@ +endpoint: wss://asset-hub-polkadot-rpc.dwellir.com +mock-signature-host: true +block: ${env.WESTEND_ASSET_HUB_BLOCK_NUMBER} +db: ./db.sqlite +runtime-log-level: 5 +wasm-override: wasms/asset_hub_westend_runtime.compact.compressed.wasm + +import-storage: + System: + Account: + - + - + - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice + - providers: 1 + data: + free: 1000000000000000 + - + - + - 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia + - providers: 1 + data: + free: 1000000000000000 + - + - + - 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty # Bob + - providers: 1 + data: + free: 1000000000000000 +# Assets: +# Account: +# - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] +# - [[1984, 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia], { balance: 1000000000 }] diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-override.yaml new file mode 100644 index 000000000000..a8e5c58c7eca --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-override.yaml @@ -0,0 +1,21 @@ +endpoint: + - wss://westend-rpc.dwellir.com +mock-signature-host: true +block: ${env.WESTEND_BLOCK_NUMBER} +db: ./db.sqlite +runtime-log-level: 5 +wasm-override: wasms/westend_runtime.compact.compressed.wasm + +import-storage: + XcmPallet: + SafeXcmVersion: 5 + System: + Account: + - + - + - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY + - providers: 1 + data: + free: '10000000000000000000' + ParasDisputes: + $removePrefix: ['disputes'] diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md new file mode 100644 index 000000000000..7740f0b42cdf --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md @@ -0,0 +1,18 @@ +# v5-sac-test + +To install dependencies: + +```bash +bun add polkadot-api +# now you need to switch to another terminal window where you executed bunx command, make sure that chains are running and copy Asset Hub's port in the command below (usually the port is 8001). +bun papi add wnd_ah -w ws://localhost:8001 +bun add @polkadot-labs/hdkd +``` + +To run the test: + +```bash +bun test ./index.ts +``` + +This project was created using `bun init` in bun v1.1.34. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts new file mode 100644 index 000000000000..6203a385c3bd --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -0,0 +1,124 @@ +import { test, expect } from "bun:test"; +import { + wnd_ah, + XcmV3Junctions, + XcmV3Junction, + XcmV3MultiassetFungibility, + XcmV4Instruction, + XcmV3WeightLimit, + XcmV3MultiassetMultiAssetFilter +} from "@polkadot-api/descriptors"; +import { Binary, Enum, createClient } from "polkadot-api"; +import { getWsProvider } from "polkadot-api/ws-provider/web"; +import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"; +import { sr25519CreateDerive } from "@polkadot-labs/hdkd"; +import { + DEV_PHRASE, + entropyToMiniSecret, + mnemonicToEntropy, +} from "@polkadot-labs/hdkd-helpers"; +import { getPolkadotSigner } from "polkadot-api/signer"; + +const WESTEND_NETWORK = Uint8Array.from([225, 67, 242, 56, 3, 172, 80, 232, 246, 248, 230, 38, 149, 209, 206, 158, 78, 29, 104, 170, 54, 193, 205, 44, 253, 21, 52, 2, 19, 243, 66, 62]); +// TODO: find a way to extract keys below from yaml config. +const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; +const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; + +// Create and initialize client +const client = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"))); +const AHApi = client.getTypedApi(wnd_ah); + +// Initialize HDKD key pairs and signers +const entropy = mnemonicToEntropy(DEV_PHRASE); +const miniSecret = entropyToMiniSecret(entropy); +const derive = sr25519CreateDerive(miniSecret); + +const hdkdKeyPairAlice = derive("//Alice"); +const hdkdKeyPairBob = derive("//Bob"); + +const aliceSigner = getPolkadotSigner( + hdkdKeyPairAlice.publicKey, + "Sr25519", + hdkdKeyPairAlice.sign, +); + +const bobSigner = getPolkadotSigner( + hdkdKeyPairBob.publicKey, + "Sr25519", + hdkdKeyPairBob.sign, +); + +// Utility function for balance fetching +async function getFreeBalance(api, accountKey) { + const balance = await api.query.System.Account.getValue(accountKey); + return balance.data.free; +} + +test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { + const bobBalanceBefore = await getFreeBalance(AHApi, BOB_KEY); + + // Transaction 1: Alice sets asset claimer to Bob and sends a trap transaction + const trapTx = AHApi.tx.PolkadotXcm.execute({ + message: Enum("V5", [ + Enum("SetAssetClaimer", { + location: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })) + }, + }), + XcmV4Instruction.WithdrawAsset([{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }]), + XcmV4Instruction.ClearOrigin(), + ]), + max_weight: { ref_time: 100_000_000_000n, proof_size: 300_000n }, + }); + + const trapResult = await trapTx.signAndSubmit(aliceSigner); + expect(trapResult.ok).toBeTruthy(); + + // Transaction 2: Bob claims trapped assets. + const bobClaimTx = AHApi.tx.PolkadotXcm.execute({ + message: Enum("V4", [ + XcmV4Instruction.ClaimAsset({ + assets: [{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }], + ticket: { parents: 0, interior: XcmV3Junctions.Here() }, + }), + XcmV4Instruction.BuyExecution({ + fees: { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000n), + }, + weight_limit: XcmV3WeightLimit.Unlimited(), + }), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 1, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })) + } + }), + ]), + max_weight: { ref_time: 100_000_000_000n, proof_size: 300_000n }, + }); + + const claimResult = await bobClaimTx.signAndSubmit(bobSigner); + expect(claimResult.ok).toBeTruthy(); + + + const bobBalanceAfter = await getFreeBalance(AHApi, BOB_KEY); + expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); +}); diff --git a/cumulus/parachains/integration-tests/chopsticks/wasms/README.md b/cumulus/parachains/integration-tests/chopsticks/wasms/README.md new file mode 100644 index 000000000000..80d7f273ef60 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/wasms/README.md @@ -0,0 +1,9 @@ +This folder contains WASM BLOBs which are supposed to be used by chopstick tests. +To populate this folder with the required files you need to: +1. BUILD relevant runtimes: usually relay and parachain(s). +- `cargo build --release -p westend-runtime ` +- `cargo build --release -p asset-hub-westend-runtime ` +2. Copy compressed wasms from target folder into the current one: +- `WBUILD_PATH=../../../../../target/release/wbuild` +- `cp $WBUILD_PATH/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm .` +- `cp $WBUILD_PATH/westend-runtime/westend_runtime.compact.compressed.wasm .` From 33c3a092f0d89462ae65c87fc4d66bc1e39b7215 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 21 Nov 2024 11:01:58 +0100 Subject: [PATCH 02/25] added bridge-hub config + improved readme --- .../configs/westend-bridge-hub-override.yaml | 32 +++++++++++++++++++ .../chopsticks/tests/v5-tests/README.md | 1 + 2 files changed, 33 insertions(+) create mode 100644 cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml new file mode 100644 index 000000000000..a71a3a8334a3 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml @@ -0,0 +1,32 @@ +endpoint: wss://bridge-hub-polkadot-rpc.dwellir.com +mock-signature-host: true +block: ${env.WESTEND_BRIDGE_HUB_BLOCK_NUMBER} +db: ./db.sqlite +runtime-log-level: 5 +wasm-override: wasms/bridge_hub_westend_runtime.compact.compressed.wasm + +import-storage: + System: + Account: + - + - + - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice + - providers: 1 + data: + free: 1000000000000000 + - + - + - 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia + - providers: 1 + data: + free: 1000000000000000 + - + - + - 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty # Bob + - providers: 1 + data: + free: 1000000000000000 +# Assets: +# Account: +# - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] +# - [[1984, 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia], { balance: 1000000000 }] diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md index 7740f0b42cdf..7ebf5f27e568 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md @@ -13,6 +13,7 @@ To run the test: ```bash bun test ./index.ts +# note: the test may time out during the first run. Single retry usually helps. ``` This project was created using `bun init` in bun v1.1.34. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. From eed6aaff99412d777cd58531a78a44defe62cfda Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 21 Nov 2024 11:31:18 +0100 Subject: [PATCH 03/25] added xcm v4 initiate teleport test --- .../chopsticks/tests/v5-tests/index.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 6203a385c3bd..17111e698fc0 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -6,7 +6,8 @@ import { XcmV3MultiassetFungibility, XcmV4Instruction, XcmV3WeightLimit, - XcmV3MultiassetMultiAssetFilter + XcmV3MultiassetMultiAssetFilter, + XcmV4AssetAssetFilter } from "@polkadot-api/descriptors"; import { Binary, Enum, createClient } from "polkadot-api"; import { getWsProvider } from "polkadot-api/ws-provider/web"; @@ -122,3 +123,38 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { const bobBalanceAfter = await getFreeBalance(AHApi, BOB_KEY); expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); }); + +test("Initiate Teleport XCM v4", async () => { + const WndToAH = AHApi.tx.PolkadotXcm.execute({ + message: Enum("V4", [ + XcmV4Instruction.WithdrawAsset([{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(7e12), + }]), + XcmV4Instruction.SetFeesMode({ + jit_withdraw: true, + }), + XcmV4Instruction.InitiateTeleport({ + assets: XcmV4AssetAssetFilter.Wild({type: "All", value: undefined}), + dest: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + xcm: [ + XcmV4Instruction.BuyExecution({ + fees: { + id: { parents: 0, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), + }, + weight_limit: XcmV3WeightLimit.Unlimited(), + }), + ], + }), + ]), + max_weight: { ref_time: 55791635000n, proof_size: 364593n }, + }, + ); + + const r = await WndToAH.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); +}) From 799d65cf88a5bde2da905b34f76958ad417e333c Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 25 Nov 2024 14:11:52 +0100 Subject: [PATCH 04/25] implemented teleport in xcm v5 manner --- .../chopsticks/tests/v5-tests/index.ts | 78 ++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 17111e698fc0..114f9b9c4c6b 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -125,7 +125,7 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { }); test("Initiate Teleport XCM v4", async () => { - const WndToAH = AHApi.tx.PolkadotXcm.execute({ + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ message: Enum("V4", [ XcmV4Instruction.WithdrawAsset([{ id: { parents: 1, interior: XcmV3Junctions.Here() }, @@ -155,6 +155,80 @@ test("Initiate Teleport XCM v4", async () => { }, ); - const r = await WndToAH.signAndSubmit(aliceSigner); + const r = await ahToWnd.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); +}) + +test("Initiate Teleport XCM v5", async () => { + + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ + message: Enum('V5', [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, + + ]), + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), + } + }), + Enum('InitiateTransfer', { + destination: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + // optional field. an example of usage: + // remote_fees: Enum('Teleport', { + // type: 'Wild', + // value: { + // type: 'All', + // value: undefined, + // }, + // }), + preserve_origin: false, + assets: [Enum('Teleport', { + type: 'Wild', + value: { + type: 'All', + value: undefined, + }, + })], + remote_xcm: [ + Enum('PayFees', { + asset: { + id: { + parents: 0, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + } + }), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), + }, + }), + ], + }), + ]), + max_weight: { ref_time: 343_504_280_000n, proof_size: 1_670_016n }, + }, + ); + const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }) From 5e677de972cd2888c0cd46594e9dded3427b083e Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 25 Nov 2024 15:06:53 +0100 Subject: [PATCH 05/25] added message weighing before execution for XCM v5 --- .../chopsticks/tests/v5-tests/index.ts | 117 +++++++++--------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 114f9b9c4c6b..628432d1f5b4 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -160,73 +160,76 @@ test("Initiate Teleport XCM v4", async () => { }) test("Initiate Teleport XCM v5", async () => { + const msg = Enum('V5', [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: Enum('V5', [ - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - - ]), + ]), + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), + } + }), + Enum('InitiateTransfer', { + destination: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + // optional field. an example of usage: + // remote_fees: Enum('Teleport', { + // type: 'Wild', + // value: { + // type: 'All', + // value: undefined, + // }, + // }), + preserve_origin: false, + assets: [Enum('Teleport', { + type: 'Wild', + value: { + type: 'All', + value: undefined, + }, + })], + remote_xcm: [ Enum('PayFees', { asset: { id: { - parents: 1, + parents: 0, interior: XcmV3Junctions.Here(), }, - fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), } }), - Enum('InitiateTransfer', { - destination: { - parents: 1, - interior: XcmV3Junctions.Here(), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), }, - // optional field. an example of usage: - // remote_fees: Enum('Teleport', { - // type: 'Wild', - // value: { - // type: 'All', - // value: undefined, - // }, - // }), - preserve_origin: false, - assets: [Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - })], - remote_xcm: [ - Enum('PayFees', { - asset: { - id: { - parents: 0, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } - }), - XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }]), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), - }, - }), - ], }), - ]), - max_weight: { ref_time: 343_504_280_000n, proof_size: 1_670_016n }, + ], + }), + ]); + + const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); + + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, }, ); const r = await ahToWnd.signAndSubmit(aliceSigner); From 443fc85fc0d59903a64657d2866956613f66a34e Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 25 Nov 2024 15:41:32 +0100 Subject: [PATCH 06/25] added message weighing before execution for XCM v4 as well --- .../chopsticks/tests/v5-tests/index.ts | 154 +++++++++--------- 1 file changed, 81 insertions(+), 73 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 628432d1f5b4..0762659b5ee4 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -58,62 +58,68 @@ async function getFreeBalance(api, accountKey) { test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { const bobBalanceBefore = await getFreeBalance(AHApi, BOB_KEY); + const alice_msg = Enum("V5", [ + Enum("SetAssetClaimer", { + location: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })) + }, + }), + XcmV4Instruction.WithdrawAsset([{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }]), + XcmV4Instruction.ClearOrigin(), + ]); + const alice_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(alice_msg); + // Transaction 1: Alice sets asset claimer to Bob and sends a trap transaction const trapTx = AHApi.tx.PolkadotXcm.execute({ - message: Enum("V5", [ - Enum("SetAssetClaimer", { - location: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })) - }, - }), - XcmV4Instruction.WithdrawAsset([{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }]), - XcmV4Instruction.ClearOrigin(), - ]), - max_weight: { ref_time: 100_000_000_000n, proof_size: 300_000n }, + message: alice_msg, + max_weight: { ref_time: alice_weight.value.ref_time, proof_size: alice_weight.value.proof_size }, }); const trapResult = await trapTx.signAndSubmit(aliceSigner); expect(trapResult.ok).toBeTruthy(); + const bob_msg = Enum("V4", [ + XcmV4Instruction.ClaimAsset({ + assets: [{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }], + ticket: { parents: 0, interior: XcmV3Junctions.Here() }, + }), + XcmV4Instruction.BuyExecution({ + fees: { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000n), + }, + weight_limit: XcmV3WeightLimit.Unlimited(), + }), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 1, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })) + } + }), + ]); + const bob_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(bob_msg); + // Transaction 2: Bob claims trapped assets. const bobClaimTx = AHApi.tx.PolkadotXcm.execute({ - message: Enum("V4", [ - XcmV4Instruction.ClaimAsset({ - assets: [{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }], - ticket: { parents: 0, interior: XcmV3Junctions.Here() }, - }), - XcmV4Instruction.BuyExecution({ - fees: { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000n), - }, - weight_limit: XcmV3WeightLimit.Unlimited(), - }), - XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 1, interior: XcmV3Junctions.Here() }, - }]), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })) - } - }), - ]), - max_weight: { ref_time: 100_000_000_000n, proof_size: 300_000n }, + message: bob_msg, + max_weight: { ref_time: bob_weight.value.ref_time, proof_size: bob_weight.value.proof_size }, }); const claimResult = await bobClaimTx.signAndSubmit(bobSigner); @@ -125,33 +131,36 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { }); test("Initiate Teleport XCM v4", async () => { - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: Enum("V4", [ - XcmV4Instruction.WithdrawAsset([{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(7e12), - }]), - XcmV4Instruction.SetFeesMode({ - jit_withdraw: true, - }), - XcmV4Instruction.InitiateTeleport({ - assets: XcmV4AssetAssetFilter.Wild({type: "All", value: undefined}), - dest: { - parents: 1, - interior: XcmV3Junctions.Here(), + const msg = Enum("V4", [ + XcmV4Instruction.WithdrawAsset([{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(7e12), + }]), + XcmV4Instruction.SetFeesMode({ + jit_withdraw: true, + }), + XcmV4Instruction.InitiateTeleport({ + assets: XcmV4AssetAssetFilter.Wild({type: "All", value: undefined}), + dest: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + xcm: [ + XcmV4Instruction.BuyExecution({ + fees: { + id: { parents: 0, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), }, - xcm: [ - XcmV4Instruction.BuyExecution({ - fees: { - id: { parents: 0, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), - }, - weight_limit: XcmV3WeightLimit.Unlimited(), - }), - ], + weight_limit: XcmV3WeightLimit.Unlimited(), }), - ]), - max_weight: { ref_time: 55791635000n, proof_size: 364593n }, + ], + }), + ]); + const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); + + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, }, ); @@ -224,7 +233,6 @@ test("Initiate Teleport XCM v5", async () => { ], }), ]); - const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); const ahToWnd = AHApi.tx.PolkadotXcm.execute({ From 274debbaaf9924e38defd7dd1c4793548d53b555 Mon Sep 17 00:00:00 2001 From: ndk Date: Tue, 26 Nov 2024 16:15:43 +0100 Subject: [PATCH 07/25] WIP: query_xcm_weight_to_asset_fee estimates wrongly --- .../chopsticks/tests/v5-tests/index.ts | 79 ++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 0762659b5ee4..bd19a3817d20 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -169,6 +169,83 @@ test("Initiate Teleport XCM v4", async () => { }) test("Initiate Teleport XCM v5", async () => { + const xcm_origin_msg = Enum('V5', [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, + + ]), + + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + } + }), + Enum('InitiateTransfer', { + destination: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + // optional field. an example of usage: + // remote_fees: Enum('Teleport', { + // type: 'Wild', + // value: { + // type: 'All', + // value: undefined, + // }, + // }), + preserve_origin: false, + assets: [Enum('Teleport', { + type: 'Wild', + value: { + type: 'All', + value: undefined, + }, + })], + remote_xcm: [ + Enum('PayFees', { + asset: { + id: { + parents: 0, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + } + }), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), + }, + }), + ], + }), + ]); + + const xcm_origin_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(xcm_origin_msg); + const weight_to_asset_fee = await AHApi.apis.XcmPaymentApi.query_weight_to_asset_fee( + { ref_time: xcm_origin_weight.value.ref_time, proof_size: xcm_origin_weight.value.proof_size }, + Enum('V5', { + parents: 1, + interior: XcmV3Junctions.Here(), + }), + ); + + + const msg = Enum('V5', [ XcmV4Instruction.WithdrawAsset([ { @@ -183,7 +260,7 @@ test("Initiate Teleport XCM v5", async () => { parents: 1, interior: XcmV3Junctions.Here(), }, - fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), + fun: XcmV3MultiassetFungibility.Fungible(weight_to_asset_fee.value), } }), Enum('InitiateTransfer', { From 6d11b524309067eb91b14ce183166a8e2fef383c Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 27 Nov 2024 14:34:57 +0100 Subject: [PATCH 08/25] added initiate teleport with remote fees program --- .../chopsticks/tests/v5-tests/index.ts | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index bd19a3817d20..aa64269786de 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -320,3 +320,70 @@ test("Initiate Teleport XCM v5", async () => { const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }) + +test("Initiate Teleport with remote fees", async () => { + const msg = Enum('V5', [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, + + ]), + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), + } + }), + Enum('InitiateTransfer', { + destination: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + // optional field. an example of usage: + remote_fees: Enum('Teleport', { + type: 'Wild', + value: { + type: 'All', + value: undefined, + }, + }), + preserve_origin: false, + assets: [Enum('Teleport', { + type: 'Wild', + value: { + type: 'All', + value: undefined, + }, + })], + remote_xcm: [ + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), + }, + }), + ], + }), + ]); + const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); + + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }, + ); + const r = await ahToWnd.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); +}) From 2ddb163a1dc7e5247463dc49ed7e01b936b53ab7 Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 27 Nov 2024 14:53:00 +0100 Subject: [PATCH 09/25] used wildcard instead of concrete fungible values in DepositAsset instruction --- .../integration-tests/chopsticks/tests/v5-tests/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index aa64269786de..933e7d453e77 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -362,10 +362,10 @@ test("Initiate Teleport with remote fees", async () => { })], remote_xcm: [ XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }]), + assets: XcmV3MultiassetMultiAssetFilter.Wild({ + type: 'All', + value: undefined, + }), beneficiary: { parents: 0, interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ From 7041b1ed7da88250acaa24d0c636d03ecb85cba4 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 28 Nov 2024 14:23:44 +0100 Subject: [PATCH 10/25] removed commented config --- .../chopsticks/configs/westend-asset-hub-override.yaml | 10 +++------- .../configs/westend-bridge-hub-override.yaml | 4 ---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml index 4b448f0864d4..651f7b7e8332 100644 --- a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml @@ -1,9 +1,9 @@ -endpoint: wss://asset-hub-polkadot-rpc.dwellir.com +endpoint: wss://asset-hub-westend-rpc.dwellir.com mock-signature-host: true -block: ${env.WESTEND_ASSET_HUB_BLOCK_NUMBER} +#block: ${env.WESTEND_ASSET_HUB_BLOCK_NUMBER} db: ./db.sqlite runtime-log-level: 5 -wasm-override: wasms/asset_hub_westend_runtime.compact.compressed.wasm +#wasm-override: wasms/asset_hub_westend_runtime.compact.compressed.wasm import-storage: System: @@ -26,7 +26,3 @@ import-storage: - providers: 1 data: free: 1000000000000000 -# Assets: -# Account: -# - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] -# - [[1984, 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia], { balance: 1000000000 }] diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml index a71a3a8334a3..5b88fcccb134 100644 --- a/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml @@ -26,7 +26,3 @@ import-storage: - providers: 1 data: free: 1000000000000000 -# Assets: -# Account: -# - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] -# - [[1984, 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia], { balance: 1000000000 }] From b7cd89196df912569f9a07f713a82b4344bd5a03 Mon Sep 17 00:00:00 2001 From: Andrii Date: Mon, 16 Dec 2024 18:07:16 +0100 Subject: [PATCH 11/25] fixed bridge hub endpoint from polkadot to westend (#6914) Fixed Bridge Hub Westend endpoint --- .../chopsticks/configs/westend-bridge-hub-override.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml index 5b88fcccb134..1b2d885e28f2 100644 --- a/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-bridge-hub-override.yaml @@ -1,4 +1,4 @@ -endpoint: wss://bridge-hub-polkadot-rpc.dwellir.com +endpoint: wss://bridge-hub-westend-rpc.dwellir.com mock-signature-host: true block: ${env.WESTEND_BRIDGE_HUB_BLOCK_NUMBER} db: ./db.sqlite From 16b02fd8cdcedd4253463a86af74caee54e6b408 Mon Sep 17 00:00:00 2001 From: Andrii Date: Tue, 17 Dec 2024 18:12:24 +0100 Subject: [PATCH 12/25] Added Asset issuance config (#6927) Asset issuance config for test-tether. On Westend total issuance of this token is equal to 0 (when in doubt check https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fasset-hub-westend-rpc.dwellir.com#/assets for Asset Hub). Even if you set yourself balance of 1 billion test-tether tokens, the execution will fail during withdrawal thus issuance config is needed. --- .../chopsticks/configs/westend-asset-hub-override.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml index 651f7b7e8332..598596137488 100644 --- a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml @@ -26,3 +26,7 @@ import-storage: - providers: 1 data: free: 1000000000000000 + Assets: + Account: + - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] + Asset: [[[1984], { supply: 1000000000 }]] From 83b75095acac33736d32d974ef65bc78ac04e4a7 Mon Sep 17 00:00:00 2001 From: Andrii Date: Wed, 18 Dec 2024 20:31:42 +0100 Subject: [PATCH 13/25] Created sovereign account of penpal on asset hub and topped it up (#6962) Restructured config, added initial USDT deposit to penpal's SA. Preparation work for Reserve Asset Transfer --- .../configs/westend-asset-hub-override.yaml | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml index 598596137488..3b45a7ab3160 100644 --- a/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-asset-hub-override.yaml @@ -3,30 +3,26 @@ mock-signature-host: true #block: ${env.WESTEND_ASSET_HUB_BLOCK_NUMBER} db: ./db.sqlite runtime-log-level: 5 -#wasm-override: wasms/asset_hub_westend_runtime.compact.compressed.wasm +wasm-override: wasms/asset_hub_westend_runtime.compact.compressed.wasm import-storage: + PolkadotXcm: + SafeXcmVersion: 5 System: Account: - - - - - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice - - providers: 1 - data: - free: 1000000000000000 - - - - - - 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia - - providers: 1 - data: - free: 1000000000000000 - - - - - - 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty # Bob - - providers: 1 - data: - free: 1000000000000000 + [ + [[5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { providers: 1, data: { free: 1000000000000000 } }], # Alice + [[5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia], { providers: 1, data: { free: 1000000000000000 } }], + [[5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty], { providers: 1, data: { free: 1000000000000000 } }] # Bob + ] Assets: Account: - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] - Asset: [[[1984], { supply: 1000000000 }]] + - [[1984, 5Eg2fntSSE9VPsfxjgvpoZCoPo2uquZaYwmNDDV91bxUxEt7], { balance: 1000000000 }] # SA of Penpal chain + + Asset: + [ + [[1984], { supply: 4000000000 }], + ] + + From bd753b2bbcdbffe75f619f14fcd51f87fae63c81 Mon Sep 17 00:00:00 2001 From: Andrii Date: Tue, 14 Jan 2025 12:30:51 +0100 Subject: [PATCH 14/25] Added reserve asset transfer scenario (#7149) Added test scenario for local reserve asset transfer. Documented my work here - https://hackmd.io/@RFUCsRRCSzKkumaXVxcCdg/B1pIuCGrJx --- .../configs/westend-penpal-override.yaml | 34 ++++++ .../chopsticks/tests/v5-tests/index.ts | 105 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 cumulus/parachains/integration-tests/chopsticks/configs/westend-penpal-override.yaml diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-penpal-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-penpal-override.yaml new file mode 100644 index 000000000000..5a9247700d00 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-penpal-override.yaml @@ -0,0 +1,34 @@ +endpoint: wss://westend-penpal-rpc.polkadot.io +mock-signature-host: true +db: ./db.sqlite +runtime-log-level: 5 +wasm-override: wasms/penpal_runtime.compact.compressed.wasm + +import-storage: + PolkadotXcm: + SafeXcmVersion: 5 + System: + Account: + - + - + - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice + - providers: 1 + data: + free: 1000000000000000 + - + - + - 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia + - providers: 1 + data: + free: 1000000000000000 + - + - + - 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty # Bob + - providers: 1 + data: + free: 1000000000000000 + Assets: + Account: + - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }] + - [[1984, 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty], { balance: 1000000000 }] # Bob + Asset: [[[1984], { supply: 1000000000 }]] diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 933e7d453e77..a5d43be8dc61 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -387,3 +387,108 @@ test("Initiate Teleport with remote fees", async () => { const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }) + +test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", async () => { + + const msg = Enum('V5', [ + XcmV4Instruction.WithdrawAsset([ + { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, + ]), + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + } + }), + XcmV4Instruction.TransferReserveAsset({ + assets: [ + { + id: { + parents: 0, + interior: XcmV3Junctions.X2([ + XcmV3Junction.PalletInstance(50), + XcmV3Junction.GeneralIndex(1984n)]), + }, + fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), + }, + { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), + }, + ], + dest: { + parents: 1, + interior: XcmV3Junctions.X1( + XcmV3Junction.Parachain(2042), + ), + }, + xcm: [ + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000n), + } + }), + XcmV4Instruction.DepositAsset({ + // some WND might get trapped bc of extra fungibles in PayFees above ^ + assets: XcmV3MultiassetMultiAssetFilter.Wild({ + type: 'All', + value: undefined, + }), + + // ===================== GRANULAR VERSIONS ===================== + // assets: XcmV4AssetAssetFilter.Definite([{ + // id: { + // parents: 1, + // interior: XcmV3Junctions.Here(), + // }, + // fun: XcmV3MultiassetFungibility.Fungible(3_995_000_000_000n), + // }]), + // + // assets: XcmV4AssetAssetFilter.Definite([{ + // id: { + // parents: 1, + // interior: XcmV3Junctions.X3([ + // XcmV3Junction.Parachain(1000), + // XcmV3Junction.PalletInstance(50), + // XcmV3Junction.GeneralIndex(1984n)]), + // }, + // fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), + // }]), + + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), + })), + }, + }), + ], + }), + ]); + + + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ + message: msg, + max_weight: { ref_time: 81834380000n, proof_size: 823193n }, + }, + ); + const r = await ahToWnd.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); +}) From b86c14cb395c718c40a143f7e8c97e6375f8d48e Mon Sep 17 00:00:00 2001 From: Andrii Date: Wed, 15 Jan 2025 11:46:03 +0100 Subject: [PATCH 15/25] Initiate reserve withdraw test scenario (#7175) Added initiate reserve withdraw test scenario. Added penpal client to test set-up and updated Readme. In order to verify USDT transfer from Asset Hub to Penpal (ReserveAssetTransfer): - go to Penpal's chain state (https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A8001#/chainstate) - select foreignAssets pallet and then select asset map - within asset map specify relative path to USDT on Asset Hub (i.e. parents: 1, Parachain(1000), PalletInstance(50), GeneralIndex(1984) and hit "+" button - within the response make sure that there is one account (`accounts: 1`) holding this foreign asset In order to verify USDT transfer from Penpal to AssetHub (InitiateReserveWithdraw): - go to Asset Hub's chain state (https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A8000#/chainstate) - select asset pallet and account map - below select Bob's account from the list (we use Bob for this test scenario but you can also check if Alice's balance was decreased) - and set id (u32) to 1984 (or USDT) - then hit "+" button and make sure that Bob's balance is correct --- .../chopsticks/tests/v5-tests/README.md | 3 +- .../chopsticks/tests/v5-tests/index.ts | 87 ++++++++++++++++++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md index 7ebf5f27e568..428eaae83a7c 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md @@ -5,7 +5,8 @@ To install dependencies: ```bash bun add polkadot-api # now you need to switch to another terminal window where you executed bunx command, make sure that chains are running and copy Asset Hub's port in the command below (usually the port is 8001). -bun papi add wnd_ah -w ws://localhost:8001 +bun papi add wnd_ah -w ws://localhost:8000 +bun papi add wnd_penpal -w ws://localhost:8001 bun add @polkadot-labs/hdkd ``` diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index a5d43be8dc61..66cc0cc1d1bd 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -1,6 +1,7 @@ import { test, expect } from "bun:test"; import { wnd_ah, + wnd_penpal, XcmV3Junctions, XcmV3Junction, XcmV3MultiassetFungibility, @@ -25,9 +26,11 @@ const WESTEND_NETWORK = Uint8Array.from([225, 67, 242, 56, 3, 172, 80, 232, 246, const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; -// Create and initialize client -const client = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"))); -const AHApi = client.getTypedApi(wnd_ah); +// Create and initialize clients +const ahClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"))); +const AHApi = ahClient.getTypedApi(wnd_ah); +const penaplClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8001"))); +const PenpalApi = penaplClient.getTypedApi(wnd_penpal); // Initialize HDKD key pairs and signers const entropy = mnemonicToEntropy(DEV_PHRASE); @@ -492,3 +495,81 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }) + +// this test scenario works together with the previous one. +// previous test serves as a set-up for this one. +test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { + const msg = Enum('V5', [ + XcmV4Instruction.WithdrawAsset([ + { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(3_995_000_000_000n), + }, + { + id: { + parents: 1, + interior: XcmV3Junctions.X3([ + XcmV3Junction.Parachain(1000), + XcmV3Junction.PalletInstance(50), + XcmV3Junction.GeneralIndex(1984n)]), + }, + fun: XcmV3MultiassetFungibility.Fungible(70_000_000n), + }, + ]), + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + } + }), + XcmV4Instruction.InitiateReserveWithdraw({ + assets: XcmV4AssetAssetFilter.Wild({ + type: 'All', + value: undefined, + }), + reserve: { + parents: 1, + interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1000)), + }, + xcm: [ + Enum('PayFees', { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + } + }), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Wild({ + type: 'All', + value: undefined, + }), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), + }, + }), + ], + }), + ]); + + + const penpalToAH = PenpalApi.tx.PolkadotXcm.execute({ + message: msg, + max_weight: { ref_time: 81834380000n, proof_size: 823193n }, + }, + ); + const r = await penpalToAH.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); +}) From d94417f365a35897ce91a5e3a5567f0294a41c97 Mon Sep 17 00:00:00 2001 From: Tiago Bandeira Date: Wed, 15 Jan 2025 12:23:03 +0000 Subject: [PATCH 16/25] Add more scenarios for Teleport and Teleport+Transact --- .../configs/westend-people-override.yaml | 24 + .../chopsticks/tests/v5-tests/index.ts | 562 ++++++++++++------ 2 files changed, 416 insertions(+), 170 deletions(-) create mode 100644 cumulus/parachains/integration-tests/chopsticks/configs/westend-people-override.yaml diff --git a/cumulus/parachains/integration-tests/chopsticks/configs/westend-people-override.yaml b/cumulus/parachains/integration-tests/chopsticks/configs/westend-people-override.yaml new file mode 100644 index 000000000000..bd3d86ca3210 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/configs/westend-people-override.yaml @@ -0,0 +1,24 @@ +endpoint: wss://people-westend-rpc.dwellir.com +mock-signature-host: true +# block: ${env.WESTEND_PEOPLE_BLOCK_NUMBER} +db: ./db.sqlite +runtime-log-level: 5 +wasm-override: wasms/people_westend_runtime.compact.compressed.wasm + +import-storage: + PolkadotXcm: + SafeXcmVersion: 5 + System: + Account: + - - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice + - providers: 1 + data: + free: 1000000000000000 + - - - 5Eg2fntQqFi3EvFWAf71G66Ecjjah26bmFzoANAeHFgj9Lia + - providers: 1 + data: + free: 1000000000000000 + - - - 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty # Bob + - providers: 1 + data: + free: 1000000000000000 diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 66cc0cc1d1bd..48361b7541ea 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -8,20 +8,20 @@ import { XcmV4Instruction, XcmV3WeightLimit, XcmV3MultiassetMultiAssetFilter, - XcmV4AssetAssetFilter + XcmV4AssetAssetFilter, + XcmV2OriginKind, } from "@polkadot-api/descriptors"; import { Binary, Enum, createClient } from "polkadot-api"; import { getWsProvider } from "polkadot-api/ws-provider/web"; import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"; import { sr25519CreateDerive } from "@polkadot-labs/hdkd"; -import { - DEV_PHRASE, - entropyToMiniSecret, - mnemonicToEntropy, -} from "@polkadot-labs/hdkd-helpers"; +import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from "@polkadot-labs/hdkd-helpers"; import { getPolkadotSigner } from "polkadot-api/signer"; -const WESTEND_NETWORK = Uint8Array.from([225, 67, 242, 56, 3, 172, 80, 232, 246, 248, 230, 38, 149, 209, 206, 158, 78, 29, 104, 170, 54, 193, 205, 44, 253, 21, 52, 2, 19, 243, 66, 62]); +const WESTEND_NETWORK = Uint8Array.from([ + 225, 67, 242, 56, 3, 172, 80, 232, 246, 248, 230, 38, 149, 209, 206, 158, 78, 29, 104, 170, 54, + 193, 205, 44, 253, 21, 52, 2, 19, 243, 66, 62, +]); // TODO: find a way to extract keys below from yaml config. const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; @@ -40,17 +40,8 @@ const derive = sr25519CreateDerive(miniSecret); const hdkdKeyPairAlice = derive("//Alice"); const hdkdKeyPairBob = derive("//Bob"); -const aliceSigner = getPolkadotSigner( - hdkdKeyPairAlice.publicKey, - "Sr25519", - hdkdKeyPairAlice.sign, -); - -const bobSigner = getPolkadotSigner( - hdkdKeyPairBob.publicKey, - "Sr25519", - hdkdKeyPairBob.sign, -); +const aliceSigner = getPolkadotSigner(hdkdKeyPairAlice.publicKey, "Sr25519", hdkdKeyPairAlice.sign); +const bobSigner = getPolkadotSigner(hdkdKeyPairBob.publicKey, "Sr25519", hdkdKeyPairBob.sign); // Utility function for balance fetching async function getFreeBalance(api, accountKey) { @@ -65,16 +56,20 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { Enum("SetAssetClaimer", { location: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })) + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), }, }), - XcmV4Instruction.WithdrawAsset([{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }]), + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }, + ]), XcmV4Instruction.ClearOrigin(), ]); const alice_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(alice_msg); @@ -82,7 +77,10 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { // Transaction 1: Alice sets asset claimer to Bob and sends a trap transaction const trapTx = AHApi.tx.PolkadotXcm.execute({ message: alice_msg, - max_weight: { ref_time: alice_weight.value.ref_time, proof_size: alice_weight.value.proof_size }, + max_weight: { + ref_time: alice_weight.value.ref_time, + proof_size: alice_weight.value.proof_size, + }, }); const trapResult = await trapTx.signAndSubmit(aliceSigner); @@ -90,10 +88,12 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { const bob_msg = Enum("V4", [ XcmV4Instruction.ClaimAsset({ - assets: [{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }], + assets: [ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }, + ], ticket: { parents: 0, interior: XcmV3Junctions.Here() }, }), XcmV4Instruction.BuyExecution({ @@ -104,17 +104,21 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { weight_limit: XcmV3WeightLimit.Unlimited(), }), XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 1, interior: XcmV3Junctions.Here() }, - }]), + assets: XcmV3MultiassetMultiAssetFilter.Definite([ + { + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 1, interior: XcmV3Junctions.Here() }, + }, + ]), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })) - } + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), + }, }), ]); const bob_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(bob_msg); @@ -122,28 +126,32 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { // Transaction 2: Bob claims trapped assets. const bobClaimTx = AHApi.tx.PolkadotXcm.execute({ message: bob_msg, - max_weight: { ref_time: bob_weight.value.ref_time, proof_size: bob_weight.value.proof_size }, + max_weight: { + ref_time: bob_weight.value.ref_time, + proof_size: bob_weight.value.proof_size, + }, }); const claimResult = await bobClaimTx.signAndSubmit(bobSigner); expect(claimResult.ok).toBeTruthy(); - const bobBalanceAfter = await getFreeBalance(AHApi, BOB_KEY); expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); }); test("Initiate Teleport XCM v4", async () => { const msg = Enum("V4", [ - XcmV4Instruction.WithdrawAsset([{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(7e12), - }]), + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(7e12), + }, + ]), XcmV4Instruction.SetFeesMode({ jit_withdraw: true, }), XcmV4Instruction.InitiateTeleport({ - assets: XcmV4AssetAssetFilter.Wild({type: "All", value: undefined}), + assets: XcmV4AssetAssetFilter.Wild({ type: "All", value: undefined }), dest: { parents: 1, interior: XcmV3Junctions.Here(), @@ -162,35 +170,33 @@ test("Initiate Teleport XCM v4", async () => { const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }, - ); + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); -}) +}); test("Initiate Teleport XCM v5", async () => { - const xcm_origin_msg = Enum('V5', [ + const xcm_origin_msg = Enum("V5", [ XcmV4Instruction.WithdrawAsset([ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, - ]), - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } + }, }), - Enum('InitiateTransfer', { + Enum("InitiateTransfer", { destination: { parents: 1, interior: XcmV3Junctions.Here(), @@ -204,34 +210,40 @@ test("Initiate Teleport XCM v5", async () => { // }, // }), preserve_origin: false, - assets: [Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - })], + assets: [ + Enum("Teleport", { + type: "Wild", + value: { + type: "All", + value: undefined, + }, + }), + ], remote_xcm: [ - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 0, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } + }, }), XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }]), + assets: XcmV3MultiassetMultiAssetFilter.Definite([ + { + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }, + ]), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), }, }), ], @@ -240,33 +252,33 @@ test("Initiate Teleport XCM v5", async () => { const xcm_origin_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(xcm_origin_msg); const weight_to_asset_fee = await AHApi.apis.XcmPaymentApi.query_weight_to_asset_fee( - { ref_time: xcm_origin_weight.value.ref_time, proof_size: xcm_origin_weight.value.proof_size }, - Enum('V5', { + { + ref_time: xcm_origin_weight.value.ref_time, + proof_size: xcm_origin_weight.value.proof_size, + }, + Enum("V5", { parents: 1, interior: XcmV3Junctions.Here(), - }), + }) ); - - - const msg = Enum('V5', [ + const msg = Enum("V5", [ XcmV4Instruction.WithdrawAsset([ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, - ]), - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(weight_to_asset_fee.value), - } + }, }), - Enum('InitiateTransfer', { + Enum("InitiateTransfer", { destination: { parents: 1, interior: XcmV3Junctions.Here(), @@ -280,34 +292,40 @@ test("Initiate Teleport XCM v5", async () => { // }, // }), preserve_origin: false, - assets: [Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - })], + assets: [ + Enum("Teleport", { + type: "Wild", + value: { + type: "All", + value: undefined, + }, + }), + ], remote_xcm: [ - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 0, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } + }, }), XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }]), + assets: XcmV3MultiassetMultiAssetFilter.Definite([ + { + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }, + ]), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), }, }), ], @@ -316,65 +334,67 @@ test("Initiate Teleport XCM v5", async () => { const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }, - ); + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); -}) +}); test("Initiate Teleport with remote fees", async () => { - const msg = Enum('V5', [ + const msg = Enum("V5", [ XcmV4Instruction.WithdrawAsset([ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, - ]), - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), - } + }, }), - Enum('InitiateTransfer', { + Enum("InitiateTransfer", { destination: { parents: 1, interior: XcmV3Junctions.Here(), }, // optional field. an example of usage: - remote_fees: Enum('Teleport', { - type: 'Wild', + remote_fees: Enum("Teleport", { + type: "Wild", value: { - type: 'All', + type: "All", value: undefined, }, }), preserve_origin: false, - assets: [Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - })], + assets: [ + Enum("Teleport", { + type: "Wild", + value: { + type: "All", + value: undefined, + }, + }), + ], remote_xcm: [ XcmV4Instruction.DepositAsset({ assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: 'All', + type: "All", value: undefined, }), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), }, }), ], @@ -383,17 +403,15 @@ test("Initiate Teleport with remote fees", async () => { const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }, - ); + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); -}) +}); test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", async () => { - - const msg = Enum('V5', [ + const msg = Enum("V5", [ XcmV4Instruction.WithdrawAsset([ { id: { @@ -403,14 +421,14 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, ]), - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } + }, }), XcmV4Instruction.TransferReserveAsset({ assets: [ @@ -419,7 +437,8 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a parents: 0, interior: XcmV3Junctions.X2([ XcmV3Junction.PalletInstance(50), - XcmV3Junction.GeneralIndex(1984n)]), + XcmV3Junction.GeneralIndex(1984n), + ]), }, fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), }, @@ -433,24 +452,22 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a ], dest: { parents: 1, - interior: XcmV3Junctions.X1( - XcmV3Junction.Parachain(2042), - ), + interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2042)), }, xcm: [ - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000n), - } + }, }), XcmV4Instruction.DepositAsset({ // some WND might get trapped bc of extra fungibles in PayFees above ^ assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: 'All', + type: "All", value: undefined, }), @@ -476,30 +493,30 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a beneficiary: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), - })), + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), + }) + ), }, }), ], }), ]); - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: 81834380000n, proof_size: 823193n }, - }, - ); + message: msg, + max_weight: { ref_time: 81834380000n, proof_size: 823193n }, + }); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); -}) +}); // this test scenario works together with the previous one. // previous test serves as a set-up for this one. test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { - const msg = Enum('V5', [ + const msg = Enum("V5", [ XcmV4Instruction.WithdrawAsset([ { id: { @@ -514,23 +531,24 @@ test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { interior: XcmV3Junctions.X3([ XcmV3Junction.Parachain(1000), XcmV3Junction.PalletInstance(50), - XcmV3Junction.GeneralIndex(1984n)]), + XcmV3Junction.GeneralIndex(1984n), + ]), }, fun: XcmV3MultiassetFungibility.Fungible(70_000_000n), }, ]), - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } + }, }), XcmV4Instruction.InitiateReserveWithdraw({ assets: XcmV4AssetAssetFilter.Wild({ - type: 'All', + type: "All", value: undefined, }), reserve: { @@ -538,38 +556,242 @@ test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1000)), }, xcm: [ - Enum('PayFees', { + Enum("PayFees", { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - } + }, }), XcmV4Instruction.DepositAsset({ assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: 'All', + type: "All", value: undefined, }), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), }, }), ], }), ]); - const penpalToAH = PenpalApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: 81834380000n, proof_size: 823193n }, - }, - ); + message: msg, + max_weight: { ref_time: 81834380000n, proof_size: 823193n }, + }); const r = await penpalToAH.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); -}) +}); + +test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { + const remarkWithEventCalldata = await PenpalApi.tx.System.remark_with_event({ + remark: Binary.fromText("Hello, World!"), + }).getEncodedData(); + + PenpalApi.event.System.Remarked.watch().forEach((e) => + console.log( + `\nBlock: ${e.meta.block.number}\nSender: ${ + e.payload.sender + }\nHash: ${e.payload.hash.asHex()}\n` + ) + ); + + const msg = Enum("V5", [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, + ]), + Enum("PayFees", { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), + }, + }), + Enum("InitiateTransfer", { + destination: { + parents: 1, + interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2042)), + }, + remote_fees: { + type: "Teleport", + value: { + type: "Wild", + value: { + type: "All", + value: undefined, + }, + }, + }, + preserve_origin: true, + assets: [], + remote_xcm: [ + { + type: "Transact", + value: { + origin_kind: XcmV2OriginKind.SovereignAccount(), + call: remarkWithEventCalldata, + }, + }, + ], + }), + ]); + + const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); + const ahToWnd = AHApi.tx.PolkadotXcm.execute({ + msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }); + const r = await ahToWnd.signAndSubmit(aliceSigner); + expect(r.ok).toBeTruthy(); +}); + +test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTeleport", async () => { + const message = Enum("V5", [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), + }, + ]), + Enum("PayFees", { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), + }, + }), + XcmV4Instruction.InitiateTeleport({ + assets: XcmV4AssetAssetFilter.Wild({ type: "All", value: undefined }), + dest: { + parents: 1, + interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), + }, + xcm: [ + XcmV4Instruction.BuyExecution({ + fees: { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), + }, + weight_limit: XcmV3WeightLimit.Unlimited(), + }), + XcmV4Instruction.DepositAsset({ + assets: XcmV4AssetAssetFilter.Wild({ type: "All", value: undefined }), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), + }) + ), + }, + }), + ], + }), + ]); + const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(message); + + const ahToPpl = AHApi.tx.PolkadotXcm.execute({ + message, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }); + const r = await ahToPpl.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); +}); + +test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTransfer", async () => { + const msg = Enum("V5", [ + XcmV4Instruction.WithdrawAsset([ + { + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(10_000_000_000_000n), + }, + ]), + Enum("PayFees", { + asset: { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(665_000_000_000n), + }, + }), + Enum("InitiateTransfer", { + destination: { + parents: 1, + interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), + }, + remote_fees: { + type: "Teleport", + value: { + type: "Definite", + value: [ + { + id: { + parents: 1, + interior: XcmV3Junctions.Here(), + }, + fun: XcmV3MultiassetFungibility.Fungible(365_000_000_000n), + }, + ], + }, + }, + preserve_origin: true, + assets: [ + Enum("Teleport", { + type: "Wild", + value: { + type: "All", + value: undefined, + }, + }), + ], + remote_xcm: [ + XcmV4Instruction.DepositAsset({ + assets: XcmV4AssetAssetFilter.Wild({ + type: "All", + value: undefined, + }), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), + }) + ), + }, + }), + ], + }), + ]); + + const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); + const ahToPpl = AHApi.tx.PolkadotXcm.execute({ + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }); + + const r = await ahToPpl.signAndSubmit(aliceSigner); + expect(r).toBeTruthy(); + + expect(await getFreeBalance(AHApi, ALICE_KEY)).toBeLessThan( + 1_000_000_000_000_000n - 10_000_000_000_000n + ); +}); From c169a6e916502a6be90f22769a28957d03e739be Mon Sep 17 00:00:00 2001 From: Andrii Date: Fri, 24 Jan 2025 10:14:11 +0100 Subject: [PATCH 17/25] Unified XCM v4 and v5 message creation (#7312) 1. Discovered broken Set Asset Claimer. Replaced with nested SetHints + AssetClaimer 2. Unified XCM v4 and v5 message creation, improved message weights, small code refactors. 3. Removed `query_weight_to_asset_fee` call. It does not work as intended; will be restored in the future iterations. --- .../chopsticks/tests/v5-tests/index.ts | 351 +++++++----------- 1 file changed, 136 insertions(+), 215 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 48361b7541ea..e33891699042 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -1,6 +1,7 @@ import { test, expect } from "bun:test"; import { wnd_ah, + Wnd_ahCalls, wnd_penpal, XcmV3Junctions, XcmV3Junction, @@ -29,6 +30,7 @@ const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; // Create and initialize clients const ahClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"))); const AHApi = ahClient.getTypedApi(wnd_ah); + const penaplClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8001"))); const PenpalApi = penaplClient.getTypedApi(wnd_penpal); @@ -38,10 +40,18 @@ const miniSecret = entropyToMiniSecret(entropy); const derive = sr25519CreateDerive(miniSecret); const hdkdKeyPairAlice = derive("//Alice"); -const hdkdKeyPairBob = derive("//Bob"); +const aliceSigner = getPolkadotSigner( + hdkdKeyPairAlice.publicKey, + "Sr25519", + hdkdKeyPairAlice.sign, +); -const aliceSigner = getPolkadotSigner(hdkdKeyPairAlice.publicKey, "Sr25519", hdkdKeyPairAlice.sign); -const bobSigner = getPolkadotSigner(hdkdKeyPairBob.publicKey, "Sr25519", hdkdKeyPairBob.sign); +const hdkdKeyPairBob = derive("//Bob"); +const bobSigner = getPolkadotSigner( + hdkdKeyPairBob.publicKey, + "Sr25519", + hdkdKeyPairBob.sign, +); // Utility function for balance fetching async function getFreeBalance(api, accountKey) { @@ -52,25 +62,25 @@ async function getFreeBalance(api, accountKey) { test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { const bobBalanceBefore = await getFreeBalance(AHApi, BOB_KEY); - const alice_msg = Enum("V5", [ - Enum("SetAssetClaimer", { - location: { - parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - }) - ), - }, + const alice_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V5", [ + Enum('SetHints', { + hints: [ + Enum('AssetClaimer', { + location: { + parents: 0, + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })) + }, + }) + ], }), - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - ]), - XcmV4Instruction.ClearOrigin(), + Enum('WithdrawAsset', [{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + }]), + Enum('ClearOrigin'), ]); const alice_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(alice_msg); @@ -86,7 +96,7 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { const trapResult = await trapTx.signAndSubmit(aliceSigner); expect(trapResult.ok).toBeTruthy(); - const bob_msg = Enum("V4", [ + const bob_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V4", [ XcmV4Instruction.ClaimAsset({ assets: [ { @@ -139,14 +149,12 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); }); -test("Initiate Teleport XCM v4", async () => { - const msg = Enum("V4", [ - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(7e12), - }, - ]), +test("Initiate Teleport XCM v4 (AH -> RC)", async () => { + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V4", [ + XcmV4Instruction.WithdrawAsset([{ + id: { parents: 1, interior: XcmV3Junctions.Here() }, + fun: XcmV3MultiassetFungibility.Fungible(7_000_000_000_000n), + }]), XcmV4Instruction.SetFeesMode({ jit_withdraw: true, }), @@ -178,16 +186,15 @@ test("Initiate Teleport XCM v4", async () => { expect(r).toBeTruthy(); }); -test("Initiate Teleport XCM v5", async () => { - const xcm_origin_msg = Enum("V5", [ - XcmV4Instruction.WithdrawAsset([ +test("Initiate Teleport XCM v5 (AH -> RC)", async () => { + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ + Enum('WithdrawAsset', [ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, ]), - - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -196,7 +203,7 @@ test("Initiate Teleport XCM v5", async () => { fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), }, }), - Enum("InitiateTransfer", { + Enum('InitiateTransfer', { destination: { parents: 1, interior: XcmV3Junctions.Here(), @@ -211,16 +218,16 @@ test("Initiate Teleport XCM v5", async () => { // }), preserve_origin: false, assets: [ - Enum("Teleport", { - type: "Wild", + Enum('Teleport', { + type: 'Wild', value: { - type: "All", + type: 'All', value: undefined, }, }), ], remote_xcm: [ - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 0, @@ -229,95 +236,11 @@ test("Initiate Teleport XCM v5", async () => { fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), }, }), - XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([ - { - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }, - ]), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - }) - ), - }, - }), - ], - }), - ]); - - const xcm_origin_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(xcm_origin_msg); - const weight_to_asset_fee = await AHApi.apis.XcmPaymentApi.query_weight_to_asset_fee( - { - ref_time: xcm_origin_weight.value.ref_time, - proof_size: xcm_origin_weight.value.proof_size, - }, - Enum("V5", { - parents: 1, - interior: XcmV3Junctions.Here(), - }) - ); - - const msg = Enum("V5", [ - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - ]), - Enum("PayFees", { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(weight_to_asset_fee.value), - }, - }), - Enum("InitiateTransfer", { - destination: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - // optional field. an example of usage: - // remote_fees: Enum('Teleport', { - // type: 'Wild', - // value: { - // type: 'All', - // value: undefined, - // }, - // }), - preserve_origin: false, - assets: [ - Enum("Teleport", { - type: "Wild", - value: { - type: "All", - value: undefined, - }, - }), - ], - remote_xcm: [ - Enum("PayFees", { - asset: { - id: { - parents: 0, - interior: XcmV3Junctions.Here(), - }, + Enum('DepositAsset', { + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - }), - XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([ - { - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }, - ]), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }]), beneficiary: { parents: 0, interior: XcmV3Junctions.X1( @@ -341,60 +264,56 @@ test("Initiate Teleport XCM v5", async () => { expect(r).toBeTruthy(); }); -test("Initiate Teleport with remote fees", async () => { - const msg = Enum("V5", [ - XcmV4Instruction.WithdrawAsset([ +test("Initiate Teleport (AH -> RC) with remote fees", async () => { + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ + Enum('WithdrawAsset', [ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, ]), - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, interior: XcmV3Junctions.Here(), }, fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), - }, + } }), - Enum("InitiateTransfer", { + Enum('InitiateTransfer', { destination: { parents: 1, interior: XcmV3Junctions.Here(), }, // optional field. an example of usage: - remote_fees: Enum("Teleport", { - type: "Wild", + remote_fees: Enum('Teleport', { + type: 'Wild', value: { - type: "All", + type: 'All', value: undefined, }, }), preserve_origin: false, - assets: [ - Enum("Teleport", { - type: "Wild", - value: { - type: "All", - value: undefined, - }, - }), - ], + assets: [Enum('Teleport', { + type: 'Wild', + value: { + type: 'All', + value: undefined, + }, + })], remote_xcm: [ - XcmV4Instruction.DepositAsset({ + Enum('DepositAsset', { assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: "All", + type: 'All', value: undefined, }), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - }) - ), + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), }, }), ], @@ -403,16 +322,17 @@ test("Initiate Teleport with remote fees", async () => { const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }); + message: msg, + max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, + }, + ); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }); -test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", async () => { - const msg = Enum("V5", [ - XcmV4Instruction.WithdrawAsset([ +test("Reserve Asset Transfer (local) of USDT from Asset Hub `Alice` to Penpal `Alice`", async () => { + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ + Enum('WithdrawAsset', [ { id: { parents: 1, @@ -421,7 +341,7 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, ]), - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -430,15 +350,14 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), }, }), - XcmV4Instruction.TransferReserveAsset({ + Enum('TransferReserveAsset', { assets: [ { id: { parents: 0, interior: XcmV3Junctions.X2([ XcmV3Junction.PalletInstance(50), - XcmV3Junction.GeneralIndex(1984n), - ]), + XcmV3Junction.GeneralIndex(1984n)]), }, fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), }, @@ -452,10 +371,12 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a ], dest: { parents: 1, - interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2042)), + interior: XcmV3Junctions.X1( + XcmV3Junction.Parachain(2042), + ), }, xcm: [ - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -464,10 +385,10 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000n), }, }), - XcmV4Instruction.DepositAsset({ + Enum('DepositAsset', { // some WND might get trapped bc of extra fungibles in PayFees above ^ assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: "All", + type: 'All', value: undefined, }), @@ -490,15 +411,14 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a // }, // fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), // }]), + // ===================== END ===================== beneficiary: { parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), - }) - ), + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), + })), }, }), ], @@ -506,18 +426,19 @@ test("Local Reserve Asset Transfer of USDT from Asset Hub to Alice on Penpal", a ]); const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: 81834380000n, proof_size: 823193n }, - }); + message: msg, + max_weight: { ref_time: 100_000_000_000n, proof_size: 1_000_000n }, + }, + ); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }); // this test scenario works together with the previous one. // previous test serves as a set-up for this one. -test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { - const msg = Enum("V5", [ - XcmV4Instruction.WithdrawAsset([ +test("InitiateReserveWithdraw USDT from Penpal `Alice` to Asset Hub `Bob`", async () => { + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ + Enum('WithdrawAsset', [ { id: { parents: 1, @@ -537,7 +458,7 @@ test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { fun: XcmV3MultiassetFungibility.Fungible(70_000_000n), }, ]), - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -546,9 +467,9 @@ test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), }, }), - XcmV4Instruction.InitiateReserveWithdraw({ + Enum('InitiateReserveWithdraw' , { assets: XcmV4AssetAssetFilter.Wild({ - type: "All", + type: 'All', value: undefined, }), reserve: { @@ -556,7 +477,7 @@ test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1000)), }, xcm: [ - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -565,29 +486,29 @@ test("InitiateReserveWithdraw USDT from Penpal to Asset Hub Bob", async () => { fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), }, }), - XcmV4Instruction.DepositAsset({ + Enum('DepositAsset', { assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: "All", + type: 'All', value: undefined, }), beneficiary: { parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - }) - ), + interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + })), }, }), ], }), ]); + const penpalToAH = PenpalApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: 81834380000n, proof_size: 823193n }, - }); + message: msg, + max_weight: { ref_time: 100_000_000_000n, proof_size: 1_000_000n }, + }, + ); const r = await penpalToAH.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); }); @@ -605,14 +526,14 @@ test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { ) ); - const msg = Enum("V5", [ + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ XcmV4Instruction.WithdrawAsset([ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, ]), - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -621,17 +542,17 @@ test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), }, }), - Enum("InitiateTransfer", { + Enum('InitiateTransfer', { destination: { parents: 1, interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2042)), }, remote_fees: { - type: "Teleport", + type: 'Teleport', value: { - type: "Wild", + type: 'Wild', value: { - type: "All", + type: 'All', value: undefined, }, }, @@ -640,7 +561,7 @@ test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { assets: [], remote_xcm: [ { - type: "Transact", + type: 'Transact', value: { origin_kind: XcmV2OriginKind.SovereignAccount(), call: remarkWithEventCalldata, @@ -660,14 +581,14 @@ test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { }); test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTeleport", async () => { - const message = Enum("V5", [ + const message: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ XcmV4Instruction.WithdrawAsset([ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), }, ]), - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -677,7 +598,7 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini }, }), XcmV4Instruction.InitiateTeleport({ - assets: XcmV4AssetAssetFilter.Wild({ type: "All", value: undefined }), + assets: XcmV4AssetAssetFilter.Wild({ type: 'All', value: undefined }), dest: { parents: 1, interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), @@ -691,7 +612,7 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini weight_limit: XcmV3WeightLimit.Unlimited(), }), XcmV4Instruction.DepositAsset({ - assets: XcmV4AssetAssetFilter.Wild({ type: "All", value: undefined }), + assets: XcmV4AssetAssetFilter.Wild({ type: 'All', value: undefined }), beneficiary: { parents: 0, interior: XcmV3Junctions.X1( @@ -716,14 +637,14 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini }); test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTransfer", async () => { - const msg = Enum("V5", [ + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ XcmV4Instruction.WithdrawAsset([ { id: { parents: 1, interior: XcmV3Junctions.Here() }, fun: XcmV3MultiassetFungibility.Fungible(10_000_000_000_000n), }, ]), - Enum("PayFees", { + Enum('PayFees', { asset: { id: { parents: 1, @@ -732,15 +653,15 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini fun: XcmV3MultiassetFungibility.Fungible(665_000_000_000n), }, }), - Enum("InitiateTransfer", { + Enum('InitiateTransfer', { destination: { parents: 1, interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), }, remote_fees: { - type: "Teleport", + type: 'Teleport', value: { - type: "Definite", + type: 'Definite', value: [ { id: { @@ -754,10 +675,10 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini }, preserve_origin: true, assets: [ - Enum("Teleport", { - type: "Wild", + Enum('Teleport', { + type: 'Wild', value: { - type: "All", + type: 'All', value: undefined, }, }), @@ -765,7 +686,7 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini remote_xcm: [ XcmV4Instruction.DepositAsset({ assets: XcmV4AssetAssetFilter.Wild({ - type: "All", + type: 'All', value: undefined, }), beneficiary: { From 69dcbff2a996458dee8b4001ea1e6b2e4c8616af Mon Sep 17 00:00:00 2001 From: ndk Date: Fri, 24 Jan 2025 13:35:09 +0100 Subject: [PATCH 18/25] added relay chain API --- .../integration-tests/chopsticks/tests/v5-tests/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index e33891699042..b340dd0adf7e 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -3,6 +3,7 @@ import { wnd_ah, Wnd_ahCalls, wnd_penpal, + wnd_rc, XcmV3Junctions, XcmV3Junction, XcmV3MultiassetFungibility, @@ -34,6 +35,9 @@ const AHApi = ahClient.getTypedApi(wnd_ah); const penaplClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8001"))); const PenpalApi = penaplClient.getTypedApi(wnd_penpal); +const rcClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8002"))); +const rcApi = rcClient.getTypedApi(wnd_penpal); + // Initialize HDKD key pairs and signers const entropy = mnemonicToEntropy(DEV_PHRASE); const miniSecret = entropyToMiniSecret(entropy); @@ -262,6 +266,7 @@ test("Initiate Teleport XCM v5 (AH -> RC)", async () => { }); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); + // need to await for a new block }); test("Initiate Teleport (AH -> RC) with remote fees", async () => { From 5083a776484cb3abca82c0d94fac34af83d241ed Mon Sep 17 00:00:00 2001 From: ndk Date: Fri, 24 Jan 2025 18:29:02 +0100 Subject: [PATCH 19/25] 1. Added new block generation. 2. Improved first Teleport test to check balance after XCM execution --- .../chopsticks/tests/v5-tests/index.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index b340dd0adf7e..d3cbd205c941 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -20,6 +20,9 @@ import { sr25519CreateDerive } from "@polkadot-labs/hdkd"; import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from "@polkadot-labs/hdkd-helpers"; import { getPolkadotSigner } from "polkadot-api/signer"; +import { ApiPromise } from '@polkadot/api'; +import { WsProvider } from '@polkadot/rpc-provider'; + const WESTEND_NETWORK = Uint8Array.from([ 225, 67, 242, 56, 3, 172, 80, 232, 246, 248, 230, 38, 149, 209, 206, 158, 78, 29, 104, 170, 54, 193, 205, 44, 253, 21, 52, 2, 19, 243, 66, 62, @@ -28,14 +31,26 @@ const WESTEND_NETWORK = Uint8Array.from([ const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; +// Addresses +const AH_ADDRESS = 'ws://localhost:8000' +const PENPAL_ADDRESS = 'ws://localhost:8001' +const RC_ADDRESS = 'ws://localhost:8002' + +// init providers +const ah_provider = new WsProvider(AH_ADDRESS); +await ah_provider.isReady; + +const rc_provider = new WsProvider(RC_ADDRESS); +await rc_provider.isReady; + // Create and initialize clients -const ahClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"))); +const ahClient = createClient(withPolkadotSdkCompat(getWsProvider(AH_ADDRESS))); const AHApi = ahClient.getTypedApi(wnd_ah); -const penaplClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8001"))); +const penaplClient = createClient(withPolkadotSdkCompat(getWsProvider(PENPAL_ADDRESS))); const PenpalApi = penaplClient.getTypedApi(wnd_penpal); -const rcClient = createClient(withPolkadotSdkCompat(getWsProvider("ws://localhost:8002"))); +const rcClient = createClient(withPolkadotSdkCompat(getWsProvider(RC_ADDRESS))); const rcApi = rcClient.getTypedApi(wnd_penpal); // Initialize HDKD key pairs and signers @@ -191,6 +206,9 @@ test("Initiate Teleport XCM v4 (AH -> RC)", async () => { }); test("Initiate Teleport XCM v5 (AH -> RC)", async () => { + const bob_balance_before = await getFreeBalance(rcApi, BOB_KEY); + const deposit_amount = 1_000_000_000_000n; + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ Enum('WithdrawAsset', [ { @@ -242,7 +260,7 @@ test("Initiate Teleport XCM v5 (AH -> RC)", async () => { }), Enum('DepositAsset', { assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), + fun: XcmV3MultiassetFungibility.Fungible(deposit_amount), id: { parents: 0, interior: XcmV3Junctions.Here() }, }]), beneficiary: { @@ -264,9 +282,13 @@ test("Initiate Teleport XCM v5 (AH -> RC)", async () => { message: msg, max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, }); + const r = await ahToWnd.signAndSubmit(aliceSigner); + await rc_provider.send('dev_newBlock', [{ count: 1 }]) expect(r).toBeTruthy(); - // need to await for a new block + + const bob_balance_after = await getFreeBalance(rcApi, BOB_KEY); + expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); }); test("Initiate Teleport (AH -> RC) with remote fees", async () => { From b090a5a54ea127c4c55aaa21f15c188f2c208efd Mon Sep 17 00:00:00 2001 From: ndk Date: Fri, 24 Jan 2025 18:37:30 +0100 Subject: [PATCH 20/25] updated test command in readme with increased per-test timeout --- .../integration-tests/chopsticks/tests/v5-tests/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md index 428eaae83a7c..85610a5af784 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/README.md @@ -13,7 +13,8 @@ bun add @polkadot-labs/hdkd To run the test: ```bash -bun test ./index.ts +# timeout per test. time in ms. during start-up it takes around 11 sec for test to be executed +bun test ./index.ts --timeout 12000 # note: the test may time out during the first run. Single retry usually helps. ``` From 3cd42907b662b7d26115d9e6102cf6bba238462f Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 27 Jan 2025 13:21:41 +0100 Subject: [PATCH 21/25] Extracted config variables to config.ts, utility functions - to util.ts. Added tests set-up. Refactored the code --- .../chopsticks/tests/v5-tests/config.ts | 18 +++ .../chopsticks/tests/v5-tests/index.ts | 123 ++++++++---------- .../chopsticks/tests/v5-tests/util.ts | 13 ++ 3 files changed, 88 insertions(+), 66 deletions(-) create mode 100644 cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts create mode 100644 cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts new file mode 100644 index 000000000000..96568c3c3c41 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts @@ -0,0 +1,18 @@ +export const CONFIG = { + WESTEND_NETWORK: Uint8Array.from([ + 225, 67, 242, 56, 3, 172, 80, 232, 246, 248, 230, 38, 149, 209, 206, 158, + 78, 29, 104, 170, 54, 193, 205, 44, 253, 21, 52, 2, 19, 243, 66, 62, + ]), + KEYS: { + BOB: "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + ALICE: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + }, + WS_ADDRESSES: { + AH: "ws://localhost:8000", + PENPAL: "ws://localhost:8001", + RC: "ws://localhost:8002", + }, +}; + +// const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; +// const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index d3cbd205c941..3294ead6221a 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -1,4 +1,7 @@ -import { test, expect } from "bun:test"; +import { test, beforeAll, expect } from "bun:test"; +import { CONFIG } from "./config"; +import { createPolkadotClient, getFreeBalance } from './util' + import { wnd_ah, Wnd_ahCalls, @@ -13,73 +16,61 @@ import { XcmV4AssetAssetFilter, XcmV2OriginKind, } from "@polkadot-api/descriptors"; -import { Binary, Enum, createClient } from "polkadot-api"; -import { getWsProvider } from "polkadot-api/ws-provider/web"; -import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"; + +import { Binary, Enum } from "polkadot-api"; +import { getPolkadotSigner } from "polkadot-api/signer"; + import { sr25519CreateDerive } from "@polkadot-labs/hdkd"; import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from "@polkadot-labs/hdkd-helpers"; -import { getPolkadotSigner } from "polkadot-api/signer"; -import { ApiPromise } from '@polkadot/api'; import { WsProvider } from '@polkadot/rpc-provider'; -const WESTEND_NETWORK = Uint8Array.from([ - 225, 67, 242, 56, 3, 172, 80, 232, 246, 248, 230, 38, 149, 209, 206, 158, 78, 29, 104, 170, 54, - 193, 205, 44, 253, 21, 52, 2, 19, 243, 66, 62, -]); -// TODO: find a way to extract keys below from yaml config. -const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; -const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; - -// Addresses -const AH_ADDRESS = 'ws://localhost:8000' -const PENPAL_ADDRESS = 'ws://localhost:8001' -const RC_ADDRESS = 'ws://localhost:8002' - -// init providers -const ah_provider = new WsProvider(AH_ADDRESS); -await ah_provider.isReady; - -const rc_provider = new WsProvider(RC_ADDRESS); -await rc_provider.isReady; - -// Create and initialize clients -const ahClient = createClient(withPolkadotSdkCompat(getWsProvider(AH_ADDRESS))); -const AHApi = ahClient.getTypedApi(wnd_ah); - -const penaplClient = createClient(withPolkadotSdkCompat(getWsProvider(PENPAL_ADDRESS))); -const PenpalApi = penaplClient.getTypedApi(wnd_penpal); - -const rcClient = createClient(withPolkadotSdkCompat(getWsProvider(RC_ADDRESS))); -const rcApi = rcClient.getTypedApi(wnd_penpal); - -// Initialize HDKD key pairs and signers -const entropy = mnemonicToEntropy(DEV_PHRASE); -const miniSecret = entropyToMiniSecret(entropy); -const derive = sr25519CreateDerive(miniSecret); - -const hdkdKeyPairAlice = derive("//Alice"); -const aliceSigner = getPolkadotSigner( - hdkdKeyPairAlice.publicKey, - "Sr25519", - hdkdKeyPairAlice.sign, -); - -const hdkdKeyPairBob = derive("//Bob"); -const bobSigner = getPolkadotSigner( - hdkdKeyPairBob.publicKey, - "Sr25519", - hdkdKeyPairBob.sign, -); - -// Utility function for balance fetching -async function getFreeBalance(api, accountKey) { - const balance = await api.query.System.Account.getValue(accountKey); - return balance.data.free; -} +let ah_provider, rc_provider; +let AHApi, PenpalApi, rcApi; + +let hdkdKeyPairAlice, hdkdKeyPairBob; +let aliceSigner, bobSigner; + + +beforeAll(async () => { + // Initialize HDKD key pairs and signers + const entropy = mnemonicToEntropy(DEV_PHRASE); + const miniSecret = entropyToMiniSecret(entropy); + const derive = sr25519CreateDerive(miniSecret); + + + hdkdKeyPairAlice = derive("//Alice"); + aliceSigner = getPolkadotSigner(hdkdKeyPairAlice.publicKey, + "Sr25519", + hdkdKeyPairAlice.sign, + ); + + hdkdKeyPairBob = derive("//Bob"); + bobSigner = getPolkadotSigner( + hdkdKeyPairBob.publicKey, + "Sr25519", + hdkdKeyPairBob.sign, + ); + + + // init clients + AHApi = createPolkadotClient(CONFIG.WS_ADDRESSES.AH, wnd_ah); + PenpalApi = createPolkadotClient(CONFIG.WS_ADDRESSES.PENPAL, wnd_penpal); + rcApi = createPolkadotClient(CONFIG.WS_ADDRESSES.RC, wnd_rc); + + // init providers + ah_provider = new WsProvider(CONFIG.WS_ADDRESSES.AH); + rc_provider = new WsProvider(CONFIG.WS_ADDRESSES.RC); + + await Promise.all([ + ah_provider.isReady, + rc_provider.isReady, + ]); +}); + test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { - const bobBalanceBefore = await getFreeBalance(AHApi, BOB_KEY); + const bobBalanceBefore = await getFreeBalance(AHApi, CONFIG.KEYS.BOB); const alice_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V5", [ Enum('SetHints', { @@ -88,7 +79,7 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { location: { parents: 0, interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: Enum("ByGenesis", Binary.fromBytes(WESTEND_NETWORK)), + network: Enum("ByGenesis", Binary.fromBytes(CONFIG.WESTEND_NETWORK)), id: Binary.fromBytes(hdkdKeyPairBob.publicKey), })) }, @@ -164,7 +155,7 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { const claimResult = await bobClaimTx.signAndSubmit(bobSigner); expect(claimResult.ok).toBeTruthy(); - const bobBalanceAfter = await getFreeBalance(AHApi, BOB_KEY); + const bobBalanceAfter = await getFreeBalance(AHApi, CONFIG.KEYS.BOB); expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); }); @@ -206,7 +197,7 @@ test("Initiate Teleport XCM v4 (AH -> RC)", async () => { }); test("Initiate Teleport XCM v5 (AH -> RC)", async () => { - const bob_balance_before = await getFreeBalance(rcApi, BOB_KEY); + const bob_balance_before = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); const deposit_amount = 1_000_000_000_000n; const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ @@ -287,7 +278,7 @@ test("Initiate Teleport XCM v5 (AH -> RC)", async () => { await rc_provider.send('dev_newBlock', [{ count: 1 }]) expect(r).toBeTruthy(); - const bob_balance_after = await getFreeBalance(rcApi, BOB_KEY); + const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); }); @@ -739,7 +730,7 @@ test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ Ini const r = await ahToPpl.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); - expect(await getFreeBalance(AHApi, ALICE_KEY)).toBeLessThan( + expect(await getFreeBalance(AHApi, CONFIG.KEYS.ALICE)).toBeLessThan( 1_000_000_000_000_000n - 10_000_000_000_000n ); }); diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts new file mode 100644 index 000000000000..dffe0bb83dd4 --- /dev/null +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts @@ -0,0 +1,13 @@ +import { createClient } from "polkadot-api"; +import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"; +import { getWsProvider } from "polkadot-api/ws-provider/web"; + +export function createPolkadotClient(wsAddress, apiType) { + const client = createClient(withPolkadotSdkCompat(getWsProvider(wsAddress))); + return client.getTypedApi(apiType); +} + +export async function getFreeBalance(api, accountKey) { + const balance = await api.query.System.Account.getValue(accountKey); + return balance.data.free; +} From 52b66c3a0e333dfefd85d4587c60a789a229c0aa Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 27 Jan 2025 13:23:04 +0100 Subject: [PATCH 22/25] removed commented lines --- .../integration-tests/chopsticks/tests/v5-tests/config.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts index 96568c3c3c41..068668bfe950 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts @@ -13,6 +13,3 @@ export const CONFIG = { RC: "ws://localhost:8002", }, }; - -// const BOB_KEY = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; -// const ALICE_KEY = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; From 785cdadac1f6e50d244856f065395cfe04262644 Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 27 Jan 2025 13:43:15 +0100 Subject: [PATCH 23/25] added assets deposit together with balance check to XCM v4 Teleport --- .../chopsticks/tests/v5-tests/index.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 3294ead6221a..87f33f2e400e 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -160,6 +160,9 @@ test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { }); test("Initiate Teleport XCM v4 (AH -> RC)", async () => { + const bob_balance_before = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); + const deposit_amount = 5_000_000_000_000n; + const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V4", [ XcmV4Instruction.WithdrawAsset([{ id: { parents: 1, interior: XcmV3Junctions.Here() }, @@ -182,6 +185,21 @@ test("Initiate Teleport XCM v4 (AH -> RC)", async () => { }, weight_limit: XcmV3WeightLimit.Unlimited(), }), + XcmV4Instruction.DepositAsset({ + assets: XcmV3MultiassetMultiAssetFilter.Definite([{ + fun: XcmV3MultiassetFungibility.Fungible(deposit_amount), + id: { parents: 0, interior: XcmV3Junctions.Here() }, + }]), + beneficiary: { + parents: 0, + interior: XcmV3Junctions.X1( + XcmV3Junction.AccountId32({ + network: undefined, + id: Binary.fromBytes(hdkdKeyPairBob.publicKey), + }) + ), + }, + }), ], }), ]); @@ -194,6 +212,10 @@ test("Initiate Teleport XCM v4 (AH -> RC)", async () => { const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); + + await rc_provider.send('dev_newBlock', [{ count: 1 }]) + const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); + expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); }); test("Initiate Teleport XCM v5 (AH -> RC)", async () => { From 258131dedaa0e97889586d8397bb9d52ecd4cf7a Mon Sep 17 00:00:00 2001 From: ndk Date: Mon, 27 Jan 2025 13:49:39 +0100 Subject: [PATCH 24/25] added balance check to Initiate Teleport v5 --- .../integration-tests/chopsticks/tests/v5-tests/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 87f33f2e400e..07a78b95eb82 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -297,9 +297,9 @@ test("Initiate Teleport XCM v5 (AH -> RC)", async () => { }); const r = await ahToWnd.signAndSubmit(aliceSigner); - await rc_provider.send('dev_newBlock', [{ count: 1 }]) expect(r).toBeTruthy(); + await rc_provider.send('dev_newBlock', [{ count: 1 }]) const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); }); @@ -368,6 +368,10 @@ test("Initiate Teleport (AH -> RC) with remote fees", async () => { ); const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); + + await rc_provider.send('dev_newBlock', [{ count: 1 }]) + const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); + expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); }); test("Reserve Asset Transfer (local) of USDT from Asset Hub `Alice` to Penpal `Alice`", async () => { From 937369d6a611d50c8453b0f9bcf4472657caec00 Mon Sep 17 00:00:00 2001 From: ndk Date: Fri, 31 Jan 2025 19:20:32 +0100 Subject: [PATCH 25/25] added initial network set-up. test in progress --- .../chopsticks/tests/v5-tests/config.ts | 6 +- .../chopsticks/tests/v5-tests/index.ts | 1340 +++++++++-------- .../chopsticks/tests/v5-tests/util.ts | 4 +- 3 files changed, 700 insertions(+), 650 deletions(-) diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts index 068668bfe950..6b685ed22eb1 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/config.ts @@ -8,8 +8,8 @@ export const CONFIG = { ALICE: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", }, WS_ADDRESSES: { - AH: "ws://localhost:8000", - PENPAL: "ws://localhost:8001", - RC: "ws://localhost:8002", + AH: "wss://westend-asset-hub-rpc.polkadot.io", + PENPAL: "wss://westend-penpal-rpc.polkadot.io", + RC: "wss://westend-rpc.polkadot.io", }, }; diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts index 07a78b95eb82..a8f38df191e6 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/index.ts @@ -23,9 +23,15 @@ import { getPolkadotSigner } from "polkadot-api/signer"; import { sr25519CreateDerive } from "@polkadot-labs/hdkd"; import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from "@polkadot-labs/hdkd-helpers"; -import { WsProvider } from '@polkadot/rpc-provider'; +// import { WsProvider } from '@polkadot/rpc-provider'; +import { setupNetworks, type NetworkContext } from "@acala-network/chopsticks-testing" +import { createClient } from "polkadot-api"; +import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"; +import { getWsProvider } from "polkadot-api/ws-provider/web"; +let parachain: NetworkContext, polkadot: NetworkContext, assetHub: NetworkContext; let ah_provider, rc_provider; +// todo unify, small case start let AHApi, PenpalApi, rcApi; let hdkdKeyPairAlice, hdkdKeyPairBob; @@ -38,6 +44,48 @@ beforeAll(async () => { const miniSecret = entropyToMiniSecret(entropy); const derive = sr25519CreateDerive(miniSecret); + ({ parachain, polkadot, assetHub } = await setupNetworks({ + // todo how to specify penpal explicitly, not a general parachain? + parachain: { + endpoint: CONFIG.WS_ADDRESSES.PENPAL, + // move hardcoded values to .env + 'wasm-override': '../../wasms/penpal_runtime.compact.compressed.wasm', + 'runtime-log-level': 5, + db: './db.sqlite', + port: 8006, + }, + // todo is there a westend option? I tried setting it up and got an error. + // todo how and where to find it? + polkadot: { + endpoint: CONFIG.WS_ADDRESSES.RC, + 'wasm-override': '../../wasms/westend_runtime.compact.compressed.wasm', + 'runtime-log-level': 5, + db: './db.sqlite', + port: 8007, + }, + assetHub: { + endpoint: CONFIG.WS_ADDRESSES.AH, + // move hardcoded values to .env + 'wasm-override': '../../wasms/asset_hub_westend_runtime.compact.compressed.wasm', + 'runtime-log-level': 5, + db: './db.sqlite', + port: 8008, + }, + })); + + // init clients + AHApi = createPolkadotClient(assetHub.ws.endpoint, wnd_ah); + PenpalApi = createPolkadotClient(parachain.ws.endpoint, wnd_penpal); + rcApi = createPolkadotClient(polkadot.ws.endpoint, wnd_rc); + + + // const penpalClient = createClient(getWsProvider(parachain.ws.endpoint)); + // PenpalApi = penpalClient.getTypedApi(wnd_penpal); + // const rcClient = createClient(getWsProvider(polkadot.ws.endpoint)); + // rcApi = rcClient.getTypedApi(wnd_rc); + // const assetHubClient = createClient(getWsProvider(assetHub.ws.endpoint)); + // AHApi = assetHubClient.getTypedApi(wnd_ah); + hdkdKeyPairAlice = derive("//Alice"); aliceSigner = getPolkadotSigner(hdkdKeyPairAlice.publicKey, @@ -53,113 +101,111 @@ beforeAll(async () => { ); - // init clients - AHApi = createPolkadotClient(CONFIG.WS_ADDRESSES.AH, wnd_ah); - PenpalApi = createPolkadotClient(CONFIG.WS_ADDRESSES.PENPAL, wnd_penpal); - rcApi = createPolkadotClient(CONFIG.WS_ADDRESSES.RC, wnd_rc); - // init providers - ah_provider = new WsProvider(CONFIG.WS_ADDRESSES.AH); - rc_provider = new WsProvider(CONFIG.WS_ADDRESSES.RC); - - await Promise.all([ - ah_provider.isReady, - rc_provider.isReady, - ]); + // ah_provider = new WsProvider(CONFIG.WS_ADDRESSES.AH); + // rc_provider = new WsProvider(CONFIG.WS_ADDRESSES.RC); + // + // await Promise.all([ + // ah_provider.isReady, + // rc_provider.isReady, + // ]); }); -test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { - const bobBalanceBefore = await getFreeBalance(AHApi, CONFIG.KEYS.BOB); - - const alice_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V5", [ - Enum('SetHints', { - hints: [ - Enum('AssetClaimer', { - location: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: Enum("ByGenesis", Binary.fromBytes(CONFIG.WESTEND_NETWORK)), - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })) - }, - }) - ], - }), - Enum('WithdrawAsset', [{ - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }]), - Enum('ClearOrigin'), - ]); - const alice_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(alice_msg); - - // Transaction 1: Alice sets asset claimer to Bob and sends a trap transaction - const trapTx = AHApi.tx.PolkadotXcm.execute({ - message: alice_msg, - max_weight: { - ref_time: alice_weight.value.ref_time, - proof_size: alice_weight.value.proof_size, - }, - }); - - const trapResult = await trapTx.signAndSubmit(aliceSigner); - expect(trapResult.ok).toBeTruthy(); - - const bob_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V4", [ - XcmV4Instruction.ClaimAsset({ - assets: [ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - ], - ticket: { parents: 0, interior: XcmV3Junctions.Here() }, - }), - XcmV4Instruction.BuyExecution({ - fees: { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000n), - }, - weight_limit: XcmV3WeightLimit.Unlimited(), - }), - XcmV4Instruction.DepositAsset({ - assets: XcmV3MultiassetMultiAssetFilter.Definite([ - { - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - id: { parents: 1, interior: XcmV3Junctions.Here() }, - }, - ]), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - }) - ), - }, - }), - ]); - const bob_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(bob_msg); - - // Transaction 2: Bob claims trapped assets. - const bobClaimTx = AHApi.tx.PolkadotXcm.execute({ - message: bob_msg, - max_weight: { - ref_time: bob_weight.value.ref_time, - proof_size: bob_weight.value.proof_size, - }, - }); - - const claimResult = await bobClaimTx.signAndSubmit(bobSigner); - expect(claimResult.ok).toBeTruthy(); - - const bobBalanceAfter = await getFreeBalance(AHApi, CONFIG.KEYS.BOB); - expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); -}); +// test("Set Asset Claimer, Trap Assets, Claim Trapped Assets", async () => { +// const bobBalanceBefore = await getFreeBalance(AHApi, CONFIG.KEYS.BOB); +// +// console.log("test start") +// +// const alice_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V5", [ +// Enum('SetHints', { +// hints: [ +// Enum('AssetClaimer', { +// location: { +// parents: 0, +// interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ +// network: Enum("ByGenesis", Binary.fromBytes(CONFIG.WESTEND_NETWORK)), +// id: Binary.fromBytes(hdkdKeyPairBob.publicKey), +// })) +// }, +// }) +// ], +// }), +// Enum('WithdrawAsset', [{ +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }]), +// Enum('ClearOrigin'), +// ]); +// const alice_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(alice_msg); +// +// // Transaction 1: Alice sets asset claimer to Bob and sends a trap transaction +// const trapTx = AHApi.tx.PolkadotXcm.execute({ +// message: alice_msg, +// max_weight: { +// ref_time: alice_weight.value.ref_time, +// proof_size: alice_weight.value.proof_size, +// }, +// }); +// +// const trapResult = await trapTx.signAndSubmit(aliceSigner); +// expect(trapResult.ok).toBeTruthy(); +// +// const bob_msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum("V4", [ +// XcmV4Instruction.ClaimAsset({ +// assets: [ +// { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }, +// ], +// ticket: { parents: 0, interior: XcmV3Junctions.Here() }, +// }), +// XcmV4Instruction.BuyExecution({ +// fees: { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000n), +// }, +// weight_limit: XcmV3WeightLimit.Unlimited(), +// }), +// XcmV4Instruction.DepositAsset({ +// assets: XcmV3MultiassetMultiAssetFilter.Definite([ +// { +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// }, +// ]), +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1( +// XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairBob.publicKey), +// }) +// ), +// }, +// }), +// ]); +// const bob_weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(bob_msg); +// +// // Transaction 2: Bob claims trapped assets. +// const bobClaimTx = AHApi.tx.PolkadotXcm.execute({ +// message: bob_msg, +// max_weight: { +// ref_time: bob_weight.value.ref_time, +// proof_size: bob_weight.value.proof_size, +// }, +// }); +// +// const claimResult = await bobClaimTx.signAndSubmit(bobSigner); +// expect(claimResult.ok).toBeTruthy(); +// +// const bobBalanceAfter = await getFreeBalance(AHApi, CONFIG.KEYS.BOB); +// expect(bobBalanceAfter > bobBalanceBefore).toBeTruthy(); +// }); test("Initiate Teleport XCM v4 (AH -> RC)", async () => { + // set storage for Alice const bob_balance_before = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); const deposit_amount = 5_000_000_000_000n; @@ -213,550 +259,554 @@ test("Initiate Teleport XCM v4 (AH -> RC)", async () => { const r = await ahToWnd.signAndSubmit(aliceSigner); expect(r).toBeTruthy(); - await rc_provider.send('dev_newBlock', [{ count: 1 }]) + await polkadot.ws.send('dev_newBlock', [{ count: 1 }]) const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); }); -test("Initiate Teleport XCM v5 (AH -> RC)", async () => { - const bob_balance_before = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); - const deposit_amount = 1_000_000_000_000n; - - const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - Enum('WithdrawAsset', [ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - }), - Enum('InitiateTransfer', { - destination: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - // optional field. an example of usage: - // remote_fees: Enum('Teleport', { - // type: 'Wild', - // value: { - // type: 'All', - // value: undefined, - // }, - // }), - preserve_origin: false, - assets: [ - Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - }), - ], - remote_xcm: [ - Enum('PayFees', { - asset: { - id: { - parents: 0, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - }), - Enum('DepositAsset', { - assets: XcmV3MultiassetMultiAssetFilter.Definite([{ - fun: XcmV3MultiassetFungibility.Fungible(deposit_amount), - id: { parents: 0, interior: XcmV3Junctions.Here() }, - }]), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - }) - ), - }, - }), - ], - }), - ]); - const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); - - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }); - - const r = await ahToWnd.signAndSubmit(aliceSigner); - expect(r).toBeTruthy(); - - await rc_provider.send('dev_newBlock', [{ count: 1 }]) - const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); - expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); -}); - -test("Initiate Teleport (AH -> RC) with remote fees", async () => { - const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - Enum('WithdrawAsset', [ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), - } - }), - Enum('InitiateTransfer', { - destination: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - // optional field. an example of usage: - remote_fees: Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - }), - preserve_origin: false, - assets: [Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - })], - remote_xcm: [ - Enum('DepositAsset', { - assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: 'All', - value: undefined, - }), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), - }, - }), - ], - }), - ]); - const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); - - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }, - ); - const r = await ahToWnd.signAndSubmit(aliceSigner); - expect(r).toBeTruthy(); - - await rc_provider.send('dev_newBlock', [{ count: 1 }]) - const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); - expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); -}); - -test("Reserve Asset Transfer (local) of USDT from Asset Hub `Alice` to Penpal `Alice`", async () => { - const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - Enum('WithdrawAsset', [ - { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - }), - Enum('TransferReserveAsset', { - assets: [ - { - id: { - parents: 0, - interior: XcmV3Junctions.X2([ - XcmV3Junction.PalletInstance(50), - XcmV3Junction.GeneralIndex(1984n)]), - }, - fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), - }, - { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), - }, - ], - dest: { - parents: 1, - interior: XcmV3Junctions.X1( - XcmV3Junction.Parachain(2042), - ), - }, - xcm: [ - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000n), - }, - }), - Enum('DepositAsset', { - // some WND might get trapped bc of extra fungibles in PayFees above ^ - assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: 'All', - value: undefined, - }), - - // ===================== GRANULAR VERSIONS ===================== - // assets: XcmV4AssetAssetFilter.Definite([{ - // id: { - // parents: 1, - // interior: XcmV3Junctions.Here(), - // }, - // fun: XcmV3MultiassetFungibility.Fungible(3_995_000_000_000n), - // }]), - // - // assets: XcmV4AssetAssetFilter.Definite([{ - // id: { - // parents: 1, - // interior: XcmV3Junctions.X3([ - // XcmV3Junction.Parachain(1000), - // XcmV3Junction.PalletInstance(50), - // XcmV3Junction.GeneralIndex(1984n)]), - // }, - // fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), - // }]), - // ===================== END ===================== - - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), - })), - }, - }), - ], - }), - ]); - - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: 100_000_000_000n, proof_size: 1_000_000n }, - }, - ); - const r = await ahToWnd.signAndSubmit(aliceSigner); - expect(r).toBeTruthy(); -}); - -// this test scenario works together with the previous one. -// previous test serves as a set-up for this one. -test("InitiateReserveWithdraw USDT from Penpal `Alice` to Asset Hub `Bob`", async () => { - const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - Enum('WithdrawAsset', [ - { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(3_995_000_000_000n), - }, - { - id: { - parents: 1, - interior: XcmV3Junctions.X3([ - XcmV3Junction.Parachain(1000), - XcmV3Junction.PalletInstance(50), - XcmV3Junction.GeneralIndex(1984n), - ]), - }, - fun: XcmV3MultiassetFungibility.Fungible(70_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - }), - Enum('InitiateReserveWithdraw' , { - assets: XcmV4AssetAssetFilter.Wild({ - type: 'All', - value: undefined, - }), - reserve: { - parents: 1, - interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1000)), - }, - xcm: [ - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), - }, - }), - Enum('DepositAsset', { - assets: XcmV3MultiassetMultiAssetFilter.Wild({ - type: 'All', - value: undefined, - }), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairBob.publicKey), - })), - }, - }), - ], - }), - ]); - - - const penpalToAH = PenpalApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: 100_000_000_000n, proof_size: 1_000_000n }, - }, - ); - const r = await penpalToAH.signAndSubmit(aliceSigner); - expect(r).toBeTruthy(); -}); - -test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { - const remarkWithEventCalldata = await PenpalApi.tx.System.remark_with_event({ - remark: Binary.fromText("Hello, World!"), - }).getEncodedData(); - - PenpalApi.event.System.Remarked.watch().forEach((e) => - console.log( - `\nBlock: ${e.meta.block.number}\nSender: ${ - e.payload.sender - }\nHash: ${e.payload.hash.asHex()}\n` - ) - ); - - const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), - }, - }), - Enum('InitiateTransfer', { - destination: { - parents: 1, - interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2042)), - }, - remote_fees: { - type: 'Teleport', - value: { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - }, - }, - preserve_origin: true, - assets: [], - remote_xcm: [ - { - type: 'Transact', - value: { - origin_kind: XcmV2OriginKind.SovereignAccount(), - call: remarkWithEventCalldata, - }, - }, - ], - }), - ]); - - const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); - const ahToWnd = AHApi.tx.PolkadotXcm.execute({ - msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }); - const r = await ahToWnd.signAndSubmit(aliceSigner); - expect(r.ok).toBeTruthy(); -}); - -test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTeleport", async () => { - const message: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), - }, - }), - XcmV4Instruction.InitiateTeleport({ - assets: XcmV4AssetAssetFilter.Wild({ type: 'All', value: undefined }), - dest: { - parents: 1, - interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), - }, - xcm: [ - XcmV4Instruction.BuyExecution({ - fees: { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), - }, - weight_limit: XcmV3WeightLimit.Unlimited(), - }), - XcmV4Instruction.DepositAsset({ - assets: XcmV4AssetAssetFilter.Wild({ type: 'All', value: undefined }), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), - }) - ), - }, - }), - ], - }), - ]); - const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(message); - - const ahToPpl = AHApi.tx.PolkadotXcm.execute({ - message, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }); - const r = await ahToPpl.signAndSubmit(aliceSigner); - expect(r).toBeTruthy(); -}); - -test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTransfer", async () => { - const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ - XcmV4Instruction.WithdrawAsset([ - { - id: { parents: 1, interior: XcmV3Junctions.Here() }, - fun: XcmV3MultiassetFungibility.Fungible(10_000_000_000_000n), - }, - ]), - Enum('PayFees', { - asset: { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(665_000_000_000n), - }, - }), - Enum('InitiateTransfer', { - destination: { - parents: 1, - interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), - }, - remote_fees: { - type: 'Teleport', - value: { - type: 'Definite', - value: [ - { - id: { - parents: 1, - interior: XcmV3Junctions.Here(), - }, - fun: XcmV3MultiassetFungibility.Fungible(365_000_000_000n), - }, - ], - }, - }, - preserve_origin: true, - assets: [ - Enum('Teleport', { - type: 'Wild', - value: { - type: 'All', - value: undefined, - }, - }), - ], - remote_xcm: [ - XcmV4Instruction.DepositAsset({ - assets: XcmV4AssetAssetFilter.Wild({ - type: 'All', - value: undefined, - }), - beneficiary: { - parents: 0, - interior: XcmV3Junctions.X1( - XcmV3Junction.AccountId32({ - network: undefined, - id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), - }) - ), - }, - }), - ], - }), - ]); - - const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); - const ahToPpl = AHApi.tx.PolkadotXcm.execute({ - message: msg, - max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, - }); - - const r = await ahToPpl.signAndSubmit(aliceSigner); - expect(r).toBeTruthy(); - - expect(await getFreeBalance(AHApi, CONFIG.KEYS.ALICE)).toBeLessThan( - 1_000_000_000_000_000n - 10_000_000_000_000n - ); -}); +// test("Initiate Teleport XCM v5 (AH -> RC)", async () => { +// const bob_balance_before = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); +// const deposit_amount = 1_000_000_000_000n; +// +// const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// Enum('WithdrawAsset', [ +// { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }, +// }), +// Enum('InitiateTransfer', { +// destination: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// // optional field. an example of usage: +// // remote_fees: Enum('Teleport', { +// // type: 'Wild', +// // value: { +// // type: 'All', +// // value: undefined, +// // }, +// // }), +// preserve_origin: false, +// assets: [ +// Enum('Teleport', { +// type: 'Wild', +// value: { +// type: 'All', +// value: undefined, +// }, +// }), +// ], +// remote_xcm: [ +// Enum('PayFees', { +// asset: { +// id: { +// parents: 0, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }, +// }), +// Enum('DepositAsset', { +// assets: XcmV3MultiassetMultiAssetFilter.Definite([{ +// fun: XcmV3MultiassetFungibility.Fungible(deposit_amount), +// id: { parents: 0, interior: XcmV3Junctions.Here() }, +// }]), +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1( +// XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairBob.publicKey), +// }) +// ), +// }, +// }), +// ], +// }), +// ]); +// const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); +// +// const ahToWnd = AHApi.tx.PolkadotXcm.execute({ +// message: msg, +// max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, +// }); +// +// const r = await ahToWnd.signAndSubmit(aliceSigner); +// expect(r).toBeTruthy(); +// +// await rc_provider.send('dev_newBlock', [{ count: 1 }]) +// const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); +// expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); +// }); + +// test("Initiate Teleport (AH -> RC) with remote fees", async () => { +// const bob_balance_before = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); +// const deposit_amount = 1_000_000_000_000n; +// +// const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// Enum('WithdrawAsset', [ +// { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(2_000_000_000_000n), +// } +// }), +// Enum('InitiateTransfer', { +// destination: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// // optional field. an example of usage: +// remote_fees: Enum('Teleport', { +// type: 'Wild', +// value: { +// type: 'All', +// value: undefined, +// }, +// }), +// preserve_origin: false, +// assets: [Enum('Teleport', { +// type: 'Wild', +// value: { +// type: 'All', +// value: undefined, +// }, +// })], +// remote_xcm: [ +// // something is wrong here! +// Enum('DepositAsset', { +// assets: XcmV3MultiassetMultiAssetFilter.Wild({ +// type: 'All', +// value: undefined, +// }), +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairBob.publicKey), +// })), +// }, +// }), +// ], +// }), +// ]); +// const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); +// +// const ahToWnd = AHApi.tx.PolkadotXcm.execute({ +// message: msg, +// max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, +// }, +// ); +// const r = await ahToWnd.signAndSubmit(aliceSigner); +// expect(r).toBeTruthy(); +// +// await rc_provider.send('dev_newBlock', [{ count: 1 }]) +// const bob_balance_after = await getFreeBalance(rcApi, CONFIG.KEYS.BOB); +// expect(bob_balance_after - bob_balance_before).toBe(deposit_amount); +// }); + +// test("Reserve Asset Transfer (local) of USDT from Asset Hub `Alice` to Penpal `Alice`", async () => { +// const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// Enum('WithdrawAsset', [ +// { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }, +// }), +// Enum('TransferReserveAsset', { +// assets: [ +// { +// id: { +// parents: 0, +// interior: XcmV3Junctions.X2([ +// XcmV3Junction.PalletInstance(50), +// XcmV3Junction.GeneralIndex(1984n)]), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), +// }, +// { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), +// }, +// ], +// dest: { +// parents: 1, +// interior: XcmV3Junctions.X1( +// XcmV3Junction.Parachain(2042), +// ), +// }, +// xcm: [ +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000n), +// }, +// }), +// Enum('DepositAsset', { +// // some WND might get trapped bc of extra fungibles in PayFees above ^ +// assets: XcmV3MultiassetMultiAssetFilter.Wild({ +// type: 'All', +// value: undefined, +// }), +// +// // ===================== GRANULAR VERSIONS ===================== +// // assets: XcmV4AssetAssetFilter.Definite([{ +// // id: { +// // parents: 1, +// // interior: XcmV3Junctions.Here(), +// // }, +// // fun: XcmV3MultiassetFungibility.Fungible(3_995_000_000_000n), +// // }]), +// // +// // assets: XcmV4AssetAssetFilter.Definite([{ +// // id: { +// // parents: 1, +// // interior: XcmV3Junctions.X3([ +// // XcmV3Junction.Parachain(1000), +// // XcmV3Junction.PalletInstance(50), +// // XcmV3Junction.GeneralIndex(1984n)]), +// // }, +// // fun: XcmV3MultiassetFungibility.Fungible(100_000_000n), +// // }]), +// // ===================== END ===================== +// +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), +// })), +// }, +// }), +// ], +// }), +// ]); +// +// const ahToWnd = AHApi.tx.PolkadotXcm.execute({ +// message: msg, +// max_weight: { ref_time: 100_000_000_000n, proof_size: 1_000_000n }, +// }, +// ); +// const r = await ahToWnd.signAndSubmit(aliceSigner); +// expect(r).toBeTruthy(); +// }); +// +// // this test scenario works together with the previous one. +// // previous test serves as a set-up for this one. +// test("InitiateReserveWithdraw USDT from Penpal `Alice` to Asset Hub `Bob`", async () => { +// const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// Enum('WithdrawAsset', [ +// { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(3_995_000_000_000n), +// }, +// { +// id: { +// parents: 1, +// interior: XcmV3Junctions.X3([ +// XcmV3Junction.Parachain(1000), +// XcmV3Junction.PalletInstance(50), +// XcmV3Junction.GeneralIndex(1984n), +// ]), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(70_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }, +// }), +// Enum('InitiateReserveWithdraw' , { +// assets: XcmV4AssetAssetFilter.Wild({ +// type: 'All', +// value: undefined, +// }), +// reserve: { +// parents: 1, +// interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1000)), +// }, +// xcm: [ +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000_000n), +// }, +// }), +// Enum('DepositAsset', { +// assets: XcmV3MultiassetMultiAssetFilter.Wild({ +// type: 'All', +// value: undefined, +// }), +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1(XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairBob.publicKey), +// })), +// }, +// }), +// ], +// }), +// ]); +// +// +// const penpalToAH = PenpalApi.tx.PolkadotXcm.execute({ +// message: msg, +// max_weight: { ref_time: 100_000_000_000n, proof_size: 1_000_000n }, +// }, +// ); +// const r = await penpalToAH.signAndSubmit(aliceSigner); +// expect(r).toBeTruthy(); +// }); +// +// test("Teleport and Transact from Westend's Asset Hub to Penpal", async () => { +// const remarkWithEventCalldata = await PenpalApi.tx.System.remark_with_event({ +// remark: Binary.fromText("Hello, World!"), +// }).getEncodedData(); +// +// PenpalApi.event.System.Remarked.watch().forEach((e) => +// console.log( +// `\nBlock: ${e.meta.block.number}\nSender: ${ +// e.payload.sender +// }\nHash: ${e.payload.hash.asHex()}\n` +// ) +// ); +// +// const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// XcmV4Instruction.WithdrawAsset([ +// { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(4_000_000_000_000n), +// }, +// }), +// Enum('InitiateTransfer', { +// destination: { +// parents: 1, +// interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(2042)), +// }, +// remote_fees: { +// type: 'Teleport', +// value: { +// type: 'Wild', +// value: { +// type: 'All', +// value: undefined, +// }, +// }, +// }, +// preserve_origin: true, +// assets: [], +// remote_xcm: [ +// { +// type: 'Transact', +// value: { +// origin_kind: XcmV2OriginKind.SovereignAccount(), +// call: remarkWithEventCalldata, +// }, +// }, +// ], +// }), +// ]); +// +// const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); +// const ahToWnd = AHApi.tx.PolkadotXcm.execute({ +// msg, +// max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, +// }); +// const r = await ahToWnd.signAndSubmit(aliceSigner); +// expect(r.ok).toBeTruthy(); +// }); +// +// test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTeleport", async () => { +// const message: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// XcmV4Instruction.WithdrawAsset([ +// { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(5_000_000_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), +// }, +// }), +// XcmV4Instruction.InitiateTeleport({ +// assets: XcmV4AssetAssetFilter.Wild({ type: 'All', value: undefined }), +// dest: { +// parents: 1, +// interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), +// }, +// xcm: [ +// XcmV4Instruction.BuyExecution({ +// fees: { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(500_000_000_000n), +// }, +// weight_limit: XcmV3WeightLimit.Unlimited(), +// }), +// XcmV4Instruction.DepositAsset({ +// assets: XcmV4AssetAssetFilter.Wild({ type: 'All', value: undefined }), +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1( +// XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), +// }) +// ), +// }, +// }), +// ], +// }), +// ]); +// const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(message); +// +// const ahToPpl = AHApi.tx.PolkadotXcm.execute({ +// message, +// max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, +// }); +// const r = await ahToPpl.signAndSubmit(aliceSigner); +// expect(r).toBeTruthy(); +// }); +// +// test("Initiate Teleport XCM v5 from Westend's Asset Hub to Westend People w/ InitiateTransfer", async () => { +// const msg: Wnd_ahCalls['PolkadotXcm']['execute']['message'] = Enum('V5', [ +// XcmV4Instruction.WithdrawAsset([ +// { +// id: { parents: 1, interior: XcmV3Junctions.Here() }, +// fun: XcmV3MultiassetFungibility.Fungible(10_000_000_000_000n), +// }, +// ]), +// Enum('PayFees', { +// asset: { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(665_000_000_000n), +// }, +// }), +// Enum('InitiateTransfer', { +// destination: { +// parents: 1, +// interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(1004)), +// }, +// remote_fees: { +// type: 'Teleport', +// value: { +// type: 'Definite', +// value: [ +// { +// id: { +// parents: 1, +// interior: XcmV3Junctions.Here(), +// }, +// fun: XcmV3MultiassetFungibility.Fungible(365_000_000_000n), +// }, +// ], +// }, +// }, +// preserve_origin: true, +// assets: [ +// Enum('Teleport', { +// type: 'Wild', +// value: { +// type: 'All', +// value: undefined, +// }, +// }), +// ], +// remote_xcm: [ +// XcmV4Instruction.DepositAsset({ +// assets: XcmV4AssetAssetFilter.Wild({ +// type: 'All', +// value: undefined, +// }), +// beneficiary: { +// parents: 0, +// interior: XcmV3Junctions.X1( +// XcmV3Junction.AccountId32({ +// network: undefined, +// id: Binary.fromBytes(hdkdKeyPairAlice.publicKey), +// }) +// ), +// }, +// }), +// ], +// }), +// ]); +// +// const weight = await AHApi.apis.XcmPaymentApi.query_xcm_weight(msg); +// const ahToPpl = AHApi.tx.PolkadotXcm.execute({ +// message: msg, +// max_weight: { ref_time: weight.value.ref_time, proof_size: weight.value.proof_size }, +// }); +// +// const r = await ahToPpl.signAndSubmit(aliceSigner); +// expect(r).toBeTruthy(); +// +// expect(await getFreeBalance(AHApi, CONFIG.KEYS.ALICE)).toBeLessThan( +// 1_000_000_000_000_000n - 10_000_000_000_000n +// ); +// }); diff --git a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts index dffe0bb83dd4..c37071a1dd26 100644 --- a/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts +++ b/cumulus/parachains/integration-tests/chopsticks/tests/v5-tests/util.ts @@ -2,8 +2,8 @@ import { createClient } from "polkadot-api"; import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"; import { getWsProvider } from "polkadot-api/ws-provider/web"; -export function createPolkadotClient(wsAddress, apiType) { - const client = createClient(withPolkadotSdkCompat(getWsProvider(wsAddress))); +export function createPolkadotClient(endpoint, apiType) { + const client = createClient(getWsProvider(endpoint)); return client.getTypedApi(apiType); }