Skip to content

Commit

Permalink
rpc: add uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
slashrsm committed Aug 14, 2018
1 parent 4210033 commit 30ba1b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/node/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ class HTTP extends Server {
});
});

this.get('/uptime', async (req, res) => {
res.json(200, { uptime: this.node.uptime().toString()});
});

// UTXO by address
this.get('/coin/address/:address', async (req, res) => {
const valid = Validator.fromRequest(req);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"istanbul": "^1.1.0-alpha.1",
"jsdoc": "^3.5.5",
"mocha": "^5.2.0",
"mockdate": "^2.0.2",
"uglify-es": "^3.3.9",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.11.1",
Expand Down
13 changes: 13 additions & 0 deletions test/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ describe('HTTP', function() {
assert.strictEqual(info.chain.height, 0);
});

it('should get uptime', async () => {
const MockDate = require('mockdate');
const mockedNow = 1225476600;
MockDate.set(mockedNow * 1000);

node.startTime = (mockedNow - 100) * 1000;
const uptime = await nclient.getUptime();
assert.strictEqual(uptime.uptime, '100');

MockDate.reset();
node.startTime = -1;
});

it('should get wallet info', async () => {
const info = await wallet.getInfo();
assert.strictEqual(info.id, 'test');
Expand Down

0 comments on commit 30ba1b6

Please sign in to comment.