From 769ca7f451736818d863f4b5f2269c27c7d70cd0 Mon Sep 17 00:00:00 2001 From: prxgr4mm3r Date: Sat, 6 Jan 2024 20:07:32 +0200 Subject: [PATCH 1/9] Add zombienet --- src/commands/zombienet/addProvider.ts | 55 +++++++++ src/commands/zombienet/init.ts | 114 ++++++++++++++++++ src/commands/zombienet/start.ts | 47 ++++++++ .../zombienet/k8s/zombienet.config.toml | 1 + .../zombienet/native/zombienet.config.toml | 49 ++++++++ 5 files changed, 266 insertions(+) create mode 100644 src/commands/zombienet/addProvider.ts create mode 100644 src/commands/zombienet/init.ts create mode 100644 src/commands/zombienet/start.ts create mode 100644 src/templates/zombienet/k8s/zombienet.config.toml create mode 100644 src/templates/zombienet/native/zombienet.config.toml diff --git a/src/commands/zombienet/addProvider.ts b/src/commands/zombienet/addProvider.ts new file mode 100644 index 00000000..a308f05b --- /dev/null +++ b/src/commands/zombienet/addProvider.ts @@ -0,0 +1,55 @@ +import { SwankyCommand } from "../../lib/swankyCommand.js"; +import { Flags } from "@oclif/core"; +import path from "node:path"; +import { existsSync } from "fs-extra"; +import { Spinner } from "../../lib/index.js"; +import inquirer from "inquirer"; +import { copyTemplateFile, providerChoices, templatePath, zombienetConfig } from "./init.js"; + + +export class AddZombienetProvider extends SwankyCommand{ + static description = "Add Zomnienet provider config"; + + static flags = { + verbose: Flags.boolean({ char: "v", description: "Verbose output" }), + provider: Flags.string({ char: "p", description: "Provider to use" }), + }; + + async run(): Promise { + const { flags } = await this.parse(AddZombienetProvider); + + const projectPath = path.resolve(); + const binPath = path.resolve(projectPath, "zombienet", "bin") + if (!existsSync(path.resolve(binPath, "zombienet"))) { + this.error("Zombienet has not initialized. Run `swanky zombienet:init` first"); + } + + const spinner = new Spinner(flags.verbose); + + let provider = flags.provider; + if (provider === undefined) { + const answer = await inquirer.prompt([{ + name: "provider", + type: "list", + choices: providerChoices, + message: "Select a provider to use", + }]) + provider = answer.provider; + } + + const configPath = path.resolve(projectPath, "zombienet", "config") + + if (existsSync(path.resolve(configPath, provider!, zombienetConfig))) { + this.error(`Zombienet config for ${provider!} provider already exists`); + } + + // Copy templates + await spinner.runCommand( + () => + copyTemplateFile(path.resolve(templatePath, provider!), path.resolve(configPath, provider!)), + "Copying template files" + ); + + this.log("ZombieNet provider config added successfully"); + } +} diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts new file mode 100644 index 00000000..499e210d --- /dev/null +++ b/src/commands/zombienet/init.ts @@ -0,0 +1,114 @@ +import path from "node:path"; +import { Flags } from "@oclif/core"; +import { SwankyCommand } from "../../lib/swankyCommand.js"; +import { getSwankyConfig, Spinner } from "../../lib/index.js"; +import { existsSync } from "fs-extra"; +import inquirer from "inquirer"; +import { copy, ensureDir } from "fs-extra/esm"; +import { DownloadEndedStats, DownloaderHelper } from "node-downloader-helper"; +import { execaCommand } from "execa"; + + +export const zombienetConfig = "zombienet.config.toml"; +export const templatePath = path.resolve(__dirname, "../../templates"); + +export const providerChoices = ["native", "k8s"]; + +export class InitZombienet extends SwankyCommand { + static description = "Initialize Zomnienet"; + + static flags = { + verbose: Flags.boolean({ char: "v", description: "Verbose output" }), + provider: Flags.string({ char: "p", description: "Provider to use" }), + }; + + async run(): Promise { + const { flags } = await this.parse(InitZombienet); + await getSwankyConfig(); + + const spinner = new Spinner(flags.verbose); + + const projectPath = path.resolve(); + if (existsSync(path.resolve(projectPath, "zombienet", "bin", "zombienet"))) { + this.error("Zombienet config already initialized"); + } + + let provider = flags.provider; + if (provider === undefined) { + const answer = await inquirer.prompt([{ + name: "provider", + type: "list", + choices: providerChoices, + message: "Select a provider to use", + }]) + provider = answer.provider; + } + + const configPath = path.resolve(projectPath, "zombienet", "config") + // Copy templates + await spinner.runCommand( + () => + copyTemplateFile(path.resolve(templatePath, provider!), path.resolve(configPath, provider!)), + "Copying template files" + ); + + // Install binaries based on zombie config + await spinner.runCommand( + async () => new Promise(async (resolve, reject) => { + const binPath = path.resolve(projectPath, "zombienet", "bin"); + await ensureDir(binPath); + const platform = process.platform.toString(); + const dlUrl = zombieNetBinInfo.downloadUrl[platform]; + if (!dlUrl) + reject(`Could not download Zombienet. Platform ${process.platform} not supported!`); + + const dlFileDetails = await new Promise((resolve, reject) => { + const dl = new DownloaderHelper(dlUrl, binPath); + + dl.on("progress", (event) => { + spinner.text(`Downloading Zombienet binary ${event.progress.toFixed(2)}%`); + }); + dl.on("end", (event) => { + resolve(event); + }); + dl.on("error", (error) => { + reject(new Error(`Error downloading Zombienet binary: , ${error.message}`)); + }); + + dl.start().catch((error) => reject(new Error(`Error downloading Zombienet: , ${error.message}`))); + }); + + if (dlFileDetails.incomplete) { + reject("Zombienet binary download incomplete"); + } + + await execaCommand(`mv ${binPath}/${dlFileDetails.fileName} ${binPath}/zombienet`) + await execaCommand(`chmod +x ${binPath}/zombienet`); + resolve(); + }), + "Download Zombienet binary", + ); + + this.log("ZombieNet config Installed successfully"); + } +} + +export async function copyTemplateFile(templatePath: string, projectPath: string) { + await ensureDir(projectPath); + await copy( + path.resolve(templatePath, zombienetConfig), + path.resolve(projectPath, zombienetConfig) + ); +} + +type downloadUrl = Record; + +const zombieNetBinInfo = { + version: "v1.3.42", + downloadUrl: { + darwin: + "https://github.com/paritytech/zombienet/releases/download/v1.3.42/zombienet-macos", + linux: + "https://github.com/paritytech/zombienet/releases/download/v1.3.42/zombienet-linux-x64", + } as downloadUrl, +}; diff --git a/src/commands/zombienet/start.ts b/src/commands/zombienet/start.ts new file mode 100644 index 00000000..e17f0b93 --- /dev/null +++ b/src/commands/zombienet/start.ts @@ -0,0 +1,47 @@ +import { SwankyCommand } from "../../lib/swankyCommand.js"; +import { Flags } from "@oclif/core"; +import path from "node:path"; +import { existsSync } from "fs-extra"; +import { Spinner } from "../../lib/index.js"; +import { zombienetConfig } from "./init.js"; +import { execaCommand } from "execa"; + + +export class StartZombienet extends SwankyCommand { + static description = "Start Zomnienet"; + + static flags = { + verbose: Flags.boolean({ char: "v", description: "Verbose output" }), + provider: Flags.string({ char: "p", description: "Provider to use", default: "native" }), + }; + + async run(): Promise { + const { flags } = await this.parse(StartZombienet); + + const projectPath = path.resolve(); + const binPath = path.resolve(projectPath, "zombienet", "bin") + if (!existsSync(path.resolve(binPath, "zombienet"))) { + this.error("Zombienet has not initialized. Run `swanky zombienet:init` first"); + } + + const spinner = new Spinner(flags.verbose); + + const configFilePath = path.resolve(projectPath, "zombienet", "config", flags.provider, zombienetConfig); + + if (!existsSync(configFilePath)) { + this.error(`Zombienet config for ${flags.provider} does not exist. Add provider config first.`); + } + + await execaCommand( + `./zombienet/bin/zombienet \ + spawn --provider ${flags.provider} \ + ./zombienet/config/${flags.provider}/zombienet.config.toml + `, + { + stdio: "inherit", + } + ); + + this.log("ZombieNet started successfully"); + } +} \ No newline at end of file diff --git a/src/templates/zombienet/k8s/zombienet.config.toml b/src/templates/zombienet/k8s/zombienet.config.toml new file mode 100644 index 00000000..bdda138f --- /dev/null +++ b/src/templates/zombienet/k8s/zombienet.config.toml @@ -0,0 +1 @@ +# TODO add k8s provider template \ No newline at end of file diff --git a/src/templates/zombienet/native/zombienet.config.toml b/src/templates/zombienet/native/zombienet.config.toml new file mode 100644 index 00000000..65b16b69 --- /dev/null +++ b/src/templates/zombienet/native/zombienet.config.toml @@ -0,0 +1,49 @@ +[settings] +timeout = 1000 + +[relaychain] +default_command = "./zombienet/bin/polkadot" +chain = "rococo-local" + + [[relaychain.nodes]] + name = "relay01" + + [[relaychain.nodes]] + name = "relay02" + + [[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" ] + +[[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 From baa55a3e393f9085e3839149146c946124f8b86b Mon Sep 17 00:00:00 2001 From: prxgr4mm3r Date: Wed, 10 Jan 2024 15:19:17 +0200 Subject: [PATCH 2/9] Add zombienet config constructor --- package.json | 1 + src/commands/zombienet/addProvider.ts | 20 +-- src/commands/zombienet/buildConfig.ts | 205 ++++++++++++++++++++++++++ src/commands/zombienet/init.ts | 77 +++------- src/commands/zombienet/start.ts | 26 ++-- src/lib/tasks.ts | 58 ++++++++ src/lib/templates.ts | 2 + src/lib/zombienetInfo.ts | 44 ++++++ 8 files changed, 359 insertions(+), 74 deletions(-) create mode 100644 src/commands/zombienet/buildConfig.ts create mode 100644 src/lib/zombienetInfo.ts diff --git a/package.json b/package.json index 02caec52..202efaf4 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/commands/zombienet/addProvider.ts b/src/commands/zombienet/addProvider.ts index a308f05b..99708f73 100644 --- a/src/commands/zombienet/addProvider.ts +++ b/src/commands/zombienet/addProvider.ts @@ -1,17 +1,16 @@ import { SwankyCommand } from "../../lib/swankyCommand.js"; import { Flags } from "@oclif/core"; import path from "node:path"; -import { existsSync } from "fs-extra"; -import { Spinner } from "../../lib/index.js"; +import { pathExistsSync } from "fs-extra/esm"; +import { getTemplates, Spinner } from "../../lib/index.js"; import inquirer from "inquirer"; -import { copyTemplateFile, providerChoices, templatePath, zombienetConfig } from "./init.js"; +import { copyTemplateFile, providerChoices, zombienetConfig } from "./init.js"; export class AddZombienetProvider extends SwankyCommand{ - static description = "Add Zomnienet provider config"; + static description = "Add Zombienet provider config"; static flags = { - verbose: Flags.boolean({ char: "v", description: "Verbose output" }), provider: Flags.string({ char: "p", description: "Provider to use" }), }; @@ -20,10 +19,13 @@ export class AddZombienetProvider extends SwankyCommand - copyTemplateFile(path.resolve(templatePath, provider!), path.resolve(configPath, provider!)), + copyTemplateFile(path.resolve(zombienetTemplatePath, provider!), path.resolve(configPath, provider!)), "Copying template files" ); - this.log("ZombieNet provider config added successfully"); + this.log("Zombienet provider config added successfully"); } } diff --git a/src/commands/zombienet/buildConfig.ts b/src/commands/zombienet/buildConfig.ts new file mode 100644 index 00000000..69bc1e84 --- /dev/null +++ b/src/commands/zombienet/buildConfig.ts @@ -0,0 +1,205 @@ +import { SwankyCommand } from "../../lib/swankyCommand.js"; +import { Flags } from "@oclif/core"; +import path from "node:path"; +import TOML from "@iarna/toml"; +import inquirer from "inquirer"; +import { writeFileSync } from "node:fs"; + + +export class BuildConfig extends SwankyCommand{ + static description = "Build Zombienet provider config"; + + static flags = { + provider: Flags.string({ char: "p", default:"native", description: "Provider to use" }), + }; + + async run(): Promise { + const { flags } = await this.parse(BuildConfig); + + const projectPath = path.resolve(); + + const configPath = path.resolve(projectPath, "zombienet", "config", flags.provider) + + // const parsedConfig = TOML.parse(readFileSync(path.resolve(configPath, zombienetConfig), "utf-8")); + // + // console.log("Parsed config:\n", parsedConfig, '\n'); + + const configBuilder = { + settings: { + timeout: 1000 + }, + relaychain:{ + default_command: "", + chain: "", + nodes: [] + }, + parachains:[], + hrmp_channels:[] + } as ZombienetConfig; + + const relaychainName = (await inquirer.prompt([{ + name: "relaychainName", + type: "list", + choices: ["rococo-local"], + message: "Select a relaychain to use", + }])).relaychainName; + + configBuilder.relaychain = relaychains[relaychainName as AvailableParachains]; + + const nodesAmount = (await inquirer.prompt([{ + name: "nodesAmount", + type: "number", + message: "How many nodes do you want to run?", + }])).nodesAmount; + + const nodes : Node[] = []; + for (let i = 0; i < nodesAmount; i++) { + nodes.push({name: `relay${ + "0".repeat(nodesAmount.toString().length - i.toString().length)+i}` + }); + } + configBuilder.relaychain.nodes = nodes; + + const parachainsAmount = (await inquirer.prompt([{ + name: "parachainsAmount", + type: "number", + message: "How many parachains do you want to run?", + }])).parachainsAmount; + + const parachains : Parachain[] = []; + for(let i = 0; i < parachainsAmount; i++) { + const parachainId = 2000 + i; + + const collatorRpcPort = 8545 + i; + + const collatorType = (await inquirer.prompt([{ + name: "collatorType", + type: "list", + choices: ["astar-collator"], + message: `Select collator type for parachain ${i}`, + }])).collatorType; + + const collator = collators[collatorType as AvailableCollators]; + + const parachainName = (await inquirer.prompt([{ + name: "parachainName", + type: "list", + choices: parachins[collatorType as AvailableCollators], + message: `Chose parachain name for parachain ${i}`, + }])).parachainName; + + collator.name = parachainName + "-collator"; + collator.rpc_port = collatorRpcPort; + + const parachain = { + id: parachainId, + chain: parachainName, + cumulus_based: true, + collator: collator + } as Parachain; + + parachains.push(parachain); + } + configBuilder.parachains = parachains; + + + const hrmp_channels : HrmpChannel[] = []; + + const hrmpChannelsAmount = (await inquirer.prompt([{ + name: "hrmpChannelsAmount", + type: "number", + message: `How many hrmp channels do you want to run?(Max: ${parachainsAmount * (parachainsAmount - 1)})`, + }])).hrmpChannelsAmount; + + if(hrmpChannelsAmount > parachainsAmount * (parachainsAmount - 1)) { + this.error("Maximum hrmp channels amount exceeded"); + } + + const channelChoices = []; + for(let j = 0; j < parachainsAmount; j++) { + for(let k = 0; k < parachainsAmount; k++) { + if(j != k) { + channelChoices.push({value: {sender: parachains[j].id, recipient: parachains[k].id}, name: `${parachains[j].chain} -> ${parachains[k].chain}`}); + } + } + } + + for(let i = 0; i < hrmpChannelsAmount; i++) { + const senderRecipient = (await inquirer.prompt([{ + name: "senderRecipient", + type: "list", + choices: channelChoices, + message: `Select sender and recipient for hrmp channel ${i}`, + }])).senderRecipient; + + + const hrmpChannel = { + sender: senderRecipient.sender, + recipient: senderRecipient.recipient, + max_capacity: 8, + max_message_size: 512 + } as HrmpChannel; + + hrmp_channels.push(hrmpChannel); + } + configBuilder.hrmp_channels = hrmp_channels; + + writeFileSync(path.resolve(configPath, "test.config.toml"), TOML.stringify(configBuilder as any)); + } +} + +type AvailableParachains = "rococo-local"; +const relaychains = { + "rococo-local": { + default_command: "./zombienet/bin/polkadot", + chain: "rococo-local", + nodes: [] + } as Relaychain +} + +type AvailableCollators = "astar-collator"; +const collators = { + "astar-collator": { + name: "", + command: "./zombienet/bin/astar-collator", + rpc_port: 0, + args: [ "-l=xcm=trace", "--enable-evm-rpc" ] + } +} +interface ZombienetConfig { + settings: { timeout: number }, + relaychain: Relaychain, + parachains: Parachain[], + hrmp_channels: HrmpChannel[], +} + +const parachins = { + "astar-collator": ["astar-dev", "shiden-dev"] +} + +interface Relaychain { + default_command: string, + chain: string, + nodes: Node[] +} +interface Node { + name: string, +} +interface HrmpChannel { + sender: number, + recipient: number, + max_capacity: number, + max_message_size: number +} +interface Parachain { + id: number, + chain: string, + cumulus_based: boolean, + collator: Collator +} +interface Collator { + name: string, + command: string, + rpc_port: number, + args: string[], +} diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index 499e210d..9d032a90 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -1,24 +1,20 @@ import path from "node:path"; import { Flags } from "@oclif/core"; import { SwankyCommand } from "../../lib/swankyCommand.js"; -import { getSwankyConfig, Spinner } from "../../lib/index.js"; -import { existsSync } from "fs-extra"; +import { downloadZombinetBinary, getSwankyConfig, getTemplates, Spinner } from "../../lib/index.js"; +import { pathExistsSync } from "fs-extra/esm"; import inquirer from "inquirer"; import { copy, ensureDir } from "fs-extra/esm"; -import { DownloadEndedStats, DownloaderHelper } from "node-downloader-helper"; -import { execaCommand } from "execa"; +import { zombienetBins } from "../../lib/zombienetInfo.js"; export const zombienetConfig = "zombienet.config.toml"; -export const templatePath = path.resolve(__dirname, "../../templates"); - export const providerChoices = ["native", "k8s"]; export class InitZombienet extends SwankyCommand { static description = "Initialize Zomnienet"; static flags = { - verbose: Flags.boolean({ char: "v", description: "Verbose output" }), provider: Flags.string({ char: "p", description: "Provider to use" }), }; @@ -29,10 +25,12 @@ export class InitZombienet extends SwankyCommand { const spinner = new Spinner(flags.verbose); const projectPath = path.resolve(); - if (existsSync(path.resolve(projectPath, "zombienet", "bin", "zombienet"))) { + if (pathExistsSync(path.resolve(projectPath, "zombienet", "bin", "zombienet"))) { this.error("Zombienet config already initialized"); } + const zombienetTemplatePath = getTemplates().zombienetTemplatesPath; + let provider = flags.provider; if (provider === undefined) { const answer = await inquirer.prompt([{ @@ -48,45 +46,24 @@ export class InitZombienet extends SwankyCommand { // Copy templates await spinner.runCommand( () => - copyTemplateFile(path.resolve(templatePath, provider!), path.resolve(configPath, provider!)), + copyTemplateFile(path.resolve(zombienetTemplatePath, provider!), path.resolve(configPath, provider!)), "Copying template files" ); // Install binaries based on zombie config - await spinner.runCommand( - async () => new Promise(async (resolve, reject) => { - const binPath = path.resolve(projectPath, "zombienet", "bin"); - await ensureDir(binPath); - const platform = process.platform.toString(); - const dlUrl = zombieNetBinInfo.downloadUrl[platform]; - if (!dlUrl) - reject(`Could not download Zombienet. Platform ${process.platform} not supported!`); - - const dlFileDetails = await new Promise((resolve, reject) => { - const dl = new DownloaderHelper(dlUrl, binPath); - - dl.on("progress", (event) => { - spinner.text(`Downloading Zombienet binary ${event.progress.toFixed(2)}%`); - }); - dl.on("end", (event) => { - resolve(event); - }); - dl.on("error", (error) => { - reject(new Error(`Error downloading Zombienet binary: , ${error.message}`)); - }); - - dl.start().catch((error) => reject(new Error(`Error downloading Zombienet: , ${error.message}`))); - }); - - if (dlFileDetails.incomplete) { - reject("Zombienet binary download incomplete"); - } - - await execaCommand(`mv ${binPath}/${dlFileDetails.fileName} ${binPath}/zombienet`) - await execaCommand(`chmod +x ${binPath}/zombienet`); - resolve(); - }), - "Download Zombienet binary", + await this.spinner.runCommand( + () => downloadZombinetBinary(projectPath, zombienetBins, "zombienet", this.spinner), + "Downloading Zombienet" + ); + + await this.spinner.runCommand( + () => downloadZombinetBinary(projectPath, zombienetBins, "polkadot", this.spinner), + "Downloading Polkadot" + ); + + await this.spinner.runCommand( + () => downloadZombinetBinary(projectPath, zombienetBins, "astar-collator", this.spinner), + "Downloading Astar Collator" ); this.log("ZombieNet config Installed successfully"); @@ -99,16 +76,4 @@ export async function copyTemplateFile(templatePath: string, projectPath: string path.resolve(templatePath, zombienetConfig), path.resolve(projectPath, zombienetConfig) ); -} - -type downloadUrl = Record; - -const zombieNetBinInfo = { - version: "v1.3.42", - downloadUrl: { - darwin: - "https://github.com/paritytech/zombienet/releases/download/v1.3.42/zombienet-macos", - linux: - "https://github.com/paritytech/zombienet/releases/download/v1.3.42/zombienet-linux-x64", - } as downloadUrl, -}; +} \ No newline at end of file diff --git a/src/commands/zombienet/start.ts b/src/commands/zombienet/start.ts index e17f0b93..50d6a354 100644 --- a/src/commands/zombienet/start.ts +++ b/src/commands/zombienet/start.ts @@ -1,17 +1,16 @@ import { SwankyCommand } from "../../lib/swankyCommand.js"; import { Flags } from "@oclif/core"; import path from "node:path"; -import { existsSync } from "fs-extra"; -import { Spinner } from "../../lib/index.js"; -import { zombienetConfig } from "./init.js"; +import { pathExistsSync } from "fs-extra/esm"; import { execaCommand } from "execa"; +import inquirer from "inquirer"; +import { readdirSync } from "fs"; export class StartZombienet extends SwankyCommand { static description = "Start Zomnienet"; static flags = { - verbose: Flags.boolean({ char: "v", description: "Verbose output" }), provider: Flags.string({ char: "p", description: "Provider to use", default: "native" }), }; @@ -20,22 +19,31 @@ export class StartZombienet extends SwankyCommand { const projectPath = path.resolve(); const binPath = path.resolve(projectPath, "zombienet", "bin") - if (!existsSync(path.resolve(binPath, "zombienet"))) { + if (!pathExistsSync(path.resolve(binPath, "zombienet"))) { this.error("Zombienet has not initialized. Run `swanky zombienet:init` first"); } - const spinner = new Spinner(flags.verbose); + const zombienetConfigPath = path.resolve("zombienet", "config", flags.provider); - const configFilePath = path.resolve(projectPath, "zombienet", "config", flags.provider, zombienetConfig); + const configList = readdirSync(zombienetConfigPath); - if (!existsSync(configFilePath)) { + const zombienetConfig = (await inquirer.prompt([{ + name: "zombienetConfig", + type: "list", + choices: configList, + message: "Select a zombienet config to use", + }])).zombienetConfig; + + const configFilePath = path.resolve(zombienetConfigPath, zombienetConfig); + + if (!pathExistsSync(configFilePath)) { this.error(`Zombienet config for ${flags.provider} does not exist. Add provider config first.`); } await execaCommand( `./zombienet/bin/zombienet \ spawn --provider ${flags.provider} \ - ./zombienet/config/${flags.provider}/zombienet.config.toml + ./zombienet/config/${flags.provider}/${zombienetConfig} `, { stdio: "inherit", diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index 20c0efdc..b1e57068 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -11,6 +11,7 @@ import decompress from "decompress"; import { Spinner } from "./spinner.js"; import { SupportedPlatforms, SupportedArch } from "../types/index.js"; import { ConfigError, NetworkError } from "./errors.js"; +import { BinaryNames, zombienetInfo } from "./zombienetInfo.js"; export async function checkCliDependencies(spinner: Spinner) { const dependencyList = [ @@ -124,6 +125,63 @@ export async function downloadNode(projectPath: string, nodeInfo: nodeInfo, spin return path.resolve(binPath, dlFileDetails.filePath); } +export async function downloadZombinetBinary(projectPath: string, zombienetInfo: zombienetInfo, binaryName: BinaryNames, spinner: Spinner) { + const binPath = path.resolve(projectPath, "zombienet", "bin"); + await ensureDir(binPath); + + const platformDlUrls = zombienetInfo[binaryName].downloadUrl[process.platform as SupportedPlatforms]; + if (!platformDlUrls) + throw new ConfigError( + `Could not download ${binaryName}. Platform ${process.platform} not supported!` + ); + + const dlUrl = platformDlUrls[process.arch as SupportedArch]; + if (!dlUrl) + throw new ConfigError( + `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` + ); + + const dlFileDetails = await new Promise((resolve, reject) => { + const dl = new DownloaderHelper(dlUrl, binPath); + + dl.on("progress", (event) => { + spinner.text(`Downloading ${binaryName} ${event.progress.toFixed(2)}%`); + }); + dl.on("end", (event) => { + resolve(event); + }); + dl.on("error", (error) => { + reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)); + }); + + dl.start().catch((error: Error) => + reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)) + ); + }); + + if (dlFileDetails.incomplete) { + throw new NetworkError("${binaryName} download incomplete"); + } + + let fileName = dlFileDetails.fileName; + + if (dlFileDetails.filePath.endsWith(".tar.gz")) { + const compressedFilePath = path.resolve(binPath, dlFileDetails.filePath); + const decompressed = await decompress(compressedFilePath, binPath); + fileName = decompressed[0].path; + } + + console.log('\n', fileName, '\n'); + + if(fileName !== binaryName) + { + await execaCommand(`mv ${binPath}/${fileName} ${binPath}/${binaryName}`) + } + await execaCommand(`chmod +x ${binPath}/${binaryName}`); + + return path.resolve(binPath, dlFileDetails.filePath); +} + export async function installDeps(projectPath: string) { let installCommand = "npm install"; diff --git a/src/lib/templates.ts b/src/lib/templates.ts index ef814298..90996e34 100644 --- a/src/lib/templates.ts +++ b/src/lib/templates.ts @@ -8,6 +8,7 @@ const __dirname = path.dirname(__filename); export function getTemplates() { const templatesPath = path.resolve(__dirname, "..", "templates"); const contractTemplatesPath = path.resolve(templatesPath, "contracts"); + const zombienetTemplatesPath = path.resolve(templatesPath, "zombienet"); const fileList = readdirSync(contractTemplatesPath, { withFileTypes: true, }); @@ -19,5 +20,6 @@ export function getTemplates() { templatesPath, contractTemplatesPath, contractTemplatesList, + zombienetTemplatesPath, }; } diff --git a/src/lib/zombienetInfo.ts b/src/lib/zombienetInfo.ts new file mode 100644 index 00000000..44d1e9a9 --- /dev/null +++ b/src/lib/zombienetInfo.ts @@ -0,0 +1,44 @@ +export type zombienetInfo = typeof zombienetBins; + +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", + } + }, + }, + "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", + } + } + }, + "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", + }, + 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", + } + } + } +}; \ No newline at end of file From b60b72510d5df33ec80b5d7a69dee916ca546d19 Mon Sep 17 00:00:00 2001 From: prxgr4mm3r Date: Wed, 17 Jan 2024 01:51:00 +0200 Subject: [PATCH 3/9] Reformat zombienet feature --- src/commands/init/index.ts | 43 +++- src/commands/zombienet/addProvider.ts | 57 ----- src/commands/zombienet/buildConfig.ts | 205 ------------------ src/commands/zombienet/init.ts | 73 +++---- src/commands/zombienet/start.ts | 19 +- src/lib/tasks.ts | 143 ++++++++---- src/templates/zombienet/astar-collator.toml | 69 ++++++ .../zombienet/k8s/zombienet.config.toml | 1 - src/templates/zombienet/polkadot.toml | 12 + .../{native => }/zombienet.config.toml | 36 +++ src/types/index.ts | 52 ++++- 11 files changed, 343 insertions(+), 367 deletions(-) delete mode 100644 src/commands/zombienet/addProvider.ts delete mode 100644 src/commands/zombienet/buildConfig.ts create mode 100644 src/templates/zombienet/astar-collator.toml delete mode 100644 src/templates/zombienet/k8s/zombienet.config.toml create mode 100644 src/templates/zombienet/polkadot.toml rename src/templates/zombienet/{native => }/zombienet.config.toml (60%) diff --git a/src/commands/init/index.ts b/src/commands/init/index.ts index 45177372..4e142524 100644 --- a/src/commands/init/index.ts +++ b/src/commands/init/index.ts @@ -107,6 +107,47 @@ export class Init extends SwankyCommand { 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[] = []; @@ -220,7 +261,7 @@ export class Init extends SwankyCommand { callback(result as string); } } - this.log("🎉 😎 Swanky project successfully initialised! 😎 🎉"); + this.log("🎉 😎 Swanky project successfully initialized! 😎 🎉"); } async generate(projectName: string) { diff --git a/src/commands/zombienet/addProvider.ts b/src/commands/zombienet/addProvider.ts deleted file mode 100644 index 99708f73..00000000 --- a/src/commands/zombienet/addProvider.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { SwankyCommand } from "../../lib/swankyCommand.js"; -import { Flags } from "@oclif/core"; -import path from "node:path"; -import { pathExistsSync } from "fs-extra/esm"; -import { getTemplates, Spinner } from "../../lib/index.js"; -import inquirer from "inquirer"; -import { copyTemplateFile, providerChoices, zombienetConfig } from "./init.js"; - - -export class AddZombienetProvider extends SwankyCommand{ - static description = "Add Zombienet provider config"; - - static flags = { - provider: Flags.string({ char: "p", description: "Provider to use" }), - }; - - async run(): Promise { - const { flags } = await this.parse(AddZombienetProvider); - - 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 zombienetTemplatePath = getTemplates().zombienetTemplatesPath; - - - const spinner = new Spinner(flags.verbose); - - let provider = flags.provider; - if (provider === undefined) { - const answer = await inquirer.prompt([{ - name: "provider", - type: "list", - choices: providerChoices, - message: "Select a provider to use", - }]) - provider = answer.provider; - } - - const configPath = path.resolve(projectPath, "zombienet", "config") - - if (pathExistsSync(path.resolve(configPath, provider!, zombienetConfig))) { - this.error(`Zombienet config for ${provider!} provider already exists`); - } - - // Copy templates - await spinner.runCommand( - () => - copyTemplateFile(path.resolve(zombienetTemplatePath, provider!), path.resolve(configPath, provider!)), - "Copying template files" - ); - - this.log("Zombienet provider config added successfully"); - } -} diff --git a/src/commands/zombienet/buildConfig.ts b/src/commands/zombienet/buildConfig.ts deleted file mode 100644 index 69bc1e84..00000000 --- a/src/commands/zombienet/buildConfig.ts +++ /dev/null @@ -1,205 +0,0 @@ -import { SwankyCommand } from "../../lib/swankyCommand.js"; -import { Flags } from "@oclif/core"; -import path from "node:path"; -import TOML from "@iarna/toml"; -import inquirer from "inquirer"; -import { writeFileSync } from "node:fs"; - - -export class BuildConfig extends SwankyCommand{ - static description = "Build Zombienet provider config"; - - static flags = { - provider: Flags.string({ char: "p", default:"native", description: "Provider to use" }), - }; - - async run(): Promise { - const { flags } = await this.parse(BuildConfig); - - const projectPath = path.resolve(); - - const configPath = path.resolve(projectPath, "zombienet", "config", flags.provider) - - // const parsedConfig = TOML.parse(readFileSync(path.resolve(configPath, zombienetConfig), "utf-8")); - // - // console.log("Parsed config:\n", parsedConfig, '\n'); - - const configBuilder = { - settings: { - timeout: 1000 - }, - relaychain:{ - default_command: "", - chain: "", - nodes: [] - }, - parachains:[], - hrmp_channels:[] - } as ZombienetConfig; - - const relaychainName = (await inquirer.prompt([{ - name: "relaychainName", - type: "list", - choices: ["rococo-local"], - message: "Select a relaychain to use", - }])).relaychainName; - - configBuilder.relaychain = relaychains[relaychainName as AvailableParachains]; - - const nodesAmount = (await inquirer.prompt([{ - name: "nodesAmount", - type: "number", - message: "How many nodes do you want to run?", - }])).nodesAmount; - - const nodes : Node[] = []; - for (let i = 0; i < nodesAmount; i++) { - nodes.push({name: `relay${ - "0".repeat(nodesAmount.toString().length - i.toString().length)+i}` - }); - } - configBuilder.relaychain.nodes = nodes; - - const parachainsAmount = (await inquirer.prompt([{ - name: "parachainsAmount", - type: "number", - message: "How many parachains do you want to run?", - }])).parachainsAmount; - - const parachains : Parachain[] = []; - for(let i = 0; i < parachainsAmount; i++) { - const parachainId = 2000 + i; - - const collatorRpcPort = 8545 + i; - - const collatorType = (await inquirer.prompt([{ - name: "collatorType", - type: "list", - choices: ["astar-collator"], - message: `Select collator type for parachain ${i}`, - }])).collatorType; - - const collator = collators[collatorType as AvailableCollators]; - - const parachainName = (await inquirer.prompt([{ - name: "parachainName", - type: "list", - choices: parachins[collatorType as AvailableCollators], - message: `Chose parachain name for parachain ${i}`, - }])).parachainName; - - collator.name = parachainName + "-collator"; - collator.rpc_port = collatorRpcPort; - - const parachain = { - id: parachainId, - chain: parachainName, - cumulus_based: true, - collator: collator - } as Parachain; - - parachains.push(parachain); - } - configBuilder.parachains = parachains; - - - const hrmp_channels : HrmpChannel[] = []; - - const hrmpChannelsAmount = (await inquirer.prompt([{ - name: "hrmpChannelsAmount", - type: "number", - message: `How many hrmp channels do you want to run?(Max: ${parachainsAmount * (parachainsAmount - 1)})`, - }])).hrmpChannelsAmount; - - if(hrmpChannelsAmount > parachainsAmount * (parachainsAmount - 1)) { - this.error("Maximum hrmp channels amount exceeded"); - } - - const channelChoices = []; - for(let j = 0; j < parachainsAmount; j++) { - for(let k = 0; k < parachainsAmount; k++) { - if(j != k) { - channelChoices.push({value: {sender: parachains[j].id, recipient: parachains[k].id}, name: `${parachains[j].chain} -> ${parachains[k].chain}`}); - } - } - } - - for(let i = 0; i < hrmpChannelsAmount; i++) { - const senderRecipient = (await inquirer.prompt([{ - name: "senderRecipient", - type: "list", - choices: channelChoices, - message: `Select sender and recipient for hrmp channel ${i}`, - }])).senderRecipient; - - - const hrmpChannel = { - sender: senderRecipient.sender, - recipient: senderRecipient.recipient, - max_capacity: 8, - max_message_size: 512 - } as HrmpChannel; - - hrmp_channels.push(hrmpChannel); - } - configBuilder.hrmp_channels = hrmp_channels; - - writeFileSync(path.resolve(configPath, "test.config.toml"), TOML.stringify(configBuilder as any)); - } -} - -type AvailableParachains = "rococo-local"; -const relaychains = { - "rococo-local": { - default_command: "./zombienet/bin/polkadot", - chain: "rococo-local", - nodes: [] - } as Relaychain -} - -type AvailableCollators = "astar-collator"; -const collators = { - "astar-collator": { - name: "", - command: "./zombienet/bin/astar-collator", - rpc_port: 0, - args: [ "-l=xcm=trace", "--enable-evm-rpc" ] - } -} -interface ZombienetConfig { - settings: { timeout: number }, - relaychain: Relaychain, - parachains: Parachain[], - hrmp_channels: HrmpChannel[], -} - -const parachins = { - "astar-collator": ["astar-dev", "shiden-dev"] -} - -interface Relaychain { - default_command: string, - chain: string, - nodes: Node[] -} -interface Node { - name: string, -} -interface HrmpChannel { - sender: number, - recipient: number, - max_capacity: number, - max_message_size: number -} -interface Parachain { - id: number, - chain: string, - cumulus_based: boolean, - collator: Collator -} -interface Collator { - name: string, - command: string, - rpc_port: number, - args: string[], -} diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index 9d032a90..c660daf9 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -1,22 +1,27 @@ import path from "node:path"; import { Flags } from "@oclif/core"; import { SwankyCommand } from "../../lib/swankyCommand.js"; -import { downloadZombinetBinary, getSwankyConfig, getTemplates, Spinner } from "../../lib/index.js"; +import { + copyZombienetTemplateFile, downloadZombinetBinaries, + buildZombienetConfigFromBinaries, + getSwankyConfig, + getTemplates, + Spinner, +} from "../../lib/index.js"; import { pathExistsSync } from "fs-extra/esm"; -import inquirer from "inquirer"; -import { copy, ensureDir } from "fs-extra/esm"; -import { zombienetBins } from "../../lib/zombienetInfo.js"; - export const zombienetConfig = "zombienet.config.toml"; -export const providerChoices = ["native", "k8s"]; - export class InitZombienet extends SwankyCommand { static description = "Initialize Zomnienet"; static flags = { - provider: Flags.string({ char: "p", description: "Provider to use" }), - }; + binaries: Flags.string({ + char: "b", + multiple: true, + required: true, + description: "Binaries to install", + }), + } async run(): Promise { const { flags } = await this.parse(InitZombienet); @@ -31,49 +36,31 @@ export class InitZombienet extends SwankyCommand { const zombienetTemplatePath = getTemplates().zombienetTemplatesPath; - let provider = flags.provider; - if (provider === undefined) { - const answer = await inquirer.prompt([{ - name: "provider", - type: "list", - choices: providerChoices, - message: "Select a provider to use", - }]) - provider = answer.provider; - } - const configPath = path.resolve(projectPath, "zombienet", "config") - // Copy templates - await spinner.runCommand( - () => - copyTemplateFile(path.resolve(zombienetTemplatePath, provider!), path.resolve(configPath, provider!)), - "Copying template files" - ); + + if(!flags.binaries || flags.binaries.length < 2) { + 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( - () => downloadZombinetBinary(projectPath, zombienetBins, "zombienet", this.spinner), - "Downloading Zombienet" + () => downloadZombinetBinaries(projectPath, this.swankyConfig, this.spinner), + "Downloading Zombienet binaries" ); - await this.spinner.runCommand( - () => downloadZombinetBinary(projectPath, zombienetBins, "polkadot", this.spinner), - "Downloading Polkadot" - ); - await this.spinner.runCommand( - () => downloadZombinetBinary(projectPath, zombienetBins, "astar-collator", this.spinner), - "Downloading Astar Collator" - ); this.log("ZombieNet config Installed successfully"); } } -export async function copyTemplateFile(templatePath: string, projectPath: string) { - await ensureDir(projectPath); - await copy( - path.resolve(templatePath, zombienetConfig), - path.resolve(projectPath, zombienetConfig) - ); -} \ No newline at end of file diff --git a/src/commands/zombienet/start.ts b/src/commands/zombienet/start.ts index 50d6a354..17a3ceeb 100644 --- a/src/commands/zombienet/start.ts +++ b/src/commands/zombienet/start.ts @@ -1,5 +1,4 @@ import { SwankyCommand } from "../../lib/swankyCommand.js"; -import { Flags } from "@oclif/core"; import path from "node:path"; import { pathExistsSync } from "fs-extra/esm"; import { execaCommand } from "execa"; @@ -10,20 +9,14 @@ import { readdirSync } from "fs"; export class StartZombienet extends SwankyCommand { static description = "Start Zomnienet"; - static flags = { - provider: Flags.string({ char: "p", description: "Provider to use", default: "native" }), - }; - async run(): Promise { - 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", flags.provider); + const zombienetConfigPath = path.resolve("zombienet", "config"); const configList = readdirSync(zombienetConfigPath); @@ -34,16 +27,10 @@ export class StartZombienet extends SwankyCommand { message: "Select a zombienet config to use", }])).zombienetConfig; - const configFilePath = path.resolve(zombienetConfigPath, zombienetConfig); - - if (!pathExistsSync(configFilePath)) { - this.error(`Zombienet config for ${flags.provider} does not exist. Add provider config first.`); - } - await execaCommand( `./zombienet/bin/zombienet \ - spawn --provider ${flags.provider} \ - ./zombienet/config/${flags.provider}/${zombienetConfig} + spawn --provider native \ + ./zombienet/config/${zombienetConfig} `, { stdio: "inherit", diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index b1e57068..8f7a9985 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -9,9 +9,13 @@ import process from "node:process"; import { nodeInfo } from "./nodeInfo.js"; import decompress from "decompress"; import { Spinner } from "./spinner.js"; -import { SupportedPlatforms, SupportedArch } from "../types/index.js"; +import { SupportedPlatforms, SupportedArch, SwankyConfig, ZombienetConfig } from "../types/index.js"; import { ConfigError, NetworkError } from "./errors.js"; -import { BinaryNames, zombienetInfo } from "./zombienetInfo.js"; +import { BinaryNames } from "./zombienetInfo.js"; +import { zombienetConfig } from "../commands/zombienet/init.js"; +import { readFileSync } from "fs"; +import TOML from "@iarna/toml"; +import { writeFileSync } from "node:fs"; export async function checkCliDependencies(spinner: Spinner) { const dependencyList = [ @@ -124,62 +128,115 @@ export async function downloadNode(projectPath: string, nodeInfo: nodeInfo, spin return path.resolve(binPath, dlFileDetails.filePath); } - -export async function downloadZombinetBinary(projectPath: string, zombienetInfo: zombienetInfo, binaryName: BinaryNames, spinner: Spinner) { +export async function copyZombienetTemplateFile(templatePath: string, configPath: string) { + await ensureDir(configPath); + await copy( + path.resolve(templatePath, zombienetConfig), + path.resolve(configPath, zombienetConfig) + ); +} +export async function downloadZombinetBinaries(projectPath: string, swankyConfig: SwankyConfig, spinner: Spinner) { const binPath = path.resolve(projectPath, "zombienet", "bin"); await ensureDir(binPath); - const platformDlUrls = zombienetInfo[binaryName].downloadUrl[process.platform as SupportedPlatforms]; - if (!platformDlUrls) - throw new ConfigError( - `Could not download ${binaryName}. Platform ${process.platform} not supported!` - ); - - const dlUrl = platformDlUrls[process.arch as SupportedArch]; - if (!dlUrl) - throw new ConfigError( - `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` - ); + const zombienetInfo = swankyConfig.zombienet; + + const dlUrls = new Map(); + if (zombienetInfo.version) { + const version = zombienetInfo.version; + const binaryName = "zombienet"; + const platformDlUrls = zombienetInfo.downloadUrl[process.platform as SupportedPlatforms]; + if (!platformDlUrls) + throw new ConfigError( + `Could not download ${binaryName}. Platform ${process.platform} not supported!` + ); + let dlUrl = platformDlUrls[process.arch as SupportedArch]; + if (!dlUrl) + throw new ConfigError( + `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` + ); + dlUrl = dlUrl.replace("${version}", version); + dlUrls.set(binaryName, dlUrl); + } - const dlFileDetails = await new Promise((resolve, reject) => { - const dl = new DownloaderHelper(dlUrl, binPath); + for(const binaryName of Object.keys(zombienetInfo.binaries)){ + const binaryInfo = zombienetInfo.binaries[binaryName as BinaryNames]; + const version = binaryInfo.version; + const platformDlUrls = binaryInfo.downloadUrl[process.platform as SupportedPlatforms]; + if (!platformDlUrls) + throw new ConfigError( + `Could not download ${binaryName}. Platform ${process.platform} not supported!` + ); + let dlUrl = platformDlUrls[process.arch as SupportedArch]; + if (!dlUrl) + throw new ConfigError( + `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` + ); + dlUrl = dlUrl.replace(/\$\{version\}/gi, version); + dlUrls.set(binaryName, dlUrl); + } - dl.on("progress", (event) => { - spinner.text(`Downloading ${binaryName} ${event.progress.toFixed(2)}%`); - }); - dl.on("end", (event) => { - resolve(event); - }); - dl.on("error", (error) => { - reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)); + for (const [binaryName, dlUrl] of dlUrls) { + const dlFileDetails = await new Promise((resolve, reject) => { + const dl = new DownloaderHelper(dlUrl, binPath); + + dl.on("progress", (event) => { + spinner.text(`Downloading ${binaryName} ${event.progress.toFixed(2)}%`); + }); + dl.on("end", (event) => { + resolve(event); + }); + dl.on("error", (error) => { + reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)); + }); + + dl.start().catch((error: Error) => + reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)) + ); }); - dl.start().catch((error: Error) => - reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)) - ); - }); + if (dlFileDetails.incomplete) { + throw new NetworkError("${binaryName} download incomplete"); + } - if (dlFileDetails.incomplete) { - throw new NetworkError("${binaryName} download incomplete"); - } + let fileName = dlFileDetails.fileName; - let fileName = dlFileDetails.fileName; + if (dlFileDetails.filePath.endsWith(".tar.gz")) { + const compressedFilePath = path.resolve(binPath, dlFileDetails.filePath); + const decompressed = await decompress(compressedFilePath, binPath); + await remove(compressedFilePath); + fileName = decompressed[0].path; + } - if (dlFileDetails.filePath.endsWith(".tar.gz")) { - const compressedFilePath = path.resolve(binPath, dlFileDetails.filePath); - const decompressed = await decompress(compressedFilePath, binPath); - fileName = decompressed[0].path; + if(fileName !== binaryName) + { + await execaCommand(`mv ${binPath}/${fileName} ${binPath}/${binaryName}`) + } + await execaCommand(`chmod +x ${binPath}/${binaryName}`); } +} - console.log('\n', fileName, '\n'); +export async function buildZombienetConfigFromBinaries(binaries: string[], templatePath: string, configPath: string) { + await ensureDir(configPath); + let configBuilder = { + settings: { + timeout: 1000 + }, + relaychain:{ + default_command: "", + chain: "", + nodes: [] + }, + parachains:[], + hrmp_channels:[] + } as ZombienetConfig; - if(fileName !== binaryName) - { - await execaCommand(`mv ${binPath}/${fileName} ${binPath}/${binaryName}`) + for (const binaryName of binaries) { + const tamplate = TOML.parse(readFileSync(path.resolve(templatePath, binaryName+".toml"), "utf8")); + configBuilder = {...configBuilder, ...tamplate}; } - await execaCommand(`chmod +x ${binPath}/${binaryName}`); - return path.resolve(binPath, dlFileDetails.filePath); + writeFileSync(path.resolve(configPath, zombienetConfig), TOML.stringify(configBuilder as any)); } export async function installDeps(projectPath: string) { diff --git a/src/templates/zombienet/astar-collator.toml b/src/templates/zombienet/astar-collator.toml new file mode 100644 index 00000000..a5a14ffb --- /dev/null +++ b/src/templates/zombienet/astar-collator.toml @@ -0,0 +1,69 @@ +[[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 \ No newline at end of file diff --git a/src/templates/zombienet/k8s/zombienet.config.toml b/src/templates/zombienet/k8s/zombienet.config.toml deleted file mode 100644 index bdda138f..00000000 --- a/src/templates/zombienet/k8s/zombienet.config.toml +++ /dev/null @@ -1 +0,0 @@ -# TODO add k8s provider template \ No newline at end of file diff --git a/src/templates/zombienet/polkadot.toml b/src/templates/zombienet/polkadot.toml new file mode 100644 index 00000000..5c34a309 --- /dev/null +++ b/src/templates/zombienet/polkadot.toml @@ -0,0 +1,12 @@ +[relaychain] +default_command = "./zombienet/bin/polkadot" +chain = "rococo-local" + + [[relaychain.nodes]] + name = "relay01" + + [[relaychain.nodes]] + name = "relay02" + + [[relaychain.nodes]] + name = "relay03" \ No newline at end of file diff --git a/src/templates/zombienet/native/zombienet.config.toml b/src/templates/zombienet/zombienet.config.toml similarity index 60% rename from src/templates/zombienet/native/zombienet.config.toml rename to src/templates/zombienet/zombienet.config.toml index 65b16b69..a57e6442 100644 --- a/src/templates/zombienet/native/zombienet.config.toml +++ b/src/templates/zombienet/zombienet.config.toml @@ -36,6 +36,17 @@ cumulus_based = true 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 @@ -47,3 +58,28 @@ cumulus_based = true 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 \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index aa13a0df..3dafa60f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -11,7 +11,7 @@ export interface ChainProperty { export type ExtrinsicPayload = SubmittableExtrinsic<"promise">; -export interface Encrypted { iv: string; data: string }; +export interface Encrypted { iv: string; data: string } export interface AccountData { isDev: boolean; @@ -38,6 +38,17 @@ export interface DeploymentData { deployerAlias: string; address: string; } + +export interface downloadUrl { + darwin: { + "arm64": string, + "x64": string + }, + linux: { + "arm64": string, + "x64": string + } +} export interface SwankyConfig { node: { polkadotPalletVersions: string; @@ -47,6 +58,45 @@ export interface SwankyConfig { accounts: AccountData[]; contracts: Record | Record; networks: Record + zombienet: { + version: string, + downloadUrl : downloadUrl, + binaries: Record + } +} + +export interface ZombienetConfig { + settings: { timeout: number }, + relaychain: Relaychain, + parachains: Parachain[], + hrmp_channels: HrmpChannel[], +} + +interface Relaychain { + default_command: string, + chain: string, + nodes: Node[] +} +interface Node { + name: string, +} +interface HrmpChannel { + sender: number, + recipient: number, + max_capacity: number, + max_message_size: number +} +interface Parachain { + id: number, + chain: string, + cumulus_based: boolean, + collator: Collator +} +interface Collator { + name: string, + command: string, + rpc_port: number, + args: string[], } export type SupportedPlatforms = "darwin" | "linux"; From 2497f3e914768b43188ea67d8edcd18de6d21bbb Mon Sep 17 00:00:00 2001 From: prxgr4mm3r Date: Thu, 18 Jan 2024 21:27:57 +0200 Subject: [PATCH 4/9] Fixes --- src/commands/init/index.ts | 41 ---------- src/commands/zombienet/init.ts | 35 +++++++-- src/commands/zombienet/start.ts | 26 +++---- src/lib/tasks.ts | 8 +- src/lib/zombienetInfo.ts | 74 +++++++++---------- src/templates/zombienet/zombienet.config.toml | 69 ----------------- src/types/index.ts | 14 ++-- 7 files changed, 92 insertions(+), 175 deletions(-) diff --git a/src/commands/init/index.ts b/src/commands/init/index.ts index 4e142524..16a78b5b 100644 --- a/src/commands/init/index.ts +++ b/src/commands/init/index.ts @@ -107,47 +107,6 @@ export class Init extends SwankyCommand { 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[] = []; diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index c660daf9..1ac55f4e 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -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 { - static description = "Initialize Zomnienet"; + static description = "Initialize Zombienet"; static flags = { binaries: Flags.string({ char: "b", multiple: true, - required: true, + required: false, + default: [], description: "Binaries to install", }), } @@ -27,18 +29,37 @@ export class InitZombienet extends SwankyCommand { const { flags } = await this.parse(InitZombienet); await getSwankyConfig(); - 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), @@ -54,7 +75,7 @@ export class InitZombienet extends SwankyCommand { // 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" ); diff --git a/src/commands/zombienet/start.ts b/src/commands/zombienet/start.ts index 17a3ceeb..e79ab829 100644 --- a/src/commands/zombienet/start.ts +++ b/src/commands/zombienet/start.ts @@ -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 { - 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 { + 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", diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index 8f7a9985..8524fc9e 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -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(); if (zombienetInfo.version) { const version = zombienetInfo.version; @@ -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]; diff --git a/src/lib/zombienetInfo.ts b/src/lib/zombienetInfo.ts index 44d1e9a9..5956c0cd 100644 --- a/src/lib/zombienetInfo.ts +++ b/src/lib/zombienetInfo.ts @@ -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: { + "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", + "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", + } + }, + }, + }, }; \ No newline at end of file diff --git a/src/templates/zombienet/zombienet.config.toml b/src/templates/zombienet/zombienet.config.toml index a57e6442..e71ba918 100644 --- a/src/templates/zombienet/zombienet.config.toml +++ b/src/templates/zombienet/zombienet.config.toml @@ -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 \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index 3dafa60f..48cf0929 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -39,7 +39,7 @@ export interface DeploymentData { address: string; } -export interface downloadUrl { +export interface DownloadUrl { darwin: { "arm64": string, "x64": string @@ -58,11 +58,13 @@ export interface SwankyConfig { accounts: AccountData[]; contracts: Record | Record; networks: Record - zombienet: { - version: string, - downloadUrl : downloadUrl, - binaries: Record - } + zombienet?: ZombienetData; +} + +interface ZombienetData { + version: string; + downloadUrl: DownloadUrl; + binaries: Record; } export interface ZombienetConfig { From 2643553426927fb2bd999f105222404ec66b176b Mon Sep 17 00:00:00 2001 From: prxgr4mm3r Date: Thu, 1 Feb 2024 14:17:54 +0200 Subject: [PATCH 5/9] fix: Update versions and fix config merging --- src/commands/zombienet/init.ts | 2 +- src/lib/tasks.ts | 27 ++++++++++++++----- src/lib/zombienetInfo.ts | 27 ++++++++++++++----- .../zombienet/polkadot-parachain.toml | 7 +++++ src/types/index.ts | 12 ++++----- 5 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 src/templates/zombienet/polkadot-parachain.toml diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index 1ac55f4e..7018a7ab 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -23,7 +23,7 @@ export class InitZombienet extends SwankyCommand { default: [], description: "Binaries to install", }), - } + }; async run(): Promise { const { flags } = await this.parse(InitZombienet); diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index 8524fc9e..ed255770 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -9,7 +9,7 @@ import process from "node:process"; import { nodeInfo } from "./nodeInfo.js"; import decompress from "decompress"; import { Spinner } from "./spinner.js"; -import { SupportedPlatforms, SupportedArch, SwankyConfig, ZombienetConfig } from "../types/index.js"; +import { SupportedPlatforms, SupportedArch, SwankyConfig, ZombienetConfig, Relaychain } from "../types/index.js"; import { ConfigError, NetworkError } from "./errors.js"; import { BinaryNames } from "./zombienetInfo.js"; import { zombienetConfig } from "../commands/zombienet/init.js"; @@ -176,7 +176,7 @@ export async function downloadZombienetBinaries(binaries: string[], projectPath: throw new ConfigError( `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` ); - dlUrl = dlUrl.replace(/\$\{version\}/gi, version); + dlUrl = dlUrl.replace(/\$\{version}/gi, version); dlUrls.set(binaryName, dlUrl); } @@ -222,7 +222,7 @@ export async function downloadZombienetBinaries(binaries: string[], projectPath: export async function buildZombienetConfigFromBinaries(binaries: string[], templatePath: string, configPath: string) { await ensureDir(configPath); - let configBuilder = { + const configBuilder = { settings: { timeout: 1000 }, @@ -231,13 +231,26 @@ export async function buildZombienetConfigFromBinaries(binaries: string[], templ chain: "", nodes: [] }, - parachains:[], - hrmp_channels:[] + parachains:[] } as ZombienetConfig; for (const binaryName of binaries) { - const tamplate = TOML.parse(readFileSync(path.resolve(templatePath, binaryName+".toml"), "utf8")); - configBuilder = {...configBuilder, ...tamplate}; + const template = TOML.parse(readFileSync(path.resolve(templatePath, binaryName+".toml"), "utf8")); + if(template.parachains !== undefined) { + (template.parachains as any).forEach((parachain: any) => { + configBuilder.parachains.push(parachain); + }); + } + if(template.hrmp_channels !== undefined) { + configBuilder.hrmp_channels = []; + (template.hrmp_channels as any).forEach((hrmp_channel: any) => { + configBuilder.hrmp_channels!.push(hrmp_channel); + }); + } + if(template.relaychain !== undefined) { + configBuilder.relaychain = template.relaychain as unknown as Relaychain; + } + } writeFileSync(path.resolve(configPath, zombienetConfig), TOML.stringify(configBuilder as any)); diff --git a/src/lib/zombienetInfo.ts b/src/lib/zombienetInfo.ts index 5956c0cd..8e30ed9b 100644 --- a/src/lib/zombienetInfo.ts +++ b/src/lib/zombienetInfo.ts @@ -1,17 +1,17 @@ export type zombienetInfo = typeof zombienet; export type BinaryNames = "zombienet" | "polkadot" | "astar-collator"; -export const zombienet= { +export const 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" + "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": { @@ -19,12 +19,25 @@ export const zombienet= { downloadUrl: { darwin: { "arm64": "https://github.com/paritytech/polkadot/releases/download/v${version}/polkadot", - "x64": "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", - } + }, + }, + }, + "polkadot-parachain": { + version: "0.9.430", + downloadUrl: { + darwin: { + "arm64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", + "x64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", + }, + linux: { + "arm64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", + "x64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", + }, }, }, "astar-collator": { @@ -32,12 +45,12 @@ export const zombienet= { 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" + "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", - } + }, }, }, }, diff --git a/src/templates/zombienet/polkadot-parachain.toml b/src/templates/zombienet/polkadot-parachain.toml new file mode 100644 index 00000000..8f0b1005 --- /dev/null +++ b/src/templates/zombienet/polkadot-parachain.toml @@ -0,0 +1,7 @@ +[[parachains]] +id = 100 + + [parachains.collator] + name = "collator01" + command = "./zombienet/bin/polkadot-parachain" + args = ["-lparachain=debug"] \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index 48cf0929..0d18333c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -71,30 +71,30 @@ export interface ZombienetConfig { settings: { timeout: number }, relaychain: Relaychain, parachains: Parachain[], - hrmp_channels: HrmpChannel[], + hrmp_channels?: HrmpChannel[], } -interface Relaychain { +export interface Relaychain { default_command: string, chain: string, nodes: Node[] } -interface Node { +export interface Node { name: string, } -interface HrmpChannel { +export interface HrmpChannel { sender: number, recipient: number, max_capacity: number, max_message_size: number } -interface Parachain { +export interface Parachain { id: number, chain: string, cumulus_based: boolean, collator: Collator } -interface Collator { +export interface Collator { name: string, command: string, rpc_port: number, From 7d70a7941eff23f24843be90542fb7ba0072481d Mon Sep 17 00:00:00 2001 From: prxgr4mm3r Date: Mon, 19 Feb 2024 21:53:25 +0200 Subject: [PATCH 6/9] fixes --- src/commands/zombienet/init.ts | 40 ++++++++++------- src/lib/tasks.ts | 78 +++++++++++++++++++++------------- src/lib/zombienetInfo.ts | 7 ++- 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index 7018a7ab..e78469c8 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -2,16 +2,18 @@ import path from "node:path"; import { Flags } from "@oclif/core"; import { SwankyCommand } from "../../lib/swankyCommand.js"; import { - copyZombienetTemplateFile, downloadZombienetBinaries, buildZombienetConfigFromBinaries, - getSwankyConfig, + copyZombienetTemplateFile, + downloadZombienetBinaries, getTemplates, + osCheck, Spinner, } from "../../lib/index.js"; import { pathExistsSync } from "fs-extra/esm"; -import { zombienet } from "../../lib/zombienetInfo.js"; +import { zombienet, zombienetBinariesList } from "../../lib/zombienetInfo.js"; export const zombienetConfig = "zombienet.config.toml"; + export class InitZombienet extends SwankyCommand { static description = "Initialize Zombienet"; @@ -20,6 +22,7 @@ export class InitZombienet extends SwankyCommand { char: "b", multiple: true, required: false, + options: zombienetBinariesList, default: [], description: "Binaries to install", }), @@ -27,7 +30,12 @@ export class InitZombienet extends SwankyCommand { async run(): Promise { const { flags } = await this.parse(InitZombienet); - await getSwankyConfig(); + + 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).`); + } const projectPath = path.resolve(); if (pathExistsSync(path.resolve(projectPath, "zombienet", "bin", "zombienet"))) { @@ -42,12 +50,15 @@ export class InitZombienet extends SwankyCommand { binaries: {}, }; - if(!flags.binaries.includes("polkadot")) { + if (!flags.binaries.includes("polkadot")) { flags.binaries.push("polkadot"); } - for(const binaryName of flags.binaries){ - if(!Object.keys(zombienet.binaries).includes(binaryName)) { + 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]; @@ -57,30 +68,27 @@ export class InitZombienet extends SwankyCommand { const zombienetTemplatePath = getTemplates().zombienetTemplatesPath; - const configPath = path.resolve(projectPath, "zombienet", "config") + const configPath = path.resolve(projectPath, "zombienet", "config"); - if(flags.binaries.length < 2) { + if (flags.binaries.length < 2) { await spinner.runCommand( () => copyZombienetTemplateFile(zombienetTemplatePath, configPath), - "Copying template files" + "Copying template files", ); - } - else { + } else { await spinner.runCommand( () => buildZombienetConfigFromBinaries(flags.binaries, zombienetTemplatePath, configPath), - "Copying template files" + "Copying template files", ); } // Install binaries based on zombie config await this.spinner.runCommand( () => downloadZombienetBinaries(flags.binaries, projectPath, this.swankyConfig, this.spinner), - "Downloading Zombienet binaries" + "Downloading Zombienet binaries", ); - - this.log("ZombieNet config Installed successfully"); } } diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index ed255770..f200b436 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -1,6 +1,6 @@ import { execaCommand } from "execa"; -import { ensureDir, copy, remove } from "fs-extra/esm"; -import { rename, readFile, rm, writeFile } from "fs/promises"; +import { copy, ensureDir, remove } from "fs-extra/esm"; +import { readFile, rename, rm, writeFile } from "fs/promises"; import path from "node:path"; import { globby } from "globby"; import handlebars from "handlebars"; @@ -9,7 +9,7 @@ import process from "node:process"; import { nodeInfo } from "./nodeInfo.js"; import decompress from "decompress"; import { Spinner } from "./spinner.js"; -import { SupportedPlatforms, SupportedArch, SwankyConfig, ZombienetConfig, Relaychain } from "../types/index.js"; +import { Relaychain, SupportedArch, SupportedPlatforms, SwankyConfig, ZombienetConfig } from "../types/index.js"; import { ConfigError, NetworkError } from "./errors.js"; import { BinaryNames } from "./zombienetInfo.js"; import { zombienetConfig } from "../commands/zombienet/init.js"; @@ -33,18 +33,37 @@ export async function checkCliDependencies(spinner: Spinner) { } } +export function osCheck() { + const platform = process.platform; + const arch = process.arch; + + const supportedPlatforms = ["darwin", "linux"]; + if (!supportedPlatforms.includes(platform)) { + throw new ConfigError(`Could not download swanky-node. Platform ${platform} not supported!`); + } + + const supportedArch = ["x64", "arm64"]; + if (!supportedArch.includes(arch)) { + throw new ConfigError( + `Architecture ${arch} is not supported`, + ); + } + + return { platform, arch }; +} + export async function copyCommonTemplateFiles(templatesPath: string, projectPath: string) { await ensureDir(projectPath); const commonFiles = await globby(`*`, { cwd: templatesPath }); await Promise.all( commonFiles.map(async (file) => { await copy(path.resolve(templatesPath, file), path.resolve(projectPath, file)); - }) + }), ); await rename(path.resolve(projectPath, "gitignore"), path.resolve(projectPath, ".gitignore")); await rename( path.resolve(projectPath, "mocharc.json"), - path.resolve(projectPath, ".mocharc.json") + path.resolve(projectPath, ".mocharc.json"), ); await copy(path.resolve(templatesPath, "github"), path.resolve(projectPath, ".github")); } @@ -52,15 +71,15 @@ export async function copyCommonTemplateFiles(templatesPath: string, projectPath export async function copyContractTemplateFiles( contractTemplatePath: string, contractName: string, - projectPath: string + projectPath: string, ) { await copy( path.resolve(contractTemplatePath, "contract"), - path.resolve(projectPath, "contracts", contractName) + path.resolve(projectPath, "contracts", contractName), ); await copy( path.resolve(contractTemplatePath, "test"), - path.resolve(projectPath, "tests", contractName) + path.resolve(projectPath, "tests", contractName), ); } @@ -85,13 +104,13 @@ export async function downloadNode(projectPath: string, nodeInfo: nodeInfo, spin const platformDlUrls = nodeInfo.downloadUrl[process.platform as SupportedPlatforms]; if (!platformDlUrls) throw new ConfigError( - `Could not download swanky-node. Platform ${process.platform} not supported!` + `Could not download swanky-node. Platform ${process.platform} not supported!`, ); const dlUrl = platformDlUrls[process.arch as SupportedArch]; if (!dlUrl) throw new ConfigError( - `Could not download swanky-node. Platform ${process.platform} Arch ${process.arch} not supported!` + `Could not download swanky-node. Platform ${process.platform} Arch ${process.arch} not supported!`, ); const dlFileDetails = await new Promise((resolve, reject) => { @@ -108,7 +127,7 @@ export async function downloadNode(projectPath: string, nodeInfo: nodeInfo, spin }); dl.start().catch((error: Error) => - reject(new Error(`Error downloading node: , ${error.message}`)) + reject(new Error(`Error downloading node: , ${error.message}`)), ); }); @@ -128,13 +147,15 @@ export async function downloadNode(projectPath: string, nodeInfo: nodeInfo, spin return path.resolve(binPath, dlFileDetails.filePath); } + export async function copyZombienetTemplateFile(templatePath: string, configPath: string) { await ensureDir(configPath); await copy( path.resolve(templatePath, zombienetConfig), - path.resolve(configPath, zombienetConfig) + path.resolve(configPath, zombienetConfig), ); } + export async function downloadZombienetBinaries(binaries: string[], projectPath: string, swankyConfig: SwankyConfig, spinner: Spinner) { const binPath = path.resolve(projectPath, "zombienet", "bin"); await ensureDir(binPath); @@ -152,29 +173,29 @@ export async function downloadZombienetBinaries(binaries: string[], projectPath: const platformDlUrls = zombienetInfo.downloadUrl[process.platform as SupportedPlatforms]; if (!platformDlUrls) throw new ConfigError( - `Could not download ${binaryName}. Platform ${process.platform} not supported!` + `Could not download ${binaryName}. Platform ${process.platform} not supported!`, ); let dlUrl = platformDlUrls[process.arch as SupportedArch]; if (!dlUrl) throw new ConfigError( - `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` + `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!`, ); dlUrl = dlUrl.replace("${version}", version); dlUrls.set(binaryName, dlUrl); } - for(const binaryName of Object.keys(zombienetInfo.binaries).filter((binaryName) => binaries.includes(binaryName))){ + 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]; if (!platformDlUrls) throw new ConfigError( - `Could not download ${binaryName}. Platform ${process.platform} not supported!` + `Could not download ${binaryName}. Platform ${process.platform} not supported!`, ); let dlUrl = platformDlUrls[process.arch as SupportedArch]; if (!dlUrl) throw new ConfigError( - `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!` + `Could not download ${binaryName}. Platform ${process.platform} Arch ${process.arch} not supported!`, ); dlUrl = dlUrl.replace(/\$\{version}/gi, version); dlUrls.set(binaryName, dlUrl); @@ -195,7 +216,7 @@ export async function downloadZombienetBinaries(binaries: string[], projectPath: }); dl.start().catch((error: Error) => - reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)) + reject(new Error(`Error downloading ${binaryName}: , ${error.message}`)), ); }); @@ -212,9 +233,8 @@ export async function downloadZombienetBinaries(binaries: string[], projectPath: fileName = decompressed[0].path; } - if(fileName !== binaryName) - { - await execaCommand(`mv ${binPath}/${fileName} ${binPath}/${binaryName}`) + if (fileName !== binaryName) { + await execaCommand(`mv ${binPath}/${fileName} ${binPath}/${binaryName}`); } await execaCommand(`chmod +x ${binPath}/${binaryName}`); } @@ -224,30 +244,30 @@ export async function buildZombienetConfigFromBinaries(binaries: string[], templ await ensureDir(configPath); const configBuilder = { settings: { - timeout: 1000 + timeout: 1000, }, - relaychain:{ + relaychain: { default_command: "", chain: "", - nodes: [] + nodes: [], }, - parachains:[] + parachains: [], } as ZombienetConfig; for (const binaryName of binaries) { - const template = TOML.parse(readFileSync(path.resolve(templatePath, binaryName+".toml"), "utf8")); - if(template.parachains !== undefined) { + const template = TOML.parse(readFileSync(path.resolve(templatePath, binaryName + ".toml"), "utf8")); + if (template.parachains !== undefined) { (template.parachains as any).forEach((parachain: any) => { configBuilder.parachains.push(parachain); }); } - if(template.hrmp_channels !== undefined) { + if (template.hrmp_channels !== undefined) { configBuilder.hrmp_channels = []; (template.hrmp_channels as any).forEach((hrmp_channel: any) => { configBuilder.hrmp_channels!.push(hrmp_channel); }); } - if(template.relaychain !== undefined) { + if (template.relaychain !== undefined) { configBuilder.relaychain = template.relaychain as unknown as Relaychain; } diff --git a/src/lib/zombienetInfo.ts b/src/lib/zombienetInfo.ts index 8e30ed9b..62a53c68 100644 --- a/src/lib/zombienetInfo.ts +++ b/src/lib/zombienetInfo.ts @@ -1,6 +1,7 @@ export type zombienetInfo = typeof zombienet; -export type BinaryNames = "zombienet" | "polkadot" | "astar-collator"; +export type BinaryNames = "zombienet" | "polkadot" | "polkadot-parachain" | "astar-collator"; + export const zombienet = { version: "1.3.89", downloadUrl: { @@ -54,4 +55,6 @@ export const zombienet = { }, }, }, -}; \ No newline at end of file +}; + +export const zombienetBinariesList = Object.keys(zombienet.binaries); From 5085625beef035f2b9df42bbd6f134445a8f45be Mon Sep 17 00:00:00 2001 From: Igor Papandinas Date: Tue, 20 Feb 2024 18:03:26 +0100 Subject: [PATCH 7/9] fix: osCheck refactored --- src/commands/zombienet/init.ts | 2 +- src/lib/tasks.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index e78469c8..10b259e2 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -34,7 +34,7 @@ export class InitZombienet extends SwankyCommand { 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).`); +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(); diff --git a/src/lib/tasks.ts b/src/lib/tasks.ts index f200b436..0c011323 100644 --- a/src/lib/tasks.ts +++ b/src/lib/tasks.ts @@ -37,15 +37,19 @@ export function osCheck() { const platform = process.platform; const arch = process.arch; - const supportedPlatforms = ["darwin", "linux"]; - if (!supportedPlatforms.includes(platform)) { - throw new ConfigError(`Could not download swanky-node. Platform ${platform} not supported!`); + const supportedConfigs = { + darwin: ["x64", "arm64"], + linux: ["x64", "arm64"], + }; + + if (!(platform in supportedConfigs)) { + throw new ConfigError(`Platform '${platform}' is not supported!`); } - const supportedArch = ["x64", "arm64"]; - if (!supportedArch.includes(arch)) { + const supportedArchs = supportedConfigs[platform as keyof typeof supportedConfigs]; + if (!supportedArchs.includes(arch)) { throw new ConfigError( - `Architecture ${arch} is not supported`, + `Architecture '${arch}' is not supported on platform '${platform}'.` ); } From c1c4c9ca72e26ea130471a6deb0e19b89334b20c Mon Sep 17 00:00:00 2001 From: Igor Papandinas Date: Tue, 20 Feb 2024 18:20:10 +0100 Subject: [PATCH 8/9] chore: Darwin binaries download url removed for polkadot and polkadot-parachain --- src/lib/zombienetInfo.ts | 8 -------- src/types/index.ts | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/lib/zombienetInfo.ts b/src/lib/zombienetInfo.ts index 62a53c68..3b6b0faf 100644 --- a/src/lib/zombienetInfo.ts +++ b/src/lib/zombienetInfo.ts @@ -18,10 +18,6 @@ export const zombienet = { "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", @@ -31,10 +27,6 @@ export const zombienet = { "polkadot-parachain": { version: "0.9.430", downloadUrl: { - darwin: { - "arm64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", - "x64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", - }, linux: { "arm64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", "x64": "https://github.com/paritytech/cumulus/releases/download/v${version}/polkadot-parachain", diff --git a/src/types/index.ts b/src/types/index.ts index 0d18333c..423c73c6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -64,7 +64,7 @@ export interface SwankyConfig { interface ZombienetData { version: string; downloadUrl: DownloadUrl; - binaries: Record; + binaries: Record }>; } export interface ZombienetConfig { From 9e1a930af245b22cc6ca76dcc8f27fae2fa17fdf Mon Sep 17 00:00:00 2001 From: Igor Papandinas Date: Tue, 27 Feb 2024 12:32:56 +0100 Subject: [PATCH 9/9] fix: Adjust zombienet --- src/commands/zombienet/init.ts | 2 +- src/templates/zombienet/polkadot.toml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/zombienet/init.ts b/src/commands/zombienet/init.ts index 3208001a..cea138f8 100644 --- a/src/commands/zombienet/init.ts +++ b/src/commands/zombienet/init.ts @@ -80,7 +80,7 @@ As a result users of MacOS need to clone the Polkadot repo (https://github.com/p const configPath = path.resolve(projectPath, "zombienet", "config"); - if (flags.binaries.length < 2) { + if (flags.binaries.length === 1 && flags.binaries[0] === "polkadot") { await spinner.runCommand( () => copyZombienetTemplateFile(zombienetTemplatePath, configPath), diff --git a/src/templates/zombienet/polkadot.toml b/src/templates/zombienet/polkadot.toml index 5c34a309..9538d660 100644 --- a/src/templates/zombienet/polkadot.toml +++ b/src/templates/zombienet/polkadot.toml @@ -1,3 +1,6 @@ +[settings] +timeout = 1000 + [relaychain] default_command = "./zombienet/bin/polkadot" chain = "rococo-local"