diff --git a/e2e-tests/tests/config.ts b/e2e-tests/tests/config.ts index 5a7cf026..964659ae 100644 --- a/e2e-tests/tests/config.ts +++ b/e2e-tests/tests/config.ts @@ -17,7 +17,7 @@ export const RELAYCHAIN_NODE_URL = "http://127.0.0.1:9944"; // Chain config export const CHAIN_ID = 667; export const GAS_PRICE = "0x3B9ACA00"; -export const ASSET_HUB_PARA_ID = 2000; +export const ASSET_HUB_PARA_ID = 1000; export const LAOS_PARA_ID = 2900; // Accounts diff --git a/e2e-tests/tests/test-create-foreign-asset.ts b/e2e-tests/tests/test-create-foreign-asset.ts deleted file mode 100644 index 3a52315f..00000000 --- a/e2e-tests/tests/test-create-foreign-asset.ts +++ /dev/null @@ -1,105 +0,0 @@ -import BN from "bn.js"; -import { assert, expect } from "chai"; -import { step } from "mocha-steps"; - -import { ALITH_PRIVATE_KEY, ASSET_HUB_PARA_ID, CHAIN_ID, FAITH, FAITH_PRIVATE_KEY, LAOS_PARA_ID, RUNTIME_IMPL_VERSION, RUNTIME_SPEC_NAME, RUNTIME_SPEC_VERSION } from "./config"; -import { customRequest, describeWithExistingNode } from "./util"; -import { Keyring } from "@polkadot/api"; - -describeWithExistingNode("Asset Hub (Create Foreign Asset)", (context) => { - step("HRMP channels between Asset Hub and LAOS are open", async function () { - const laosToAssetHubChannel = await context.networks.relaychain.query.hrmp.hrmpChannels({ - sender: LAOS_PARA_ID, - recipient: ASSET_HUB_PARA_ID, - }); - expect(laosToAssetHubChannel.isEmpty).to.be.false; - const assetHubToLaosChannel = await context.networks.relaychain.query.hrmp.hrmpChannels({ - sender: ASSET_HUB_PARA_ID, - recipient: LAOS_PARA_ID, - }); - expect(assetHubToLaosChannel.isEmpty).to.be.false; - }); - - step("", async function () { - const apiLaos = await context.networks.laos; - const apiAssetHub = await context.networks.assetHub; - const faith = new Keyring().addFromUri(FAITH_PRIVATE_KEY); - const alith = new Keyring({ type: "ethereum" }).addFromUri(ALITH_PRIVATE_KEY); - - const destination = apiLaos.createType('XcmVersionedLocation', { - V3: { - parents: '1', - interior: { - X1: { Parachain: ASSET_HUB_PARA_ID }, - }, - }, - }); - - let accountId = apiAssetHub.createType('AccountId', faith.address); - const beneficiary = apiLaos.createType('XcmVersionedLocation', { - V2: { - parents: '0', - interior: { - X1: { - AccountId32: { - network: 'Any', - id: accountId.toHex(), - }, - }, - }, - }, - }); - - // 1 KSM = 10^12, this is .1 KSM - const amount = 100000000000; - const assets = apiLaos.createType('XcmVersionedAssets', { - V2: [ - { - id: { - Concrete: { - parents: 0, - interior: { - Here: '', - }, - }, - }, - fun: { - Fungible: amount, - }, - }, - ], - }); - const fee_asset_item = '0'; - const weight_limit = 'Unlimited'; - - const call = apiLaos.tx.polkadotXcm.limitedTeleportAssets( - destination, - beneficiary, - assets, - fee_asset_item, - weight_limit - ); - - // const unsubscribe = await call.signAndSend( - // alith, - // ( {status} ) => { - // console.log(`Current status is ${status}`); - - // if (status.isInBlock) { - // console.log(`Transaction included at blockHash ${status.asInBlock}`); - // } else if (status.isFinalized) { - // console.log(`Transaction finalized at blockHash ${status.asFinalized}`); - // unsubscribe(); - // } - // } - // ); - - call.signAndSend(alith, (result) => { - console.log(`RESULT =>>> ${result}`); - }) - .catch((error: any) => { - console.log("transaction failed", error); - }); - }); - -}); diff --git a/e2e-tests/tests/test-teleport-laos.ts b/e2e-tests/tests/test-teleport-laos.ts new file mode 100644 index 00000000..96a21d48 --- /dev/null +++ b/e2e-tests/tests/test-teleport-laos.ts @@ -0,0 +1,157 @@ +import BN from "bn.js"; +import { assert, expect } from "chai"; +import { step } from "mocha-steps"; + +import { + ALITH_PRIVATE_KEY, + ASSET_HUB_PARA_ID, + CHAIN_ID, + FAITH, + FAITH_PRIVATE_KEY, + LAOS_PARA_ID, + RUNTIME_IMPL_VERSION, + RUNTIME_SPEC_NAME, + RUNTIME_SPEC_VERSION, +} from "./config"; +import { customRequest, describeWithExistingNode } from "./util"; +import { Keyring } from "@polkadot/api"; +import { withExpect } from '@acala-network/chopsticks-testing' + + +describeWithExistingNode("Asset Hub (Create Foreign Asset)", (context) => { + // See: https://github.com/paritytech/polkadot-sdk/pull/1616 + before("Open HRMP channels between LAOS and AssetHub", async function () { + // TODO wait till channel is not openned + const apiRelaychain = await context.networks.relaychain; + const maxCapacity = 8; + const maxMessageSize = 1048576; + const keyring = new Keyring({ type: "sr25519" }); + const sudo = keyring.addFromUri("//Alice"); + + const laosToAssetHubChannel = await context.networks.relaychain.query.hrmp.hrmpChannels({ + sender: LAOS_PARA_ID, + recipient: ASSET_HUB_PARA_ID, + }); + if (laosToAssetHubChannel.isEmpty) { + const tx = apiRelaychain.tx.hrmp.forceOpenHrmpChannel( + LAOS_PARA_ID, + ASSET_HUB_PARA_ID, + maxCapacity, + maxMessageSize + ); + apiRelaychain.tx.sudo + .sudo(tx) + .signAndSend(sudo, () => {}) + .catch((error: any) => { + console.log("transaction failed", error); + }); + } + + const assetHubToLaosChannel = await context.networks.relaychain.query.hrmp.hrmpChannels({ + sender: ASSET_HUB_PARA_ID, + recipient: LAOS_PARA_ID, + }); + if (assetHubToLaosChannel.isEmpty) { + const tx = apiRelaychain.tx.hrmp.forceOpenHrmpChannel( + ASSET_HUB_PARA_ID, + LAOS_PARA_ID, + maxCapacity, + maxMessageSize + ); + apiRelaychain.tx.sudo + .sudo(tx) + .signAndSend(sudo, () => {}) + .catch((error: any) => { + console.log("transaction failed", error); + }); + } + }); + + step("HRMP channels between Asset Hub and LAOS are open", async function () { + const laosToAssetHubChannel = await context.networks.relaychain.query.hrmp.hrmpChannels({ + sender: LAOS_PARA_ID, + recipient: ASSET_HUB_PARA_ID, + }); + expect(laosToAssetHubChannel.isEmpty).to.be.false; + const assetHubToLaosChannel = await context.networks.relaychain.query.hrmp.hrmpChannels({ + sender: ASSET_HUB_PARA_ID, + recipient: LAOS_PARA_ID, + }); + expect(assetHubToLaosChannel.isEmpty).to.be.false; + }); + + // TODO ? + // step("Create LAOS foreign asset in AssetHub", async function () { + // expect(false).to.be.true; + // }); + + step("Teleport from LAOS to AssetHub", async function () { + const apiLaos = await context.networks.laos; + const apiAssetHub = await context.networks.assetHub; + const faith = new Keyring().addFromUri(FAITH_PRIVATE_KEY); + const alith = new Keyring({ type: "ethereum" }).addFromUri(ALITH_PRIVATE_KEY); + + const destination = apiLaos.createType("XcmVersionedLocation", { + V3: { + parents: "1", + interior: { + X1: { Parachain: ASSET_HUB_PARA_ID }, + }, + }, + }); + + // We need to use AssetHub api otherwise we get an error as LAOS does not use AccountId32 + let accountId = apiAssetHub.createType("AccountId", faith.address); + const beneficiary = apiLaos.createType("XcmVersionedLocation", { + V3: { + parents: "0", + interior: { + X1: { + AccountId32: { + // network: 'Any', + id: accountId.toHex(), + }, + }, + }, + }, + }); + + // 1 LAOS = 10^18, this is .1 LAOS + const amount = 1; // TODO 100000000000000000 + const assets = apiLaos.createType("XcmVersionedAssets", { + V3: [ + { + id: { + Concrete: { + parents: 0, + interior: { + Here: "", + }, + }, + }, + fun: { + Fungible: amount, + }, + }, + ], + }); + // TODO check this in production we should pay + const fee_asset_item = "0"; + const weight_limit = "Unlimited"; + + const call = apiLaos.tx.polkadotXcm.limitedTeleportAssets( + destination, + beneficiary, + assets, + fee_asset_item, + weight_limit + ); + + call.signAndSend(alith, (result) => { + console.log(`RESULT =>>> ${result}`); + }).catch((error: any) => { + console.log("transaction failed", error); + }); + + }); +}); diff --git a/e2e-tests/tests/util.ts b/e2e-tests/tests/util.ts index 824a131d..ddec0a34 100644 --- a/e2e-tests/tests/util.ts +++ b/e2e-tests/tests/util.ts @@ -47,7 +47,7 @@ export async function customRequest(web3: Web3, method: string, params: any[]) { export function describeWithExistingNode( title: string, - cb: (context: { web3: Web3; networks: { laos: ApiPromise, assetHub: ApiPromise, relaychain: ApiPromise } }) => void, + cb: (context: { web3: Web3; networks: { laos: ApiPromise; assetHub: ApiPromise; relaychain: ApiPromise } }) => void, providerLaosNodeUrl?: string, providerAssetHubNodeUrl?: string, providerRelaychainNodeUrl?: string @@ -56,7 +56,7 @@ export function describeWithExistingNode( let context: { web3: Web3; ethersjs: ethers.JsonRpcProvider; - networks: { laos: ApiPromise, assetHub: ApiPromise, relaychain: ApiPromise }; + networks: { laos: ApiPromise; assetHub: ApiPromise; relaychain: ApiPromise }; } = { web3: null, ethersjs: null, diff --git a/zombienet/native.toml b/zombienet/native.toml index 296a2610..6f3a4402 100644 --- a/zombienet/native.toml +++ b/zombienet/native.toml @@ -50,3 +50,16 @@ chain = "asset-hub-rococo-local" ws_port = 9950 command = "{{ZOMBIENET_ASSETHUB_COMMAND}}" args = ["--log=xcm=trace,pallet-assets=trace"] + +# See: https://github.com/paritytech/polkadot-sdk/pull/1616 +# [[hrmp_channels]] +# sender = 2900 +# recipient = 1000 +# max_capacity = 8 +# max_message_size = 1048576 # 512 + +# [[hrmp_channels]] +# sender = 1000 +# recipient = 2900 +# max_capacity = 8 +# max_message_size = 1048576 \ No newline at end of file