From d67950145c9cb8294827d958120615cea799c993 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 3 Sep 2015 10:45:18 -0400 Subject: [PATCH] add status tests --- lib/status.js | 7 ++- lib/transactions.js | 2 + test/status.js | 150 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 test/status.js diff --git a/lib/status.js b/lib/status.js index 6c3ad94..0209e85 100644 --- a/lib/status.js +++ b/lib/status.js @@ -28,7 +28,10 @@ StatusController.prototype.show = function(req, res) { }; StatusController.prototype.getInfo = function() { - return this.node.services.bitcoind.getInfo(); + var info = this.node.services.bitcoind.getInfo(); + return { + info: info + }; }; StatusController.prototype.getDifficulty = function() { @@ -67,7 +70,7 @@ StatusController.prototype.peer = function(req, res) { StatusController.prototype.version = function(req, res) { var pjson = require('../package.json'); - res.json({ + res.jsonp({ version: pjson.version }); } diff --git a/lib/transactions.js b/lib/transactions.js index 495528f..c08e731 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -136,6 +136,8 @@ TxController.prototype.transformOutput = function(output, index) { }; TxController.prototype.rawTransaction = function(req, res, next, txid) { + var self = this; + this.node.getTransaction(txid, true, function(err, transaction) { if (err && err instanceof self.node.errors.Transaction.NotFound) { return common.handleErrors(null, res); diff --git a/test/status.js b/test/status.js new file mode 100644 index 0000000..0d7e573 --- /dev/null +++ b/test/status.js @@ -0,0 +1,150 @@ +'use strict'; + +var sinon = require('sinon'); +var should = require('should'); +var StatusController = require('../lib/status'); + +describe('Status', function() { + describe('/status', function() { + var info = { + version: 110000, + protocolversion: 70002, + blocks: 548645, + timeoffset: 0, + connections: 8, + difficulty: 21546.906405522557, + testnet: true, + relayfee: 1000, + errors: '' + }; + + var node = { + services: { + bitcoind: { + getInfo: sinon.stub().returns(info) + } + } + }; + + var status = new StatusController(node); + + it('getInfo', function(done) { + var req = { + query: {} + }; + var res = { + jsonp: function(data) { + should.exist(data.info.version); + should.exist(data.info.protocolversion); + should.exist(data.info.blocks); + should.exist(data.info.timeoffset); + should.exist(data.info.connections); + should.exist(data.info.difficulty); + should.exist(data.info.testnet); + should.exist(data.info.relayfee); + done(); + } + }; + + status.show(req, res); + }); + + it('getDifficulty', function(done) { + var req = { + query: { + q: 'getDifficulty' + } + }; + var res = { + jsonp: function(data) { + data.difficulty.should.equal(info.difficulty); + done(); + } + }; + + status.show(req, res); + }); + }); + + describe('/sync', function() { + it('should have correct data', function(done) { + var node = { + services: { + db: { + tip: { + __height: 500000 + } + }, + bitcoind: { + height: 500000, + isSynced: sinon.stub().returns(true) + } + } + }; + + var expected = { + status: 'finished', + blockChainHeight: 500000, + syncPercentage: 100, + height: 500000, + error: null, + type: 'bitcore node' + }; + + var status = new StatusController(node); + + var req = {}; + var res = { + jsonp: function(data) { + should(data).eql(expected); + done(); + } + }; + status.sync(req, res); + }); + }); + + describe('/peer', function() { + it('should have correct data', function(done) { + var node = {}; + + var expected = { + connected: true, + host: '127.0.0.1', + port: null + }; + + var req = {}; + var res = { + jsonp: function(data) { + should(data).eql(expected); + done(); + } + }; + + var status = new StatusController(node); + + status.peer(req, res); + }); + }); + + describe('/version', function() { + it('should have correct data', function(done) { + var node = {}; + var expected = { + version: '0.3.0' + }; + + var req = {}; + var res = { + jsonp: function(data) { + should(data).eql(expected); + done(); + } + }; + + var status = new StatusController(node); + status.version(req, res); + }); + }); +}); \ No newline at end of file