Merge pull request #897 from yemel/feature/test-performance

Improve performance of index discovery tests
This commit is contained in:
Gustavo Maximiliano Cortez 2014-07-10 18:09:13 -03:00
commit 28bc387ee6
1 changed files with 34 additions and 5 deletions

View File

@ -778,20 +778,49 @@ describe('Wallet model', function() {
return index <= 14 && index % 2 == 0; return index <= 14 && index % 2 == 0;
}); });
w.updateIndexes(function(err) { var updateIndex = sinon.stub(w, 'updateIndex', function(i, cb) { cb(); });
w.publicKeyRing.getIndex(0).receiveIndex.should.equal(15);
w.publicKeyRing.getIndex(0).changeIndex.should.equal(15);
w.publicKeyRing.getIndex(1).receiveIndex.should.equal(0); w.updateIndexes(function(err) {
w.publicKeyRing.getIndex(1).changeIndex.should.equal(0); // check updated all indexes
var cosignersChecked = []
updateIndex.args.forEach(function(i){
cosignersChecked.indexOf(i[0].cosigner).should.equal(-1);
cosignersChecked.push(i[0].cosigner);
});
sinon.assert.callCount(updateIndex, 4);
w.updateIndex.restore();
done(); done();
}); });
}); });
it('#updateIndex should update correctly', function(done) {
mockFakeActivity(function(index) {
return index <= 14 && index % 2 == 0;
});
var indexDiscovery = sinon.stub(w, 'indexDiscovery', function(a, b, c, d, cb) { cb(null, 8); });
var index = {
changeIndex: 1,
receiveIndex: 2,
cosigner: 2,
}
w.updateIndex(index, function(err) {
index.receiveIndex.should.equal(9);
index.changeIndex.should.equal(9);
indexDiscovery.callCount.should.equal(2);
w.indexDiscovery.restore();
done();
});
});
it('#updateIndexes should store wallet', function(done) { it('#updateIndexes should store wallet', function(done) {
mockFakeActivity(function(index) { mockFakeActivity(function(index) {
return index <= 14 && index % 2 == 0; return index <= 14 && index % 2 == 0;
}); });
var indexDiscovery = sinon.stub(w, 'indexDiscovery', function(a, b, c, d, cb) { cb(null, 8); });
var spyStore = sinon.spy(w, 'store'); var spyStore = sinon.spy(w, 'store');
w.updateIndexes(function(err) { w.updateIndexes(function(err) {
sinon.assert.callCount(spyStore, 1); sinon.assert.callCount(spyStore, 1);