From 19d95d9a49859664be03b2a4b09e5a7ee17b8fae Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 27 Jul 2016 10:25:13 -0300 Subject: [PATCH] ref tests --- lib/server.js | 5 +- test/integration/server.js | 202 ++++++++++++++++++++----------------- 2 files changed, 112 insertions(+), 95 deletions(-) diff --git a/lib/server.js b/lib/server.js index 9e80cef..9c22a34 100644 --- a/lib/server.js +++ b/lib/server.js @@ -2788,10 +2788,9 @@ WalletService.prototype.getTxHistory = function(opts, cb) { bc.getTransactions(addressStrs, from, to, function(err, txs, total) { if (err) return cb(err); var txsNormalized = self._normalizeTxHistory(txs); - next(err, txsNormalized); if (addresses.length < Defaults.HISTORY_CACHE_ADDRESS_THRESOLD) - return; + return next(err, txsNormalized); var txsToCache = _.filter(txsNormalized, function(i) { return i.confirmations >= Defaults.CONFIRMATIONS_TO_START_CACHING; @@ -2799,7 +2798,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { var index = total - to; if (index < 0) index = 0; self.storage.storeTxHistoryCache(self.walletId, total, index, txsToCache, function(err) { - if (err) log.warn(err); + next(err, txsNormalized); }) }); }, diff --git a/test/integration/server.js b/test/integration/server.js index 1bf91c8..da5bad2 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -5895,7 +5895,7 @@ describe('Wallet service', function() { }); }); - describe.only('#getTxHistory', function() { + describe('#getTxHistory', function() { var server, wallet, mainAddresses, changeAddresses; beforeEach(function(done) { helpers.createAndJoinWallet(1, 1, function(s, w) { @@ -5924,97 +5924,6 @@ describe('Wallet service', function() { }); }); - it('should store partial cache tx history from insight', function(done) { - var h = helpers.historyCacheTest(200); - helpers.stubHistory(h); - var spy = sinon.spy(server.storage, 'storeTxHistoryCache'); - var toCache = _.filter(h, function(i) { - return i.confirmations >= server.confirmationsToStartCaching; - }); - var skip = 95; - var limit = 10; - - server.getTxHistory({ - skip: skip, - limit: limit, - }, function(err, txs) { - - // FROM the END, we are getting items - // End-1, end-2, end-3. - - should.not.exist(err); - should.exist(txs); - txs.length.should.equal(limit); - var calls = spy.getCalls(); - calls.length.should.equal(1); - - calls[0].args[1].should.equal(200); // total - calls[0].args[2].should.equal(200 - skip - limit); // position - calls[0].args[3].length.should.equal(5); // 5 txs have confirmations>= 100 - - // should be reversed! - calls[0].args[3][0].confirmations.should.equal(104); - calls[0].args[3][0].txid.should.equal(h[104].txid); - server.storage.storeTxHistoryCache.restore(); - done(); - }); - }); - - - it('should not cache tx history from insight', function(done) { - var h = helpers.historyCacheTest(200); - helpers.stubHistory(h); - var spy = sinon.spy(server.storage, 'storeTxHistoryCache'); - server.getTxHistory({ - skip:0, - limit: 10, - }, function(err, txs) { - should.not.exist(err); - should.exist(txs); - var calls = spy.getCalls(); - calls.length.should.equal(1); - calls[0].args[3].length.should.equal(0); - server.storage.storeTxHistoryCache.restore(); - done(); - }); - }); - - - it('should store cache all tx history from insight', function(done) { - var h = helpers.historyCacheTest(200); - helpers.stubHistory(h); - var spy = sinon.spy(server.storage, 'storeTxHistoryCache'); - var toCache = _.filter(h, function(i) { - return i.confirmations >= server.confirmationsToStartCaching; - }); - var skip = 195; - var limit = 5; - - server.getTxHistory({ - skip: skip, - limit: limit, - }, function(err, txs) { - - should.not.exist(err); - should.exist(txs); - txs.length.should.equal(limit); - var calls = spy.getCalls(); - calls.length.should.equal(1); - - calls[0].args[1].should.equal(200); // total - calls[0].args[2].should.equal(200 - skip - limit); // position - calls[0].args[3].length.should.equal(5); - - // should be reversed! - calls[0].args[3][0].confirmations.should.equal(199); - calls[0].args[3][0].txid.should.equal(h[199].txid); - server.storage.storeTxHistoryCache.restore(); - done(); - }); - }); - - - it('should get tx history for incoming txs', function(done) { server._normalizeTxHistory = sinon.stub().returnsArg(0); var txs = [{ @@ -6310,6 +6219,115 @@ describe('Wallet service', function() { }); }); + describe('#getTxHistory cache', function() { + var server, wallet, mainAddresses, changeAddresses; + var _threshold = Defaults.HISTORY_CACHE_ADDRESS_THRESOLD; + beforeEach(function(done) { + Defaults.HISTORY_CACHE_ADDRESS_THRESOLD = 1; + helpers.createAndJoinWallet(1, 1, function(s, w) { + server = s; + wallet = w; + helpers.createAddresses(server, wallet, 1, 1, function(main, change) { + mainAddresses = main; + changeAddresses = change; + done(); + }); + }); + }); + afterEach(function() { + Defaults.HISTORY_CACHE_ADDRESS_THRESOLD = _threshold; + }); + + it('should store partial cache tx history from insight', function(done) { + var h = helpers.historyCacheTest(200); + helpers.stubHistory(h); + var spy = sinon.spy(server.storage, 'storeTxHistoryCache'); + var toCache = _.filter(h, function(i) { + return i.confirmations >= server.confirmationsToStartCaching; + }); + var skip = 95; + var limit = 10; + + server.getTxHistory({ + skip: skip, + limit: limit, + }, function(err, txs) { + + // FROM the END, we are getting items + // End-1, end-2, end-3. + + should.not.exist(err); + should.exist(txs); + txs.length.should.equal(limit); + var calls = spy.getCalls(); + calls.length.should.equal(1); + + calls[0].args[1].should.equal(200); // total + calls[0].args[2].should.equal(200 - skip - limit); // position + calls[0].args[3].length.should.equal(5); // 5 txs have confirmations>= 100 + + // should be reversed! + calls[0].args[3][0].confirmations.should.equal(104); + calls[0].args[3][0].txid.should.equal(h[104].txid); + server.storage.storeTxHistoryCache.restore(); + done(); + }); + }); + + + it('should not cache tx history from insight', function(done) { + var h = helpers.historyCacheTest(200); + helpers.stubHistory(h); + var spy = sinon.spy(server.storage, 'storeTxHistoryCache'); + server.getTxHistory({ + skip: 0, + limit: 10, + }, function(err, txs) { + should.not.exist(err); + should.exist(txs); + var calls = spy.getCalls(); + calls.length.should.equal(1); + calls[0].args[3].length.should.equal(0); + server.storage.storeTxHistoryCache.restore(); + done(); + }); + }); + + + it('should store cache all tx history from insight', function(done) { + var h = helpers.historyCacheTest(200); + helpers.stubHistory(h); + var spy = sinon.spy(server.storage, 'storeTxHistoryCache'); + var toCache = _.filter(h, function(i) { + return i.confirmations >= server.confirmationsToStartCaching; + }); + var skip = 195; + var limit = 5; + + server.getTxHistory({ + skip: skip, + limit: limit, + }, function(err, txs) { + + should.not.exist(err); + should.exist(txs); + txs.length.should.equal(limit); + var calls = spy.getCalls(); + calls.length.should.equal(1); + + calls[0].args[1].should.equal(200); // total + calls[0].args[2].should.equal(200 - skip - limit); // position + calls[0].args[3].length.should.equal(5); + + // should be reversed! + calls[0].args[3][0].confirmations.should.equal(199); + calls[0].args[3][0].txid.should.equal(h[199].txid); + server.storage.storeTxHistoryCache.restore(); + done(); + }); + }); + }); + describe('#scan', function() { var server, wallet;