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 17, 2018
1 parent 2869583 commit ba83746
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"devDependencies": {
"eslint": "^5.1.0",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^5.2.0"
"mocha": "^5.2.0",
"mockdate": "^2.0.2"
},
"main": "./lib/bcoin.js",
"bin": {
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 ba83746

Please sign in to comment.