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
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"ora": "6.3.1",
"semver": "7.5.4",
"shelljs": "0.8.5",
"toml": "^3.0.0",
"ts-mocha": "^10.0.0",
"winston": "^3.10.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class Init extends SwankyCommand<typeof Init> {
callback(result as string);
}
}
this.log("🎉 😎 Swanky project successfully initialised! 😎 🎉");
this.log("🎉 😎 Swanky project successfully initialized! 😎 🎉");
}

async generate(projectName: string) {
Expand Down
95 changes: 95 additions & 0 deletions src/commands/zombienet/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import path from "node:path";
import { Flags } from "@oclif/core";
import { SwankyCommand } from "../../lib/swankyCommand.js";
import {
buildZombienetConfigFromBinaries,
copyZombienetTemplateFile,
downloadZombienetBinaries,
getTemplates,
osCheck,
Spinner,
} from "../../lib/index.js";
import { pathExistsSync } from "fs-extra/esm";
import { zombienet, zombienetBinariesList } from "../../lib/zombienetInfo.js";

export const zombienetConfig = "zombienet.config.toml";

export class InitZombienet extends SwankyCommand<typeof InitZombienet> {
static description = "Initialize Zombienet";

static flags = {
binaries: Flags.string({
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
char: "b",
multiple: true,
required: false,
options: zombienetBinariesList,
default: [],
description: "Binaries to install",
}),
};

async run(): Promise<void> {
const { flags } = await this.parse(InitZombienet);

const platform = osCheck().platform;
if (platform === "darwin") {
this.warn(`Note for MacOs users: Polkadot binary is not currently supported for MacOs.
As a result users of MacOS need to clone the Polkadot repo (https://github.com/paritytech/polkadot), create a release and add it in your PATH manually (setup will advice you so as well). Check the official zombienet documentation for manual settings: https://paritytech.github.io/zombienet/.`);
}

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");
}
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved

for (const binaryName of flags.binaries) {
if (platform === "darwin" && binaryName.startsWith("polkadot")) {
continue;
}
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.length < 2) {
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
await spinner.runCommand(
() =>
copyZombienetTemplateFile(zombienetTemplatePath, configPath),
"Copying template files",
);
} else {
await spinner.runCommand(
() => buildZombienetConfigFromBinaries(flags.binaries, zombienetTemplatePath, configPath),
"Copying template files",
);
}

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

this.log("ZombieNet config Installed successfully");
}
}

42 changes: 42 additions & 0 deletions src/commands/zombienet/start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { SwankyCommand } from "../../lib/swankyCommand.js";
import path from "node:path";
import { pathExistsSync } from "fs-extra/esm";
import { execaCommand } from "execa";
import inquirer from "inquirer";

Check failure on line 5 in src/commands/zombienet/start.ts

View workflow job for this annotation

GitHub Actions / lint-check

'inquirer' is defined but never used
import { readdirSync } from "fs";

Check failure on line 6 in src/commands/zombienet/start.ts

View workflow job for this annotation

GitHub Actions / lint-check

'readdirSync' is defined but never used
import { Flags } from "@oclif/core";


export class StartZombienet extends SwankyCommand<typeof StartZombienet> {
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");
}

await execaCommand(
`./zombienet/bin/zombienet \
spawn --provider native \
${flags["config-path"]}
`,
{
stdio: "inherit",
}
);

this.log("ZombieNet started successfully");
}
}
Loading
Loading