Modify network property in config.json to test

To avoid the test nodes to try to connect to the main network,
we need to modify the `config.json` of each node to use the `test`
network

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-08-15 13:25:42 +02:00
committed by Rūdolfs Ošiņš
parent 6a1137a024
commit 18a5d40b0a
2 changed files with 36 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
b456d3a401abf5314598cbede49c4fb2864bdf6f
15b50ce6a544bdb7d22e124d486eeb933456f87e
+35
View File
@@ -14,6 +14,7 @@ import { execa } from "execa";
import * as Process from "./process.js";
import { randomTag } from "@tests/support/support.js";
import { sleep } from "@app/lib/sleep.js";
import { array, boolean, literal, number, object, string, union, z } from "zod";
export type RefsUpdate =
| { updated: { name: string; old: string; new: string } }
@@ -105,6 +106,29 @@ export async function createPeerManager(createParams: {
};
}
export const NodeConfigSchema = object({
node: object({
alias: string(),
peers: union([
object({ type: literal("static") }),
object({ type: literal("dynamic"), target: number() }),
]),
connect: array(string()),
externalAddresses: array(string()),
network: union([literal("main"), literal("test")]),
relay: boolean(),
limits: object({
routingMaxSize: number(),
routingMaxAge: number(),
fetchConcurrency: number(),
}),
policy: union([literal("track"), literal("block")]),
scope: union([literal("trusted"), literal("all")]),
}),
});
export interface NodeConfig extends z.infer<typeof NodeConfigSchema> {}
export class RadiclePeer {
public checkoutPath: string;
public nodeId: string;
@@ -173,6 +197,17 @@ export class RadiclePeer {
};
await execa("rad", ["auth", "--alias", name], { env });
const config = await Fs.readFile(
Path.join(radHome, "config.json"),
"utf-8",
);
const parsedConfig = NodeConfigSchema.parse(JSON.parse(config));
parsedConfig.node.network = "test";
await Fs.writeFile(
Path.join(radHome, "config.json"),
JSON.stringify(parsedConfig),
"utf-8",
);
const { stdout: nodeId } = await execa("rad", ["self", "--nid"], { env });
return new RadiclePeer({