From 30ba1b61955b4a473b586a6ab3edcd6bb380efd4 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 | 1 + test/http-test.js | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/lib/node/http.js b/lib/node/http.js index 2f75035dd..9c8508594 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 77ba3ba36..9baf8d405 100644 --- a/package.json +++ b/package.json @@ -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", 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');