Skip to content

Commit

Permalink
fix override, allowing full and relative path (#38)
Browse files Browse the repository at this point in the history
* fix override, allowing full and relative path

* change name

* change default global timeout
  • Loading branch information
pepoviola authored Dec 20, 2021
1 parent 73bad18 commit 07d18f8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "zombie-net",
"name": "zombienet",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const RPC_HTTP_PORT = 9944;
// The port substrate listens for p2p connections on
export const P2P_PORT = 30333;

export const DEFAULT_GLOBAL_TIMEOUT = 300; // seconds
export const DEFAULT_GLOBAL_TIMEOUT = 1200; // 20 mins
export const DEFAULT_INDIVIDUAL_TEST_TIMEOUT = 10; // seconds
export const DEFAULT_COMMAND = "polkadot";
export const DEFAULT_IMAGE = "parity/substrate:latest";
Expand Down Expand Up @@ -233,6 +233,7 @@ export function generateNetworkSpec(config: LaunchConfig): ComputedNetwork {
}

networkSpec.types = config.types ? config.types : {};
networkSpec.configBasePath = config.configBasePath;

return networkSpec;
}
Expand Down
22 changes: 16 additions & 6 deletions src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
} from "./utils";
import tmp from "tmp-promise";
import fs from "fs";
import { resolve } from "path";
import path, { resolve } from "path";
import { generateParachainFiles } from "./paras";
import { setupChainSpec } from "./providers/k8s";
import { getChainSpecRaw } from "./providers/k8s/chain-spec";
Expand Down Expand Up @@ -104,10 +104,8 @@ export async function start(
fs.openSync(localMagicFilepath, "w");

const zombieWrapperLocalPath = `${tmpDir.path}/${ZOMBIE_WRAPPER}`;
await fs.promises.copyFile(zombieWrapperPath,zombieWrapperLocalPath);

// const zombieWrapperContent = await fs.promises.readFile(zombieWrapperPath);
// await fs.promises.writeFile(zombieWrapperLocalPath, zombieWrapperContent);
const zombieWrapperContent = await fs.promises.readFile(zombieWrapperPath);
await fs.promises.writeFile(zombieWrapperLocalPath, zombieWrapperContent, {mode: 0o755 });

// Define chain name and file name to use.
const chainSpecFileName = `${networkSpec.relaychain.chain}.json`;
Expand Down Expand Up @@ -211,8 +209,20 @@ export async function start(

let finalFilesToCopyToNode = filesToCopyToNodes;
for (const override of node.overrides) {
// let check if local_path is full or relative
let local_real_path = "";
if( fs.existsSync(override.local_path) ){
local_real_path = override.local_path;
} else {
// check relative to config
local_real_path = path.join(networkSpec.configBasePath, override.local_path);
console.log(local_real_path);
if(! fs.existsSync(local_real_path)) throw new Error("Invalid override config, only fullpaths or relative paths (from the config) are allowed");
}

console.log('es: ' +local_real_path);
finalFilesToCopyToNode.push({
localFilePath: override.local_path,
localFilePath: local_real_path,
remoteFilePath: `/cfg/${override.remote_name}`
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ComputedNetwork {
};
parachains: Parachain[];
types: any;
configBasePath: string;
}

export interface Node {
Expand Down Expand Up @@ -118,6 +119,7 @@ export interface LaunchConfig {
relaychain: RelayChainConfig;
parachains: ParachainConfig[];
types: any;
configBasePath: string;
}

export interface Settings {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { format } from "util";
import { LaunchConfig, Node } from "./types";
import toml from "toml";
import { getUniqueName, WAIT_UNTIL_SCRIPT_SUFIX } from "./configManager";
import path from "path";

export async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand Down Expand Up @@ -68,6 +69,7 @@ export function filterConsole(excludePatterns: string[], options?: any) {
}

export function readNetworkConfig(filepath: string): LaunchConfig {
const configBasePath = path.dirname(filepath);
let content = fs.readFileSync(filepath).toString();
let replacements = getReplacementInText(content);

Expand All @@ -88,6 +90,8 @@ export function readNetworkConfig(filepath: string): LaunchConfig {
? JSON.parse(content) //require(filepath)
: toml.parse(content);


config.configBasePath = configBasePath;
return config;
}

Expand Down

0 comments on commit 07d18f8

Please sign in to comment.