-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integrate Zombienet for XCM development and testing (#66)
Co-authored-by: Igor Papandinas <igor.papandinas@posteo.net>
- Loading branch information
1 parent
e315716
commit f6e32e5
Showing
13 changed files
with
534 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import path from "node:path"; | ||
import { Flags } from "@oclif/core"; | ||
import { SwankyCommand } from "../../lib/swankyCommand.js"; | ||
import { | ||
buildZombienetConfigFromBinaries, | ||
copyZombienetTemplateFile, | ||
downloadZombienetBinaries, | ||
getSwankyConfig, | ||
getTemplates, | ||
osCheck, | ||
Spinner, | ||
} from "../../lib/index.js"; | ||
import { pathExistsSync } from "fs-extra/esm"; | ||
import { zombienet, zombienetBinariesList } from "../../lib/zombienetInfo.js"; | ||
import { ConfigBuilder } from "../../lib/config-builder.js"; | ||
import { SwankyConfig, ZombienetData } from "../../index.js"; | ||
|
||
export const zombienetConfig = "zombienet.config.toml"; | ||
|
||
export class InitZombienet extends SwankyCommand<typeof InitZombienet> { | ||
static description = "Initialize Zombienet"; | ||
|
||
static flags = { | ||
binaries: Flags.string({ | ||
char: "b", | ||
multiple: true, | ||
required: false, | ||
options: zombienetBinariesList, | ||
default: [], | ||
description: "Binaries to install", | ||
}), | ||
}; | ||
|
||
async run(): Promise<void> { | ||
const { flags } = await this.parse(InitZombienet); | ||
|
||
const localConfig = getSwankyConfig("local") as SwankyConfig; | ||
|
||
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); | ||
|
||
const zombienetData: ZombienetData = { | ||
version: zombienet.version, | ||
downloadUrl: zombienet.downloadUrl, | ||
binaries: {}, | ||
}; | ||
|
||
if (!flags.binaries.includes("polkadot")) { | ||
flags.binaries.push("polkadot"); | ||
} | ||
|
||
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`); | ||
} | ||
zombienetData.binaries[binaryName] = zombienet.binaries[binaryName as keyof typeof zombienet.binaries]; | ||
} | ||
|
||
await this.spinner.runCommand(async () => { | ||
const newLocalConfig = new ConfigBuilder(localConfig) | ||
.addZombienet(zombienetData) | ||
.build(); | ||
await this.storeConfig(newLocalConfig, "local"); | ||
}, "Writing config"); | ||
|
||
const zombienetTemplatePath = getTemplates().zombienetTemplatesPath; | ||
|
||
const configPath = path.resolve(projectPath, "zombienet", "config"); | ||
|
||
if (flags.binaries.length === 1 && flags.binaries[0] === "polkadot") { | ||
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, localConfig, this.spinner), | ||
"Downloading Zombienet binaries", | ||
); | ||
|
||
this.log("ZombieNet config Installed successfully"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { SwankyCommand } from "../../lib/swankyCommand.js"; | ||
import path from "node:path"; | ||
import { pathExistsSync } from "fs-extra/esm"; | ||
import { execaCommand } from "execa"; | ||
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.