Skip to content

Commit 30ba1b6

Browse files
committed
rpc: add uptime
1 parent 4210033 commit 30ba1b6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/node/http.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ class HTTP extends Server {
148148
});
149149
});
150150

151+
this.get('/uptime', async (req, res) => {
152+
res.json(200, { uptime: this.node.uptime().toString()});
153+
});
154+
151155
// UTXO by address
152156
this.get('/coin/address/:address', async (req, res) => {
153157
const valid = Validator.fromRequest(req);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"istanbul": "^1.1.0-alpha.1",
6363
"jsdoc": "^3.5.5",
6464
"mocha": "^5.2.0",
65+
"mockdate": "^2.0.2",
6566
"uglify-es": "^3.3.9",
6667
"uglifyjs-webpack-plugin": "^1.2.5",
6768
"webpack": "^4.11.1",

test/http-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ describe('HTTP', function() {
6969
assert.strictEqual(info.chain.height, 0);
7070
});
7171

72+
it('should get uptime', async () => {
73+
const MockDate = require('mockdate');
74+
const mockedNow = 1225476600;
75+
MockDate.set(mockedNow * 1000);
76+
77+
node.startTime = (mockedNow - 100) * 1000;
78+
const uptime = await nclient.getUptime();
79+
assert.strictEqual(uptime.uptime, '100');
80+
81+
MockDate.reset();
82+
node.startTime = -1;
83+
});
84+
7285
it('should get wallet info', async () => {
7386
const info = await wallet.getInfo();
7487
assert.strictEqual(info.id, 'test');

0 commit comments

Comments
 (0)