add status tests
This commit is contained in:
parent
6c276ada49
commit
d67950145c
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
150
test/status.js
Normal file
150
test/status.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user