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

Integrate Zombienet for XCM development and testing #199

Merged
merged 10 commits into from
Feb 27, 2024
41 changes: 0 additions & 41 deletions src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,47 +107,6 @@ export class Init extends SwankyCommand<typeof Init> {
shibuya: { url: DEFAULT_SHIBUYA_NETWORK_URL },
},
contracts: {},
zombienet: {
version: "1.3.89",
downloadUrl: {
darwin: {
"arm64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-macos",
"x64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-macos"
},
linux: {
"arm64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-linux-arm64",
"x64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-linux-x64",
}
},
binaries: {
"polkadot": {
version: "0.9.43",
downloadUrl: {
darwin: {
"arm64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot",
"x64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot"
},
linux: {
"arm64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot",
"x64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot",
}
},
},
"astar-collator": {
version: "5.28.0",
downloadUrl: {
darwin: {
"arm64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-macOS-x86_64.tar.gz",
"x64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-macOS-x86_64.tar.gz"
},
linux: {
"arm64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-ubuntu-aarch64.tar.gz",
"x64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-ubuntu-x86_64.tar.gz",
}
},
},
},
},
};

taskQueue: Task[] = [];
Expand Down
35 changes: 28 additions & 7 deletions src/commands/zombienet/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import path from "node:path";
import { Flags } from "@oclif/core";
import { SwankyCommand } from "../../lib/swankyCommand.js";
import {
copyZombienetTemplateFile, downloadZombinetBinaries,
copyZombienetTemplateFile, downloadZombienetBinaries,
buildZombienetConfigFromBinaries,
getSwankyConfig,
getTemplates,
Spinner,
} from "../../lib/index.js";
import { pathExistsSync } from "fs-extra/esm";
import { zombienet } from "../../lib/zombienetInfo.js";

export const zombienetConfig = "zombienet.config.toml";
export class InitZombienet extends SwankyCommand<typeof InitZombienet> {
static description = "Initialize Zomnienet";
static description = "Initialize Zombienet";

static flags = {
binaries: Flags.string({
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
char: "b",
multiple: true,
required: true,
required: false,
default: [],
description: "Binaries to install",
}),
}
Expand All @@ -27,18 +29,37 @@ export class InitZombienet extends SwankyCommand<typeof InitZombienet> {
const { flags } = await this.parse(InitZombienet);
await getSwankyConfig();
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved

const spinner = new Spinner(flags.verbose);

const projectPath = path.resolve();
if (pathExistsSync(path.resolve(projectPath, "zombienet", "bin", "zombienet"))) {
this.error("Zombienet config already initialized");
}

const spinner = new Spinner(flags.verbose);

this.swankyConfig.zombienet = {
version: zombienet.version,
downloadUrl: zombienet.downloadUrl,
binaries: {},
};

if(!flags.binaries.includes("polkadot")) {
flags.binaries.push("polkadot");
}

for(const binaryName of flags.binaries){
if(!Object.keys(zombienet.binaries).includes(binaryName)) {
this.error(`Binary ${binaryName} not found in Zombienet config`);
}
this.swankyConfig.zombienet.binaries[binaryName] = zombienet.binaries[binaryName as keyof typeof zombienet.binaries];
}

await this.storeConfig();

const zombienetTemplatePath = getTemplates().zombienetTemplatesPath;

const configPath = path.resolve(projectPath, "zombienet", "config")

if(!flags.binaries || flags.binaries.length < 2) {
if(flags.binaries.length < 2) {
await spinner.runCommand(
() =>
copyZombienetTemplateFile(zombienetTemplatePath, configPath),
Expand All @@ -54,7 +75,7 @@ export class InitZombienet extends SwankyCommand<typeof InitZombienet> {

// Install binaries based on zombie config
await this.spinner.runCommand(
() => downloadZombinetBinaries(projectPath, this.swankyConfig, this.spinner),
() => downloadZombienetBinaries(flags.binaries, projectPath, this.swankyConfig, this.spinner),
"Downloading Zombienet binaries"
);

Expand Down
26 changes: 13 additions & 13 deletions src/commands/zombienet/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import { pathExistsSync } from "fs-extra/esm";
import { execaCommand } from "execa";
import inquirer from "inquirer";
import { readdirSync } from "fs";
import { Flags } from "@oclif/core";


export class StartZombienet extends SwankyCommand<typeof StartZombienet> {
static description = "Start Zomnienet";
static description = "Start Zombienet";

static flags = {
"config-path": Flags.string({
char: "c",
required: false,
default: "./zombienet/config/zombienet.config.toml",
description: "Path to zombienet config",
}),
};

async run(): Promise<void> {
const { flags } = await this.parse(StartZombienet);
const projectPath = path.resolve();
const binPath = path.resolve(projectPath, "zombienet", "bin")
if (!pathExistsSync(path.resolve(binPath, "zombienet"))) {
this.error("Zombienet has not initialized. Run `swanky zombienet:init` first");
}

const zombienetConfigPath = path.resolve("zombienet", "config");

const configList = readdirSync(zombienetConfigPath);

const zombienetConfig = (await inquirer.prompt([{
name: "zombienetConfig",
type: "list",
choices: configList,
message: "Select a zombienet config to use",
}])).zombienetConfig;

await execaCommand(
`./zombienet/bin/zombienet \
spawn --provider native \
./zombienet/config/${zombienetConfig}
${flags["config-path"]}
`,
{
stdio: "inherit",
Expand Down
8 changes: 6 additions & 2 deletions src/lib/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ export async function copyZombienetTemplateFile(templatePath: string, configPath
path.resolve(configPath, zombienetConfig)
);
}
export async function downloadZombinetBinaries(projectPath: string, swankyConfig: SwankyConfig, spinner: Spinner) {
export async function downloadZombienetBinaries(binaries: string[], projectPath: string, swankyConfig: SwankyConfig, spinner: Spinner) {
const binPath = path.resolve(projectPath, "zombienet", "bin");
await ensureDir(binPath);

const zombienetInfo = swankyConfig.zombienet;

if (!zombienetInfo) {
throw new ConfigError("No zombienet config found");
}

const dlUrls = new Map<string, string>();
if (zombienetInfo.version) {
const version = zombienetInfo.version;
Expand All @@ -159,7 +163,7 @@ export async function downloadZombinetBinaries(projectPath: string, swankyConfig
dlUrls.set(binaryName, dlUrl);
}

for(const binaryName of Object.keys(zombienetInfo.binaries)){
for(const binaryName of Object.keys(zombienetInfo.binaries).filter((binaryName) => binaries.includes(binaryName))){
const binaryInfo = zombienetInfo.binaries[binaryName as BinaryNames];
const version = binaryInfo.version;
const platformDlUrls = binaryInfo.downloadUrl[process.platform as SupportedPlatforms];
Expand Down
74 changes: 37 additions & 37 deletions src/lib/zombienetInfo.ts
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
export type zombienetInfo = typeof zombienetBins;
export type zombienetInfo = typeof zombienet;

export type BinaryNames = "zombienet" | "polkadot" | "astar-collator";
export const zombienetBins = {
"zombienet": {
version: "1.3.89",
downloadUrl: {
darwin: {
"arm64": "https://github.com/paritytech/zombienet/releases/download/v1.3.89/zombienet-macos",
"x64": "https://github.com/paritytech/zombienet/releases/download/v1.3.89/zombienet-macos"
},
linux: {
"arm64": "https://github.com/paritytech/zombienet/releases/download/v1.3.89/zombienet-linux-arm64",
"x64": "https://github.com/paritytech/zombienet/releases/download/v1.3.89/zombienet-linux-x64",
}
export const zombienet= {
version: "1.3.89",
downloadUrl: {
darwin: {
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
"arm64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-macos",
"x64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-macos"
},
},
"polkadot": {
version: "0.9.43",
downloadUrl: {
darwin: {
"arm64": "https://github.com/paritytech/polkadot/releases/download/v0.9.43/polkadot",
"x64": "https://github.com/paritytech/polkadot/releases/download/v0.9.43/polkadot",
},
linux: {
"arm64": "https://github.com/paritytech/polkadot/releases/download/v0.9.43/polkadot",
"x64": "https://github.com/paritytech/polkadot/releases/download/v0.9.43/polkadot",
}
linux: {
"arm64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-linux-arm64",
"x64": "https://github.com/paritytech/zombienet/releases/download/v${version}/zombienet-linux-x64",
}
},
"astar-collator": {
version: "5.28.0",
downloadUrl: {
darwin: {
"arm64": "https://github.com/AstarNetwork/Astar/releases/download/v5.28.0/astar-collator-v5.28.0-macOS-x86_64.tar.gz",
"x64": "https://github.com/AstarNetwork/Astar/releases/download/v5.28.0/astar-collator-v5.28.0-macOS-x86_64.tar.gz",
binaries: {
"polkadot": {
version: "0.9.43",
downloadUrl: {
darwin: {
"arm64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot",
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
"x64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot"
},
linux: {
"arm64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot",
"x64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot",
}
},
linux: {
"arm64": "https://github.com/AstarNetwork/Astar/releases/download/v5.28.0/astar-collator-v5.28.0-ubuntu-aarch64.tar.gz",
"x64": "https://github.com/AstarNetwork/Astar/releases/download/v5.28.0/astar-collator-v5.28.0-ubuntu-x86_64.tar.gz",
}
}
}
},
"astar-collator": {
version: "5.28.0",
downloadUrl: {
darwin: {
"arm64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-macOS-x86_64.tar.gz",
"x64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-macOS-x86_64.tar.gz"
},
linux: {
"arm64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-ubuntu-aarch64.tar.gz",
"x64": "https://github.com/AstarNetwork/Astar/releases/download/v${version}/astar-collator-v${version}-ubuntu-x86_64.tar.gz",
}
},
},
},
};
69 changes: 0 additions & 69 deletions src/templates/zombienet/zombienet.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,72 +14,3 @@ chain = "rococo-local"
[[relaychain.nodes]]
name = "relay03"

[[parachains]]
id = 2006
chain = "astar-dev"
cumulus_based = true

[parachains.collator]
name = "astar"
command = "./zombienet/bin/astar-collator"
rpc_port = 8545
args = [ "-l=xcm=trace", "--enable-evm-rpc" ]

[[parachains]]
id = 2007
chain = "shiden-dev"
cumulus_based = true

[parachains.collator]
name = "shiden"
command = "./zombienet/bin/astar-collator"
rpc_port = 8546
args = [ "-l=xcm=trace", "--enable-evm-rpc" ]

[[parachains]]
id = 2008
chain = "shibuya-dev"
cumulus_based = true

[parachains.collator]
name = "shibuya"
command = "./zombienet/bin/astar-collator"
rpc_port = 8546
args = [ "-l=xcm=trace", "--enable-evm-rpc" ]

[[hrmp_channels]]
sender = 2006
recipient = 2007
max_capacity = 8
max_message_size = 512

[[hrmp_channels]]
sender = 2007
recipient = 2006
max_capacity = 8
max_message_size = 512

[[hrmp_channels]]
sender = 2006
recipient = 2008
max_capacity = 8
max_message_size = 512

[[hrmp_channels]]
sender = 2008
recipient = 2006
max_capacity = 8
max_message_size = 512


[[hrmp_channels]]
sender = 2008
recipient = 2007
max_capacity = 8
max_message_size = 512

[[hrmp_channels]]
sender = 2007
recipient = 2008
max_capacity = 8
max_message_size = 512
14 changes: 8 additions & 6 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface DeploymentData {
address: string;
}

export interface downloadUrl {
export interface DownloadUrl {
darwin: {
"arm64": string,
"x64": string
Expand All @@ -58,11 +58,13 @@ export interface SwankyConfig {
accounts: AccountData[];
contracts: Record<string, ContractData> | Record<string, never>;
networks: Record<string, {url: string}>
zombienet: {
version: string,
downloadUrl : downloadUrl,
binaries: Record<string, {version: string, downloadUrl: downloadUrl}>
}
zombienet?: ZombienetData;
}

interface ZombienetData {
version: string;
downloadUrl: DownloadUrl;
binaries: Record<string, { version: string; downloadUrl: DownloadUrl }>;
}

export interface ZombienetConfig {
Expand Down