-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
71 lines (38 loc) · 2.09 KB
/
setup.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
const fs = require('fs');
const path = require('path');
const netRunnerConfigsPath = path.join(__dirname, 'netrunner_configs.json');
const netRunnerConfigs = JSON.parse(fs.readFileSync(netRunnerConfigsPath, 'utf8'));
const directoryForTestnet = path.join(__dirname, `X${netRunnerConfigs.testnetDir}`);
const directoryWithSourceFiles = path.join(__dirname, `files/testnets/${netRunnerConfigs.testnetDir}`);
const copyFile = (src, dest) => fs.copyFileSync(src, dest);
const setupDirectories = () => {
let numberOfNodes = +(netRunnerConfigs.testnetDir.split('V')[1]);
if (!fs.existsSync(directoryForTestnet)) fs.mkdirSync(directoryForTestnet);
for (let i = 1 ; i <= numberOfNodes ; i++) {
// Here will be subdirectories for files for each node in network
const nodeDirectory = path.join(directoryForTestnet, `V${i}`);
if (!fs.existsSync(nodeDirectory)) fs.mkdirSync(nodeDirectory);
// For each subdirectory - create subdirs for genesis and configs
const genesisDir = path.join(nodeDirectory, 'GENESIS');
const configsDir = path.join(nodeDirectory, 'CONFIGS');
if (!fs.existsSync(genesisDir)) fs.mkdirSync(genesisDir);
if (!fs.existsSync(configsDir)) fs.mkdirSync(configsDir);
// ============= 1. Copy genesis
const genesisSrc = path.join(directoryWithSourceFiles, 'genesis.json');
const genesisDest = path.join(genesisDir, 'genesis.json');
copyFile(genesisSrc, genesisDest);
// ============= 2. Copy configs for VMs
let vmsConfigs = ['kly_wvm.json','kly_evm.json'];
vmsConfigs.forEach(file => {
const src = path.join(__dirname, `files/common_files/${file}`);
const dest = path.join(configsDir, file);
copyFile(src, dest);
});
// ============= 3. Copy node configs
const nodeConfigsSrc = path.join(directoryWithSourceFiles, `configs_for_nodes/config_${i}.json`);
const nodeConfigsDest = path.join(configsDir, 'config.json');
copyFile(nodeConfigsSrc, nodeConfigsDest);
}
console.log(`Directories setup complete for testnet size ${netRunnerConfigs.testnetDir}`);
};
setupDirectories();