-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
80 lines (40 loc) · 1.61 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require('fs');
const {spawn} = require('child_process');
const path = require('path');
const netRunnerConfigsPath = path.join(__dirname, 'netrunner_configs.json');
const netRunnerConfigs = JSON.parse(fs.readFileSync(netRunnerConfigsPath, 'utf8'));
const CORE_PATH = netRunnerConfigs.corePath;
const KLY_MODE = netRunnerConfigs.mode;
// Directory with subdirs for nodes
const baseDir = path.join(__dirname,`X${netRunnerConfigs.testnetDir}`);
// Set full pathes to dirs
let NODES_DIRS = [`${baseDir}/V1`, `${baseDir}/V2`];
if(netRunnerConfigs.testnetDir==='TESTNET_V5'){
NODES_DIRS = [];
for(let i = 1; i <= 5 ; i++) {
NODES_DIRS.push(`${baseDir}/V${i}`);
}
} else if (netRunnerConfigs.testnetDir==='TESTNET_V21'){
NODES_DIRS = [];
for(let i = 1; i <= 21 ; i++) {
NODES_DIRS.push(`${baseDir}/V${i}`);
}
}
const childProcesses = [];
// Main function to run nodes as a subprocesses
function runKlyntarWithEnv(pathToChainDirectory) {
const env = { ...process.env, SYMBIOTE_DIR: pathToChainDirectory, KLY_MODE }; // set process env vars
const klyntarProcess = spawn('node',[CORE_PATH], { env });
childProcesses.push(klyntarProcess);
// Handlers to work with IO
klyntarProcess.stdout.on('data', (data) => {
console.log(`[${pathToChainDirectory}]: ${data}`);
});
klyntarProcess.stderr.on('data', (data) => {
console.error(`[${pathToChainDirectory}]: ${data}`);
});
klyntarProcess.on('close', (code) => {
console.log(`[${pathToChainDirectory}]: ${code}`);
});
}
NODES_DIRS.forEach(runKlyntarWithEnv);