Compare commits

...

19 commits

Author SHA1 Message Date
Brendon Duncan
4692e0d91d Unit test case for 2 items in cache and that being all of the transactions. 2018-09-26 22:38:29 +12:00
Brendon Duncan
9cfc05dedd Unit test cases to cover confirmations increasing, and insufficient overlap. 2018-09-26 22:05:31 +12:00
Brendon Duncan
5825ff26b8 A few more test cases. 2018-09-26 21:50:42 +12:00
Brendon Duncan
2d0e5c5f79 Started on unit tests for wallet history. 2018-09-26 18:24:24 +12:00
Brendon Duncan
d68870f743 Bugfix for getting wallet history when cache is empty, while still enforcing overlap in transactions when cache contains transactions, to ensure no transactions are missed. 2018-09-26 18:03:14 +12:00
Sebastiaan Pasma
fb41fca601
Also apply fix to addLatestTransactions function 2018-09-24 17:13:28 +02:00
Jean-Baptiste Dominguez
8039ea26da Merge branch 'wallet/task/593' of https://github.com/Bitcoin-com/Wallet into wallet/task/593 2018-09-24 16:54:53 +02:00
Jean-Baptiste Dominguez
5401bf9a09 Fix the case where the cache is empty 2018-09-24 16:54:40 +02:00
Jean-Baptiste Dominguez
9f904bb098
Merge pull request #358 from Bitcoin-com/wallet/sprint/21
android fix
2018-09-24 12:32:56 +02:00
Jean-Baptiste Dominguez
37596c3a25
Merge pull request #355 from Bitcoin-com/wallet/task/595
595 - Get Android build working again
2018-09-24 12:29:24 +02:00
Jean-Baptiste Dominguez
dbe920a67b
Merge pull request #357 from Bitcoin-com/wallet/task/546
546 - Bugfix for crashing when scanning BitPay invoice URL
2018-09-24 11:47:16 +02:00
Brendon Duncan
d2178d670f Fix identification of BitPay. 2018-09-23 21:05:26 -07:00
Brendon Duncan
8f8027d573 Reverse out bugfix. 2018-09-23 20:56:15 -07:00
Brendon Duncan
babdc8a13b Restored production setting for page size. 2018-09-23 20:14:42 -07:00
Brendon Duncan
6452a0c7f4 Handling JSON exception. 2018-09-23 13:06:36 -07:00
Brendon Duncan
1b0541a7b5 Return error from Shapeshift when pairs are unavailable. 2018-09-22 22:22:06 -07:00
Brendon Duncan
c661798cd1 Android Debug and release builds work when Gradle 3.3 is in PATH. 2018-09-22 17:45:19 -07:00
Brendon Duncan
a5a1d3edb6 Remove debug logging. 2018-09-22 11:07:24 -07:00
Brendon Duncan
0ba4db83e0 Handling confirmation updates correctly for early transactions. 2018-09-22 11:03:26 -07:00
7 changed files with 504 additions and 18 deletions

View file

@ -71,7 +71,7 @@ module.exports = function(grunt) {
sign_android: { sign_android: {
// When the build log outputs "Built the following apk(s):", it seems to need the filename to start with "android-release". // When the build log outputs "Built the following apk(s):", it seems to need the filename to start with "android-release".
// It looks like it simply lists all apk files starting with "android-release" // It looks like it simply lists all apk files starting with "android-release"
command: 'rm -f platforms/android/build/outputs/apk/android-release-signed-*.apk; jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../bitcoin-com-release-key.jks -signedjar platforms/android/build/outputs/apk/android-release-signed.apk platforms/android/build/outputs/apk/android-release-unsigned.apk bitcoin-com && zipalign -v 4 platforms/android/build/outputs/apk/android-release-signed.apk platforms/android/build/outputs/apk/bitcoin-com-wallet-<%= pkg.fullVersion %>-android-signed-aligned.apk', command: 'rm -f platforms/android/build/outputs/apk/release/*-android-signed-aligned.apk; jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../bitcoin-com-release-key.jks -signedjar platforms/android/build/outputs/apk/release/android-release-signed.apk platforms/android/build/outputs/apk/release/android-release-unsigned.apk bitcoin-com && zipalign -v 4 platforms/android/build/outputs/apk/release/android-release-signed.apk platforms/android/build/outputs/apk/release/bitcoin-com-wallet-<%= pkg.fullVersion %>-android-signed-aligned.apk',
stdin: true, stdin: true,
}, },
sign_desktop_dist: { sign_desktop_dist: {

View file

@ -77,7 +77,7 @@
</plugin> </plugin>
<!-- Supported Platforms --> <!-- Supported Platforms -->
<engine name="ios" spec="~4.5.3" /> <engine name="ios" spec="~4.5.3" />
<engine name="android" spec="~6.3.0" /> <engine name="android" spec="~6.4.0" />
<engine name="windows" spec="~5.0.0" /> <engine name="windows" spec="~5.0.0" />
<!-- Platform Specific Settings --> <!-- Platform Specific Settings -->

View file

@ -1,5 +1,6 @@
ext { ext {
ANDROID_SUPPORT_V4_VERSION = '26.1.0' ANDROID_SUPPORT_V4_VERSION = '26.1.0'
ANDROID_SUPPORT_ANNOTATIONS_VERSION = '26.1.0'
} }
configurations.all { configurations.all {

View file

@ -52,7 +52,7 @@ angular
// Detect some merchant that we know // Detect some merchant that we know
if (payProData.memo.indexOf('eGifter') > -1) { if (payProData.memo.indexOf('eGifter') > -1) {
name = 'eGifter' name = 'eGifter'
} else if (paymentUrl.indexOf('https://bitpay.com') > -1) { } else if (payProData.url.indexOf('https://bitpay.com') > -1) {
name = 'BitPay'; name = 'BitPay';
} }

View file

@ -24,7 +24,7 @@ var ShapeShift = (function() {
var parsedResponse = JP(xmlhttp.responseText); var parsedResponse = JP(xmlhttp.responseText);
cb.apply(null, [parsedResponse]); cb.apply(null, [parsedResponse]);
} else { } else {
cb.apply(null, [new Error('Request Failed')]) cb.apply(null, [new Error('Request Failed')]);
} }
} }
}; };

View file

@ -6,9 +6,9 @@
.module('bitcoincom.services') .module('bitcoincom.services')
.factory('walletHistoryService', walletHistoryService); .factory('walletHistoryService', walletHistoryService);
function walletHistoryService(configService, storageService, lodash, $log, txFormatService) { function walletHistoryService(storageService, lodash, $log, txFormatService) {
//var PAGE_SIZE = 50; var PAGE_SIZE = 50;
var PAGE_SIZE = 20; // For dev only //var PAGE_SIZE = 20; // For dev only
// How much to overlap on each end of the page, for mitigating inconsistent sort order. // How much to overlap on each end of the page, for mitigating inconsistent sort order.
var PAGE_OVERLAP_FRACTION = 0.2; var PAGE_OVERLAP_FRACTION = 0.2;
var PAGE_OVERLAP = Math.floor(PAGE_SIZE * PAGE_OVERLAP_FRACTION); var PAGE_OVERLAP = Math.floor(PAGE_SIZE * PAGE_OVERLAP_FRACTION);
@ -28,8 +28,8 @@
function addEarlyTransactions(walletId, cachedTxs, newTxs) { function addEarlyTransactions(walletId, cachedTxs, newTxs) {
var cachedTxIndexFromId = {}; var cachedTxIndexFromId = {};
cachedTxs.forEach(function forCachedTx(tx){ cachedTxs.forEach(function forCachedTx(tx, txIndex){
cachedTxIndexFromId[tx.txid] = true; cachedTxIndexFromId[tx.txid] = txIndex;
}); });
var confirmationsUpdated = false; var confirmationsUpdated = false;
@ -47,10 +47,17 @@
} }
}); });
var txsAreContinuous = false;
if (cachedTxs.length > 0) {
var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP); var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP);
console.log('overlappingTxsCount:', overlappingTxsCount);
console.log('overlappingTxFraction:', overlappingTxFraction); console.log('overlappingTxFraction:', overlappingTxFraction);
txsAreContinuous = overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION;
} else {
txsAreContinuous = true;
}
if (overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION) { // We are good if (txsAreContinuous) {
if (someTransactionsWereNew) { if (someTransactionsWereNew) {
saveTxHistory(walletId, cachedTxs); saveTxHistory(walletId, cachedTxs);
} else if (confirmationsUpdated) { } else if (confirmationsUpdated) {
@ -61,7 +68,7 @@
return cachedTxs; return cachedTxs;
} else { } else {
// We might be missing some txs. // We might be missing some txs.
console.error('We might be missing some txs in the history.'); $log.error('We might be missing some txs in the history.');
// Our history is wrong, so remove it - we could instead, try to fetch data that was not so early. // Our history is wrong, so remove it - we could instead, try to fetch data that was not so early.
storageService.removeTxHistory(walletId, function onRemoveTxHistory(){}); storageService.removeTxHistory(walletId, function onRemoveTxHistory(){});
return []; return [];
@ -91,9 +98,17 @@
} }
}); });
var txsAreContinuous = false;
if (cachedTxs.length > 0) {
var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP); var overlappingTxFraction = overlappingTxsCount / Math.min(cachedTxs.length, PAGE_OVERLAP);
console.log('overlappingTxsCount:', overlappingTxsCount);
console.log('overlappingTxFraction:', overlappingTxFraction);
txsAreContinuous = overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION;
} else {
txsAreContinuous = true;
}
if (overlappingTxFraction >= MIN_KNOWN_TX_OVERLAP_FRACTION) { // We are good if (txsAreContinuous) {
if (someTransactionsWereNew) { if (someTransactionsWereNew) {
var allTxs = uniqueNewTxs.concat(cachedTxs); var allTxs = uniqueNewTxs.concat(cachedTxs);
saveTxHistory(walletId, allTxs); saveTxHistory(walletId, allTxs);
@ -106,6 +121,7 @@
} }
} else { } else {
// We might be missing some txs. // We might be missing some txs.
$log.error('We might be missing some txs in the history.');
// Our history is wrong, so just include the latest ones // Our history is wrong, so just include the latest ones
saveTxHistory(walletId, newTxs); saveTxHistory(walletId, newTxs);
return newTxs; return newTxs;
@ -147,7 +163,6 @@
* @param {function(error, txs)} cb - txs is always an array, may be empty * @param {function(error, txs)} cb - txs is always an array, may be empty
*/ */
function getCachedTxHistory(walletId, cb) { function getCachedTxHistory(walletId, cb) {
console.log('txhistory updateLocalTxHistoryByPage()');
storageService.getTxHistory(walletId, function onGetTxHistory(err, txHistoryString){ storageService.getTxHistory(walletId, function onGetTxHistory(err, txHistoryString){
if (err) { if (err) {
return cb(err, []); return cb(err, []);
@ -230,7 +245,6 @@
} }
function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) { function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) {
console.log('txhistory updaetLocalTxHistoryByPage()');
if (flushCacheOnNew) { if (flushCacheOnNew) {
fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){ fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){
if (err) { if (err) {

View file

@ -0,0 +1,471 @@
fdescribe('walletHistoryService', function(){
var history = [];
var historyStringFull;
var storageServiceMock;
var txFormatServiceMock;
var walletMock;
var walletHistoryService;
beforeEach(function(){
module('ngLodash');
module('bitcoincom.services');
storageServiceMock = jasmine.createSpyObj(['getTxHistory', 'removeTxHistory', 'setTxHistory']);
txFormatServiceMock = jasmine.createSpyObj(['processTx']);
txFormatServiceMock.processTx.and.callFake(function(coin, tx){
return tx;
});
walletMock = jasmine.createSpyObj(['getTxHistory']);
module(function($provide) {
$provide.value('storageService', storageServiceMock);
$provide.value('txFormatService', txFormatServiceMock);
});
inject(function($injector){
walletHistoryService = $injector.get('walletHistoryService');
});
for(var i = 0; i < 100; i++) {
history.push({
confirmations: i,
time: (Date.now() / 1000) - i,
txid: 'id' + i.toString()
});
}
historyStringFull = JSON.stringify(history);
});
it('getCachedHistory empty', function() {
var returnedErr;
var returnedHistory;
var walletIdForStorageGet = '';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, "[]");
});
walletHistoryService.getCachedTxHistory('wallet1234', function(err, txHistory){
returnedErr = err;
returnedHistory = txHistory;
});
expect(walletIdForStorageGet).toBe('wallet1234');
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(0);
});
it('getCachedHistory error from storage', function() {
var returnedErr;
var returnedHistory;
var walletIdForStorageGet = '';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(new Error('Something went wrong.'), null);
});
walletHistoryService.getCachedTxHistory('wallet12345', function(err, txHistory){
returnedErr = err;
returnedHistory = txHistory;
});
expect(walletIdForStorageGet).toBe('wallet12345');
expect(returnedErr.message).toBe('Something went wrong.');
expect(returnedHistory.length).toBe(0);
});
it('getCachedHistory page full', function() {
var returnedErr;
var returnedHistory;
var walletIdForStorageGet = '';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(0, 50)));
});
walletHistoryService.getCachedTxHistory('wallet1234', function(err, txHistory){
returnedErr = err;
returnedHistory = txHistory;
});
expect(walletIdForStorageGet).toBe('wallet1234');
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(50);
});
it('updateLocalTxHistoryByPage, 2 in cache, getEarlier, keep cache, same 2 returned, so all transactions received.', function(){
var fetchLimit;
var fetchSkip;
var returnedAllFetched;
var returnedErr;
var returnedHistory;
var walletIdForStorageGet;
walletMock.id = 'wallet456';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(0, 2)));
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(0, 2));
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, false, false, function(err, txs, allFetched){
returnedErr = err;
returnedHistory = txs;
returnedAllFetched = allFetched;
});
expect(walletIdForStorageGet).toBe('wallet456');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(2);
expect(returnedAllFetched).toBe(true);
expect(storageServiceMock.setTxHistory.calls.any()).toBe(false);
});
it('updateLocalTxHistoryByPage, getEarlier, keep cache, sufficient overlap so saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedErr;
var returnedHistory;
var returnedAllFetched;
var savedTxs;
var walletIdForStorageGet;
var walletIdForStorageSet;
walletMock.id = 'wallet67890';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(0, 40)));
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(fetchSkip, fetchSkip + fetchLimit));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, false, false, function(err, txs, allFetched){
returnedErr = err;
returnedHistory = txs;
returnedAllFetched = allFetched;
});
expect(walletIdForStorageGet).toBe('wallet67890');
expect(walletIdForStorageSet).toBe('wallet67890');
expect(fetchSkip).toBe(30);
expect(fetchLimit).toBe(50);
expect(savedTxs.length).toBe(80);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(80);
expect(returnedAllFetched).toBe(false);
});
it('updateLocalTxHistoryByPage, cache empty, getLatest, do not flush cache, one new so saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var savedTxs;
var walletIdForStorageGet;
var walletIdForStorageSet;
walletMock.id = 'wallet789';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, "[]");
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(0, 1));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, false, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageGet).toBe('wallet789');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(savedTxs.length).toBe(1);
expect(walletIdForStorageSet).toBe('wallet789');
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(1);
});
it('updateLocalTxHistoryByPage, cache empty, getLatest, do not flush cache, some new so saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var savedTxs;
var walletIdForStorageGet;
var walletIdForStorageSet;
walletMock.id = 'wallet789';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, "[]");
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(0, 10));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, false, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageGet).toBe('wallet789');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(savedTxs.length).toBe(10);
expect(walletIdForStorageSet).toBe('wallet789');
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(10);
});
it('updateLocalTxHistoryByPage, some cachedTx, getLatest, do not flush cache, nothing new so nothing added.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var walletIdForStorageGet;
walletMock.id = 'wallet789';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(0, 40)));
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, []);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, false, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageGet).toBe('wallet789');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(40);
expect(storageServiceMock.setTxHistory.calls.any()).toBe(false);
});
it('updateLocalTxHistoryByPage, some cachedTx, getLatest, do not flush cache, confirmations increased, saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var savedTxs;
var walletIdForStorageGet;
var walletIdForStorageSet;
walletMock.id = 'wallet789';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(2, 52)));
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
var historyWithHigherConfirmations = [];
for (var i = 0; i < 50; i++) {
historyWithHigherConfirmations.push({
confirmations: i >= 6 ? history[i].confirmations : history[i].confirmations + 1,
time: history[i].time,
txid: history[i].txid
});
}
cb(null, historyWithHigherConfirmations.slice(fetchSkip, fetchSkip + fetchLimit));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, false, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageGet).toBe('wallet789');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(walletIdForStorageSet).toBe('wallet789');
expect(savedTxs.length).toBe(52);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(52);
expect(returnedHistory[2].confirmations).toBe(3);
});
it('updateLocalTxHistoryByPage, some cachedTx, getLatest, do not flush cache, some new with insufficient overlap, so only new saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var savedTxs;
var walletIdForStorageGet;
var walletIdForStorageSet;
walletMock.id = 'wallet789';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(48, 78)));
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(fetchSkip, fetchSkip + fetchLimit));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, false, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageGet).toBe('wallet789');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(walletIdForStorageSet).toBe('wallet789');
expect(savedTxs.length).toBe(50);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(50);
});
it('updateLocalTxHistoryByPage, some cachedTx, getLatest, do not flush cache, some new with sufficient overlap so all saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var savedTxs;
var walletIdForStorageGet;
var walletIdForStorageSet;
walletMock.id = 'wallet789';
storageServiceMock.getTxHistory.and.callFake(function(walletId, cb){
walletIdForStorageGet = walletId;
cb(null, JSON.stringify(history.slice(42, 72)));
});
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(fetchSkip, fetchSkip + fetchLimit));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, false, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageGet).toBe('wallet789');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(walletIdForStorageSet).toBe('wallet789');
expect(savedTxs.length).toBe(72);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(72);
});
it('updateLocalTxHistoryByPage, getLatest, flush cache, some new so saved.', function(){
var fetchLimit;
var fetchSkip;
var returnedHistory;
var savedTxs;
var walletIdForStorageSet;
walletMock.id = 'wallet7890';
walletMock.getTxHistory.and.callFake(function(opts, cb){
fetchSkip = opts.skip;
fetchLimit = opts.limit;
cb(null, history.slice(0, fetchLimit));
});
storageServiceMock.setTxHistory.and.callFake(function(txs, walletId, cb){
savedTxs = txs;
walletIdForStorageSet = walletId;
cb(null);
});
walletHistoryService.updateLocalTxHistoryByPage(walletMock, true, true, function(err, txs){
returnedErr = err;
returnedHistory = txs;
});
expect(walletIdForStorageSet).toBe('wallet7890');
expect(fetchSkip).toBe(0);
expect(fetchLimit).toBe(50);
expect(savedTxs.length).toBe(50);
expect(returnedErr).toBeNull();
expect(returnedHistory.length).toBe(50);
expect(storageServiceMock.getTxHistory.calls.any()).toBe(false);
});
});