This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
forked from pbca26/komodo-rpc-lib
-
Notifications
You must be signed in to change notification settings - Fork 3
/
start-mutil-chain.js
90 lines (73 loc) · 2.08 KB
/
start-mutil-chain.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
81
82
83
84
85
86
87
88
89
90
/**
* Use KomodoRPC to start COQUI and KMDICE chain
* How to run:
*
* $ npm run devtest -- examples/start-mutil-chain.js
*/
import KomodoRPC from "../src";
import { coqui, kmdice, getBinPath } from "./config";
const debug = require("debug")("kmdrpc:test:start-mutil-chain");
// function wait(delay) {
// return new Promise(resovle => {
// setTimeout(resovle, delay);
// });
// }
(async () => {
const application = "Agama";
const kmdiceCoin = kmdice.coin;
const kmdiceargs = kmdice.args;
const coquiCoin = coqui.coin;
const coquiargs = coqui.args;
let i = 0;
function end(code, signal) {
debug(`child process terminated due to receipt of signal ${signal}`);
i += 1;
setTimeout(() => {
if (i >= 2) {
process.exit(0);
}
}, 2000);
}
try {
// Step 1: create application
const api = KomodoRPC(application, {
bin: getBinPath()
});
// Step 2: start the chain
const kmdiced = await api.startDaemon(kmdiceCoin);
await kmdiced.start({
args: kmdiceargs
});
const coquid = await api.startDaemon(coquiCoin);
await coquid.start({
args: coquiargs
});
// add event via darmon
kmdiced.on("exit", end);
coquid.on("exit", end);
// Step 3: wait until ready
const kmdicedReady = await kmdiced.waitUntilReady();
debug(`kmdicedReady = ${JSON.stringify(kmdicedReady)}`);
const coquidReady = await coquid.waitUntilReady();
debug(`coquidReady = ${JSON.stringify(coquidReady)}`);
const infoKmdiced = await kmdiced.getInfo();
debug(`infoKmdiced = ${infoKmdiced}`);
const infoCoquid = await coquid.getInfo();
debug(`infoCoquid = ${infoCoquid}`);
// Step 4: stop daemon
let rs = null;
if (kmdiced.isRunning() === true) {
rs = await kmdiced.stop();
debug(`rs.ok === done = ${rs.ok === "done"}`);
}
if (coquid.isRunning() === true) {
rs = await coquid.stop();
debug(`rs.ok === done = ${rs.ok === "done"}`);
}
} catch (err) {
debug(err.message);
setTimeout(() => {
process.exit(1);
}, 2000);
}
})();