UNPKG

@zombienet/orchestrator

Version:

ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks

106 lines (105 loc) 4.85 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setSubstrateCliArgsVersion = void 0; const utils_1 = require("@zombienet/utils"); const providers_1 = require("./providers"); const sharedTypes_1 = require("./sharedTypes"); const network_1 = require("./network"); const debug = require("debug")("zombie::substrateCliArgsVersion"); const setSubstrateCliArgsVersion = (network, client) => __awaiter(void 0, void 0, void 0, function* () { const { getCliArgsHelp } = (0, providers_1.getProvider)(client.providerName); // Calculate substrate cli version for each node // and set in the node to use later when we build the cmd. const imgCmdMap = new Map(); network.relaychain.nodes.reduce((memo, node) => { if (node.substrateCliArgsVersion) return memo; const uniq_image_cmd = `${node.image}_${node.command}`; if (!memo.has(uniq_image_cmd)) memo.set(uniq_image_cmd, { image: node.image, command: node.command, scope: network_1.Scope.RELAY, }); return memo; }, imgCmdMap); network.parachains.reduce((memo, parachain) => { for (const collator of parachain.collators) { if (collator.substrateCliArgsVersion) return memo; const uniq_image_cmd = `${collator.image}_${collator.command}`; if (!memo.has(uniq_image_cmd)) memo.set(uniq_image_cmd, { image: collator.image, command: collator.command, scope: network_1.Scope.PARA, }); } return memo; }, imgCmdMap); // check versions in series const promiseGenerators = []; for (const [, v] of imgCmdMap) { const getVersionPromise = () => __awaiter(void 0, void 0, void 0, function* () { const helpStdout = yield getCliArgsHelp(v.image, v.command); const version = yield getCliArgsVersion(helpStdout, v.scope); v.version = version; return version; }); promiseGenerators.push(getVersionPromise); } yield (0, utils_1.series)(promiseGenerators, 4); // now we need to iterate and set in each node the version // IFF is not set for (const node of network.relaychain.nodes) { if (node.substrateCliArgsVersion) continue; const uniq_image_cmd = `${node.image}_${node.command}`; node.substrateCliArgsVersion = imgCmdMap.get(uniq_image_cmd).version; } for (const parachain of network.parachains) { for (const collator of parachain.collators) { if (collator.substrateCliArgsVersion) continue; const uniq_image_cmd = `${collator.image}_${collator.command}`; collator.substrateCliArgsVersion = imgCmdMap.get(uniq_image_cmd).version; } } }); exports.setSubstrateCliArgsVersion = setSubstrateCliArgsVersion; function getCliArgsVersion(helpStdout, scope) { // IFF stdout includes `ws-port` flag we are always in V0 if (helpStdout.includes("--ws-port <PORT>")) { debug(`returning cliArgsVersion ${sharedTypes_1.SubstrateCliArgsVersion.V0}`); return sharedTypes_1.SubstrateCliArgsVersion.V0; } // If not, we should check the scope if (scope == network_1.Scope.RELAY) { const version = !helpStdout.includes("--insecure-validator-i-know-what-i-do") ? sharedTypes_1.SubstrateCliArgsVersion.V1 : sharedTypes_1.SubstrateCliArgsVersion.V2; debug(`returning cliArgsVersion ${version}`); return version; } else if (scope == network_1.Scope.PARA) { const version = !helpStdout.includes("export-genesis-head") ? sharedTypes_1.SubstrateCliArgsVersion.V2 : sharedTypes_1.SubstrateCliArgsVersion.V3; debug(`returning cliArgsVersion ${version}`); return version; } else { debug(`returning default cliArgsVersion`); // For other scopes we just return the latest version. return sharedTypes_1.SubstrateCliArgsVersion.V3; } }