diff --git a/scripts/testNetworkForeignAssets.ts b/scripts/testNetworkForeignAssets.ts index d8789c64..79667e1e 100644 --- a/scripts/testNetworkForeignAssets.ts +++ b/scripts/testNetworkForeignAssets.ts @@ -5,8 +5,8 @@ import { Keyring } from '@polkadot/keyring'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import chalk from 'chalk'; -import { KUSAMA_ASSET_HUB_WS_URL, TRAPPIST_WS_URL } from './consts'; -import { awaitBlockProduction, delay, logWithDate } from './util'; +import { KUSAMA_ASSET_HUB_WS_URL, ROCOCO_ALICE_WS_URL, TRAPPIST_WS_URL } from './consts'; +import { awaitBlockProduction, awaitEpochChange, delay, logWithDate } from './util'; const fAssetSetMetadataCall = (assetHubApi: ApiPromise): `0x${string}` => { const trappistMultiLocation = { @@ -58,7 +58,7 @@ const fAssetCreateCall = (assetHubApi: ApiPromise): `0x${string}` => { const sudoCallWrapper = (trappistApi: ApiPromise, call: `0x${string}`) => { // Double encode the call - const xcmDoubleEncoded = trappistApi.createType('XcmDoubleEncoded', { + const xcmDoubleEncoded = trappistApi.createType('StagingXcmDoubleEncoded', { encoded: call, }); @@ -159,6 +159,10 @@ const setMetadataForeignAssetViaSudo = (assetHubApi: ApiPromise, trappistApi: Ap return sudoCallWrapper(trappistApi, setMetadataCall); }; +const openHrmpChannels = (api: ApiPromise, sender: number, receiver: number) => { + return api.tx.hrmp.forceOpenHrmpChannel(sender, receiver, Number(8), Number(512)); +}; + const main = async () => { logWithDate(chalk.yellow('Initializing script to create foreignAssets on chain')); await cryptoWaitReady(); @@ -183,6 +187,27 @@ const main = async () => { await trappistApi.isReady; logWithDate(chalk.green('Created a connection to Trappist')); + const relayApi = await ApiPromise.create({ + provider: new WsProvider(ROCOCO_ALICE_WS_URL), + noInitWarn: true, + }); + + await relayApi.isReady; + + logWithDate(chalk.green('Created a connection to Rococo')); + + logWithDate(chalk.blue('Opening HRMP Channels')); + + const hrmpChannelCalls = []; + + hrmpChannelCalls.push(openHrmpChannels(relayApi, Number(1000), Number(1836))); + hrmpChannelCalls.push(openHrmpChannels(relayApi, Number(1836), Number(1000))); + + await relayApi.tx.sudo.sudo(relayApi.tx.utility.batchAll(hrmpChannelCalls)).signAndSend(alice); + + await awaitEpochChange(relayApi); + logWithDate(chalk.magenta('HRMP channels open')); + logWithDate(chalk.magenta('Sending funds to Trappist Sibling on Kusama AssetHub')); await kusamaAssetHubApi.tx.balances diff --git a/scripts/testNetworkLiquidAssets.ts b/scripts/testNetworkLiquidAssets.ts index 05d54ee4..bab1f2ff 100644 --- a/scripts/testNetworkLiquidAssets.ts +++ b/scripts/testNetworkLiquidAssets.ts @@ -6,8 +6,8 @@ import { KeyringPair } from '@polkadot/keyring/types'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import chalk from 'chalk'; -import { KUSAMA_ASSET_HUB_WS_URL } from './consts'; -import { awaitBlockProduction, delay, logWithDate } from './util'; +import { KUSAMA_ASSET_HUB_WS_URL, ROCOCO_ALICE_WS_URL } from './consts'; +import { awaitBlockProduction, awaitEpochChange, delay, logWithDate } from './util'; const ASSET_ID = 1; const ASSET_NAME = 'Testy'; @@ -57,6 +57,10 @@ const transferLPTokensCall = (api: ApiPromise, token: number, amount: number, to return api.tx.poolAssets.transferKeepAlive(token, to.address, amount); }; +const openHrmpChannels = (api: ApiPromise, sender: number, receiver: number) => { + return api.tx.hrmp.forceOpenHrmpChannel(sender, receiver, Number(8), Number(512)); +}; + const main = async () => { logWithDate(chalk.yellow('Initializing script to create a liquidity pool on Kusama Asset Hub')); await cryptoWaitReady(); @@ -65,6 +69,25 @@ const main = async () => { const alice = keyring.addFromUri('//Alice'); const bob = keyring.addFromUri('//Bob'); + const relayApi = await ApiPromise.create({ + provider: new WsProvider(ROCOCO_ALICE_WS_URL), + noInitWarn: true, + }); + + await relayApi.isReady; + + logWithDate(chalk.blue('Opening HRMP Channels')); + + const hrmpChannelCalls = []; + + hrmpChannelCalls.push(openHrmpChannels(relayApi, Number(1000), Number(1836))); + hrmpChannelCalls.push(openHrmpChannels(relayApi, Number(1836), Number(1000))); + + await relayApi.tx.sudo.sudo(relayApi.tx.utility.batchAll(hrmpChannelCalls)).signAndSend(alice); + + await awaitEpochChange(relayApi); + logWithDate(chalk.magenta('HRMP channels open')); + const api = await ApiPromise.create({ provider: new WsProvider(KUSAMA_ASSET_HUB_WS_URL), noInitWarn: true, @@ -87,7 +110,7 @@ const main = async () => { txs.push(createPool); txs.push(addLiquidity); - await api.tx.utility.batch(txs).signAndSend(alice); + await api.tx.utility.batch(txs).signAndSend(alice, { nonce: -1 }); await delay(24000); @@ -122,7 +145,7 @@ const main = async () => { logWithDate(chalk.magenta('Sending 1,000,000,000,000 lpTokens from Alice to Bob on Kusama Asset Hub')); - await transferLPTokensCall(api, 0, 1000000000000, bob).signAndSend(alice); + await transferLPTokensCall(api, 0, 1000000000000, bob).signAndSend(alice, { nonce: -1 }); await delay(24000); diff --git a/scripts/util.ts b/scripts/util.ts index 0d3e3ad6..bbb0a980 100644 --- a/scripts/util.ts +++ b/scripts/util.ts @@ -57,3 +57,25 @@ export const awaitBlockProduction = async (wsUrl: string) => { logWithDate(chalk.blue('Polkadot-js successfully disconnected')); }); }; + +export const awaitEpochChange = async (api: ApiPromise) => { + const currentEpoch = await api.call.babeApi.currentEpoch(); + const currentEpochIndex = currentEpoch.epochIndex; + let counter = 1; + let changedEpoch = false; + while (!changedEpoch) { + const { epochIndex } = await api.call.babeApi.currentEpoch(); + + if (epochIndex.toNumber() > currentEpochIndex.toNumber() + 1) { + changedEpoch = true; + } + await delay(1000); + + counter += 1; + process.stdout.clearLine(0); + process.stdout.write(`\rWaiting for Epoch change${'.'.repeat((counter % 3) + 1)}`); + } + + process.stdout.clearLine(0); + logWithDate(chalk.magenta('Epoch changed'), true); +}; diff --git a/zombienet/medium-network.toml b/zombienet/medium-network.toml index fe7552d2..c5cdc83f 100644 --- a/zombienet/medium-network.toml +++ b/zombienet/medium-network.toml @@ -64,15 +64,3 @@ chain = "trappist-local" number = "u64" parent_hash = "Hash" post_state = "Hash" - -[[hrmp_channels]] -sender = 1000 -recipient = 1836 -max_capacity = 8 -max_message_size = 512 - -[[hrmp_channels]] -sender = 1836 -recipient = 1000 -max_capacity = 8 -max_message_size = 512