ref tests
This commit is contained in:
parent
63e6847767
commit
19d95d9a49
|
@ -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);
|
||||
})
|
||||
});
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue