From ba837462c54584b08817d420d1ee020e801e7760 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Wed, 15 Aug 2018 00:00:27 +0200 Subject: [PATCH] rpc: add uptime --- lib/node/http.js | 4 ++++ package.json | 3 ++- test/http-test.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/node/http.js b/lib/node/http.js index eaedfedd6..15a1f16b0 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -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); diff --git a/package.json b/package.json index 9d89992e5..b152eb33a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/http-test.js b/test/http-test.js index b6772258e..5c5e6430a 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -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');