Skip to content

Commit

Permalink
test force the creation of hrmp channels
Browse files Browse the repository at this point in the history
  • Loading branch information
magecnion committed Oct 17, 2024
1 parent d22d706 commit 079d94d
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 108 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 0 additions & 105 deletions e2e-tests/tests/test-create-foreign-asset.ts

This file was deleted.

157 changes: 157 additions & 0 deletions e2e-tests/tests/test-teleport-laos.ts
Original file line number Diff line number Diff line change
@@ -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);
});

});
});
4 changes: 2 additions & 2 deletions e2e-tests/tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions zombienet/native.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 079d94d

Please sign in to comment.