Fixed some tests.

This commit is contained in:
Chris Kleeschulte 2017-08-08 10:09:30 -04:00
parent 07a4b706c7
commit 5ff8e7c6c1
2 changed files with 11 additions and 2 deletions

View File

@ -259,7 +259,11 @@ HeaderService.prototype._onHeaders = function(headers) {
HeaderService.prototype._detectReorg = function() {
// is our original tip's height and hash the same after we rewound by the checkpoint amount of blocks
// and re-imported? If so, then we've reorg'ed since we've been shut down.
if (this._originalTip.hash !== this._headers.getIndex(this._originalTip.height).hash) {
var headerHash = this._headers.getIndex(this._originalTip.height).hash;
assert(headerHash, 'Expected a header to exist at height ' + this._originalTip.height);
if (this._originalTip.hash !== headerHash) {
return true;
}
return false;
@ -285,7 +289,7 @@ HeaderService.prototype._onBestHeight = function(height) {
HeaderService.prototype._startSync = function() {
this._numNeeded = this._bestHeight - this._tip.height;
this._numNeeded = Math.max(this._bestHeight - this._tip.height, this._checkpoint);
log.info('Header Service: Gathering: ' + this._numNeeded + ' ' + 'header(s) from the peer-to-peer network.');

View File

@ -109,6 +109,11 @@ describe('Header Service', function() {
headerService._tip = { height: 0 };
headerService._originalTip = { height: 0, hash: header.hash };
headerService._bestHeight = { height: 1 };
headerService._headers = {
getIndex: function() { return { hash: header.hash }; },
getLastIndex: sinon.stub(),
set: sinon.stub()
};
var getChainwork = sandbox.stub(headerService, '_getChainwork').returns(new BN(1));
var headers = [ header ];