|
|
@ -5895,7 +5895,7 @@ describe('Wallet service', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#getTxHistory', function() { |
|
|
|
describe.only('#getTxHistory', function() { |
|
|
|
var server, wallet, mainAddresses, changeAddresses; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
@ -5924,16 +5924,19 @@ describe('Wallet service', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should cache tx history from insight', function(done) { |
|
|
|
helpers.stubHistory(TestData.historyToCache); |
|
|
|
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(TestData.historyToCache, function(i) { |
|
|
|
var toCache = _.filter(h, function(i) { |
|
|
|
return i.confirmations >= server.confirmationsToStartCaching; |
|
|
|
}); |
|
|
|
var skip = 1; |
|
|
|
var skip = 95; |
|
|
|
var limit = 10; |
|
|
|
|
|
|
|
server.getTxHistory({ |
|
|
|
skip: skip, |
|
|
|
limit: limit, |
|
|
|
}, function(err, txs) { |
|
|
|
|
|
|
|
// FROM the END, we are getting items
|
|
|
@ -5941,15 +5944,17 @@ describe('Wallet service', function() { |
|
|
|
|
|
|
|
should.not.exist(err); |
|
|
|
should.exist(txs); |
|
|
|
txs.length.should.equal(TestData.historyToCache.length - skip); |
|
|
|
txs.length.should.equal(limit); |
|
|
|
var calls = spy.getCalls(); |
|
|
|
calls.length.should.equal(1); |
|
|
|
calls[0].args[1].should.equal(100); // total
|
|
|
|
calls[0].args[2].should.equal(100 - skip); // position
|
|
|
|
calls[0].args[3].length.should.equal(toCache.length - skip); |
|
|
|
|
|
|
|
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].txid.should.equal(toCache[toCache.length-1].txid); |
|
|
|
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(); |
|
|
|
}); |
|
|
@ -5957,25 +5962,59 @@ describe('Wallet service', function() { |
|
|
|
|
|
|
|
|
|
|
|
it('should not cache tx history from insight', function(done) { |
|
|
|
helpers.stubHistory(TestData.history); |
|
|
|
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 total = _.filter(TestData.history, function(i) { |
|
|
|
var toCache = _.filter(h, function(i) { |
|
|
|
return i.confirmations >= server.confirmationsToStartCaching; |
|
|
|
}); |
|
|
|
server.getTxHistory({}, function(err, txs) { |
|
|
|
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(TestData.history.length); |
|
|
|
txs.length.should.equal(limit); |
|
|
|
var calls = spy.getCalls(); |
|
|
|
calls.length.should.equal(1); |
|
|
|
calls[0].args[1].should.equal(100); |
|
|
|
calls[0].args[2].should.equal(100); |
|
|
|
calls[0].args[3].length.should.deep.equal(total.length); |
|
|
|
|
|
|
|
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 = [{ |
|
|
|