improve # of confirmations tests

This commit is contained in:
Ivan Socolsky 2016-08-08 09:12:04 -03:00
parent f423f8a567
commit 13735829c7
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
1 changed files with 45 additions and 21 deletions

View File

@ -6337,31 +6337,49 @@ describe('Wallet service', function() {
Defaults.CONFIRMATIONS_TO_START_CACHING = 6; Defaults.CONFIRMATIONS_TO_START_CACHING = 6;
var h = helpers.historyCacheTest(20); var h = helpers.historyCacheTest(20);
_.each(h, function(x, i) {
x.blockheight = 100 - i;
});
helpers.stubHistory(h); helpers.stubHistory(h);
var storeTxHistoryCacheSpy = sinon.spy(server.storage, 'storeTxHistoryCache'); var storeTxHistoryCacheSpy = sinon.spy(server.storage, 'storeTxHistoryCache');
var skip = 0;
var limit = 20;
blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 100); blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 100);
// Cache txs
server.getTxHistory({ server.getTxHistory({
skip: skip, skip: 0,
limit: limit, limit: 30,
}, function(err, txs) { }, function(err, txs) {
should.not.exist(err); should.not.exist(err);
should.exist(txs); should.exist(txs);
txs.length.should.equal(limit);
var calls = storeTxHistoryCacheSpy.getCalls(); var calls = storeTxHistoryCacheSpy.getCalls();
calls.length.should.equal(1); calls.length.should.equal(1);
_.first(txs).confirmations.should.equal(82); server.getTxHistory({
_.last(txs).confirmations.should.equal(101); skip: 0,
limit: 30,
}, function(err, txs) {
should.not.exist(err);
txs.length.should.equal(20);
_.first(txs).confirmations.should.equal(1);
_.last(txs).confirmations.should.equal(20);
blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 200);
server.getTxHistory({
skip: 0,
limit: 30,
}, function(err, txs) {
should.not.exist(err);
_.first(txs).confirmations.should.equal(101);
_.last(txs).confirmations.should.equal(120);
server.storage.storeTxHistoryCache.restore(); server.storage.storeTxHistoryCache.restore();
Defaults.CONFIRMATIONS_TO_START_CACHING = _confirmations; Defaults.CONFIRMATIONS_TO_START_CACHING = _confirmations;
done(); done();
}); });
}); });
});
});
it('should get cached # of confirmations if current height unknown', function(done) { it('should get cached # of confirmations if current height unknown', function(done) {
var _confirmations = Defaults.CONFIRMATIONS_TO_START_CACHING; var _confirmations = Defaults.CONFIRMATIONS_TO_START_CACHING;
@ -6370,22 +6388,27 @@ describe('Wallet service', function() {
var h = helpers.historyCacheTest(20); var h = helpers.historyCacheTest(20);
helpers.stubHistory(h); helpers.stubHistory(h);
var storeTxHistoryCacheSpy = sinon.spy(server.storage, 'storeTxHistoryCache'); var storeTxHistoryCacheSpy = sinon.spy(server.storage, 'storeTxHistoryCache');
var skip = 0;
var limit = 20;
var _getLastKnownBlockchainHeight = server._getLastKnownBlockchainHeight; var _getLastKnownBlockchainHeight = server._getLastKnownBlockchainHeight;
server._getLastKnownBlockchainHeight = sinon.stub().callsArgWith(1, null, null); server._getLastKnownBlockchainHeight = sinon.stub().callsArgWith(1, null, null);
// Cache txs
server.getTxHistory({ server.getTxHistory({
skip: skip, skip: 0,
limit: limit, limit: 30,
}, function(err, txs) { }, function(err, txs) {
should.not.exist(err); should.not.exist(err);
should.exist(txs); should.exist(txs);
txs.length.should.equal(limit); txs.length.should.equal(20);
var calls = storeTxHistoryCacheSpy.getCalls(); var calls = storeTxHistoryCacheSpy.getCalls();
calls.length.should.equal(1); calls.length.should.equal(1);
server.getTxHistory({
skip: 0,
limit: 30,
}, function(err, txs) {
should.not.exist(err);
txs.length.should.equal(20);
_.first(txs).confirmations.should.equal(0); _.first(txs).confirmations.should.equal(0);
_.last(txs).confirmations.should.equal(19); _.last(txs).confirmations.should.equal(19);
@ -6395,6 +6418,7 @@ describe('Wallet service', function() {
done(); done();
}); });
}); });
});
describe('Downloading history', function() { describe('Downloading history', function() {
var h; var h;