-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathcreateTestnets.js
More file actions
103 lines (86 loc) · 2.43 KB
/
createTestnets.js
File metadata and controls
103 lines (86 loc) · 2.43 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const axios = require('axios');
const { ethers } = require('ethers');
const { BB_BACKEND_URL, BB_API_KEY } = require('./constants');
const {
confirmAndStoreNodeData,
clearNodesFile,
getUserDetails,
} = require('./helpers');
async function createTestnet(apiKey, createdNodes, aliveNodes) {
const data = JSON.stringify({
allowUnlimitedContractSize: false,
mining: { auto: true, interval: 0 },
accounts: {
mnemonic: ethers.Wallet.createRandom().mnemonic.phrase,
},
options: {
hardhat: {
mine: true,
stopImpersonatingAccount: true,
impersonateAccount: true
},
evm: {
mine: true,
increaseTime: true,
setNextBlockTimestamp: true,
revert: true,
snapshot: true
},
extra: { overrideGas: true }
}
});
const config = {
method: 'post',
url: `${BB_BACKEND_URL}/user/container`,
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
data,
};
let node;
try {
const response = await axios(config);
const resData = response.data;
if (response.status === 200) {
node = { nodeId: resData.nodeId };
} else {
console.log('Error in creating node, Error: ', resData);
}
} catch (err) {
console.log('Error in creating node, Error: ', err);
}
if (node) {
confirmAndStoreNodeData(node, apiKey, aliveNodes);
createdNodes.push(node);
}
}
async function createTestnets() {
// await getUserDetails();
const ora = (await import('ora')).default;
const createNodeSpinner = ora(`Creating testnets on Buildbear...`).start();
const aliveNodes = [0];
const createdNodes = [];
const noOfNodes = 5;
// clear nodes.json before creating new nodes
await clearNodesFile();
// loop to create testnets
while (true) {
if (createdNodes.length == noOfNodes) {
createNodeSpinner.succeed('Testnets created on Buildbear');
break;
}
await createTestnet(BB_API_KEY, createdNodes, aliveNodes);
}
console.log('Created nodes..');
console.log(createdNodes);
const waitAliveNodesSpinner = ora(`Waiting for nodes to be live...`).start();
// interval to check whether nodes are live
const waitAliveNodesInterval = setInterval(() => {
if (aliveNodes[0] === noOfNodes) {
waitAliveNodesSpinner.succeed('All nodes are live');
clearInterval(waitAliveNodesInterval);
}
}, 100);
}
createTestnets();