Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updated zombienet to work with polkadot-sdk nodes #319

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions scripts/testNetworkForeignAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
31 changes: 27 additions & 4 deletions scripts/testNetworkLiquidAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,25 @@ export const awaitBlockProduction = async (wsUrl: string) => {
logWithDate(chalk.blue('Polkadot-js successfully disconnected'));
});
};

export const awaitEpochChange = async (api: ApiPromise) => {
marshacb marked this conversation as resolved.
Show resolved Hide resolved
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);
};
12 changes: 0 additions & 12 deletions zombienet/medium-network.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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