diff --git a/lib/services/address/index.js b/lib/services/address/index.js index c39c1459..8a54366b 100644 --- a/lib/services/address/index.js +++ b/lib/services/address/index.js @@ -226,8 +226,7 @@ AddressService.prototype.getAPIMethods = function() { return [ ['getAddressHistory', this, this.getAddressHistory, 2], ['getAddressSummary', this, this.getAddressSummary, 1], - ['getAddressUnspentOutputs', this, this.getAddressUnspentOutputs, 1], - ['syncPercentage', this, this.syncPercentage, 0] + ['getAddressUnspentOutputs', this, this.getAddressUnspentOutputs, 1] ]; }; @@ -363,7 +362,6 @@ AddressService.prototype._onReorg = function(oldBlockList, commonAncestor) { key: tipOps.key, value: tipOps.value }]; - // for every tx, remove the address index key for every input and output for(var i = 0; i < oldBlockList.length; i++) { var block = oldBlockList[i]; @@ -484,7 +482,7 @@ AddressService.prototype._processOutput = function(tx, output, index, opts) { }; -AddressService.prototype._processTransaction = function(opts, tx) { +AddressService.prototype._processTransaction = function(tx, opts) { var self = this; diff --git a/lib/services/transaction/index.js b/lib/services/transaction/index.js index a1c84f14..7cdb5223 100644 --- a/lib/services/transaction/index.js +++ b/lib/services/transaction/index.js @@ -50,7 +50,7 @@ TransactionService.prototype.getTransaction = function(txid, options, callback) var queryMempool = _.isUndefined(options.queryMempool) ? true : options.queryMempool; var key = self.encoding.encodeTransactionKey(txid); - this._db.get(key, function(err, tx) { + self._db.get(key, function(err, tx) { if(err) { return callback(err); @@ -58,7 +58,7 @@ TransactionService.prototype.getTransaction = function(txid, options, callback) if (queryMempool && !tx) { - this._mempool.getTransaction(tx, function(err, memTx) { + self._mempool.getTransaction(tx, function(err, memTx) { if(err) { return callback(err); @@ -75,7 +75,7 @@ TransactionService.prototype.getTransaction = function(txid, options, callback) } else { if (tx) { - tx.confirmations = this._p2p.getBestHeight - tx.__height; + tx.confirmations = self._p2p.getBestHeight - tx.__height; return callback(null, tx); } return callback(); diff --git a/package-lock.json b/package-lock.json index f6412963..7a875484 100644 --- a/package-lock.json +++ b/package-lock.json @@ -382,7 +382,7 @@ } }, "bitcore-p2p": { - "version": "github:bitpay/bitcore-p2p#f537eb86b9759985822f0f35887642040b1165cb", + "version": "github:bitpay/bitcore-p2p#5de3ca9eabc1ad7dbeeb882e5b3f85c5f6a4ed9d", "requires": { "bcoin": "github:bcoin-org/bcoin#ffec8ff2d7e05591d113004ed1aca6e0c4fd1d20", "bitcore-lib": "0.14.0", diff --git a/package.json b/package.json index 3fd4e814..058be28b 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ ], "dependencies": { "async": "^2.5.0", - "bcoin": "bcoin-org/bcoin#master", + "bcoin": "1.0.0-beta.12", "bitcoind-rpc": "^0.6.0", "bitcore-lib": "^0.14", "body-parser": "^1.13.3", diff --git a/test/services/address/index.unit.js b/test/services/address/index.unit.js index e247654c..fb3d94e3 100644 --- a/test/services/address/index.unit.js +++ b/test/services/address/index.unit.js @@ -201,7 +201,8 @@ describe('Address Service', function() { }); - describe('#_Rrorg', function() { + describe('#_onReorg', function() { + it('should reorg', function() { var getAddressString = sandbox.stub().returns('a'); var encodeTip = sandbox.stub().returns({ key: 'key', value: 'value' }); @@ -210,13 +211,12 @@ describe('Address Service', function() { addressService._db = { batch: batch }; utils.getAddressString = getAddressString; utils.encodeTip = encodeTip; - var common = { height: 90 }; + var common = { height: 99 }; var oldList = []; - var newList = []; - addressService._onReorg(oldList, newList, common); + addressService._onReorg(oldList, common); expect(batch.calledOnce).to.be.true; - expect(getAddressString.calledOnce).to.be.true; expect(encodeTip.calledOnce).to.be.true; }); + }); }); diff --git a/test/services/block/index.unit.js b/test/services/block/index.unit.js index 2b63d334..d08c1a6a 100644 --- a/test/services/block/index.unit.js +++ b/test/services/block/index.unit.js @@ -15,7 +15,9 @@ describe('Block Service', function() { var blockService; + var sandbox; beforeEach(function() { + sandbox = sinon.sandbox.create(); blockService = new BlockService({ node: { getNetworkName: function() { return 'regtest'; }, @@ -26,13 +28,21 @@ describe('Block Service', function() { blockService._encoding = new Encoding(new Buffer('0000', 'hex')); }); + afterEach(function() { + sandbox.restore(); + }); + describe('#_blockAlreadyProcessed', function() { it('should detect that a block has already been delivered to us', function() { + var rhash1 = sinon.stub().returns('aa'); + var rhash2 = sinon.stub().returns('bb'); + var block1 = { rhash: rhash1 }; + var block2 = { rhash: rhash2 }; blockService._blockQueue = LRU(1); blockService._blockQueue.set('aa', '00'); - expect(blockService._blockAlreadyProcessed({ hash: 'aa' })).to.be.true; - expect(blockService._blockAlreadyProcessed('bb')).to.be.false; + expect(blockService._blockAlreadyProcessed(block1)).to.be.true; + expect(blockService._blockAlreadyProcessed(block2)).to.be.false; blockService._blockQueue.reset(); }); @@ -42,10 +52,11 @@ describe('Block Service', function() { it('should set the block in the block queue and db', function() { var sandbox = sinon.sandbox.create(); + var rhash = sinon.stub().returns('aa'); var spy1 = sandbox.spy(); var stub1 = sandbox.stub(); blockService._blockQueue = { set: stub1 }; - var block = {}; + var block = { rhash: rhash }; sandbox.stub(blockService, '_getBlockOperations'); blockService._db = { batch: spy1 }; blockService._cacheBlock(block); @@ -56,18 +67,6 @@ describe('Block Service', function() { }); - describe('#_computeChainwork', function() { - - it('should calculate chain work correctly', function() { - var expected = new BN(new Buffer('000000000000000000000000000000000000000000677c7b8122f9902c79f4e0', 'hex')); - var prev = new BN(new Buffer('000000000000000000000000000000000000000000677bd68118a98f8779ea90', 'hex')); - - var actual = blockService._computeChainwork(0x18018d30, prev); - assert(actual.eq(expected), 'not equal: actual: ' + actual + ' expected: ' + expected); - }); - - }); - describe('#_determineBlockState', function() { it('should determine the block in a normal state', function() { @@ -164,7 +163,7 @@ describe('Block Service', function() { describe('#getBlockOverview', function() { it('should get block overview', function() { }); - }; + }); describe('#_getChainwork', function() { diff --git a/test/services/header/index.unit.js b/test/services/header/index.unit.js index d3561ee4..03d2e158 100644 --- a/test/services/header/index.unit.js +++ b/test/services/header/index.unit.js @@ -134,4 +134,16 @@ describe('Header Service', function() { }); }); + describe('#_computeChainwork', function() { + + it('should calculate chain work correctly', function() { + var expected = new BN(new Buffer('000000000000000000000000000000000000000000677c7b8122f9902c79f4e0', 'hex')); + var prev = new BN(new Buffer('000000000000000000000000000000000000000000677bd68118a98f8779ea90', 'hex')); + + var actual = headerService._computeChainwork(0x18018d30, prev); + assert(actual.eq(expected), 'not equal: actual: ' + actual + ' expected: ' + expected); + }); + + }); + });