diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index 0a4c12e46ec..d85c2d3ad09 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -2474,9 +2474,10 @@ const onInitRead = (state, parsedData) => { return state } -const onFuzzing = () => { +const onFuzzing = (pushBack, pruned = false) => { if (client && client.state) { - appActions.onLedgerFuzzing(client.state.reconcileStamp) + const newStamp = pushBack ? client.state.reconcileStamp : null + appActions.onLedgerFuzzing(newStamp, pruned) } } @@ -3305,6 +3306,7 @@ const getMethods = () => { resetPublishers, clearPaymentHistory, getPaymentInfo, + synopsisNormalizer, cacheRuleSet } @@ -3334,7 +3336,6 @@ const getMethods = () => { currentMediaKey = key }, getCurrentMediaKey: (key) => currentMediaKey, - synopsisNormalizer, observeTransactions, onWalletRecovery, getStateInfo, @@ -3348,6 +3349,7 @@ const getMethods = () => { roundTripFromWindow, onReferralCodeRead, onVerifiedPStatus, + onFuzzing, checkSeed, shouldTrackTab } diff --git a/app/browser/reducers/ledgerReducer.js b/app/browser/reducers/ledgerReducer.js index 9e8c611f0df..11c74571696 100644 --- a/app/browser/reducers/ledgerReducer.js +++ b/app/browser/reducers/ledgerReducer.js @@ -523,10 +523,16 @@ const ledgerReducer = (state, action, immutableAction) => { } case appConstants.APP_ON_LEDGER_FUZZING: { - state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.FUZZING) - const newStamp = parseInt(action.get('newStamp')) - if (!isNaN(newStamp) && newStamp > 0) { - state = ledgerState.setInfoProp(state, 'reconcileStamp', newStamp) + if (action.get('newStamp') != null) { + const newStamp = parseInt(action.get('newStamp')) + if (!isNaN(newStamp) && newStamp > 0) { + state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.FUZZING) + state = ledgerState.setInfoProp(state, 'reconcileStamp', newStamp) + } + } + + if (action.get('pruned')) { + state = ledgerApi.synopsisNormalizer(state, null, true, true) } break } diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 515090f2cfd..7e87949be17 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -1992,10 +1992,11 @@ const appActions = { }) }, - onLedgerFuzzing: function (newStamp) { + onLedgerFuzzing: function (newStamp, pruned) { dispatch({ actionType: appConstants.APP_ON_LEDGER_FUZZING, - newStamp + newStamp, + pruned }) }, diff --git a/package-lock.json b/package-lock.json index 9c734e08438..29d00905124 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1566,9 +1566,9 @@ } }, "bat-client": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/bat-client/-/bat-client-3.3.1.tgz", - "integrity": "sha512-fVggtG2Um8uaoO8OlbFLM89sawH3ldFEhHl28KMznDkVYNCRNHP3TD+1GCUF6kX3vtliSF185p2+IWPrtEXBkA==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/bat-client/-/bat-client-3.3.2.tgz", + "integrity": "sha512-hpXG/qAxgtElpmMI+WkrqS6yIXSLvr/AOlvesYN8FWDvn1fh1fd9mbF0Cd++r/r8qhbtO8vRqNS/tdd/I+oNLQ==", "requires": { "@ambassify/backoff-strategies": "1.0.0", "bat-balance": "^1.0.7", @@ -1596,9 +1596,9 @@ } }, "bat-publisher": { - "version": "2.0.16", - "resolved": "https://registry.npmjs.org/bat-publisher/-/bat-publisher-2.0.16.tgz", - "integrity": "sha512-PzGSL0GqVM8I50NGDNUlkSQk1L1//reBK72uL5vxp7EZsSQHwlvkMP/wANLX8qyNNCLomWg1FCb4jQTf/3bW9w==", + "version": "2.0.17", + "resolved": "https://registry.npmjs.org/bat-publisher/-/bat-publisher-2.0.17.tgz", + "integrity": "sha512-f69M1vvlTPg+8HLnCoQjbR6P6M3gecgHWrHWXBazKXSzgbGsZkqbINZQmgpwRB0D7apgr0sloq3BozCQdybQzw==", "requires": { "@ambassify/backoff-strategies": "1.0.0", "async": "^2.5.0", @@ -6796,11 +6796,11 @@ } }, "for-each": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.2.tgz", - "integrity": "sha1-LEBFC5NI6X8oEyJZO6lnBLmr1NQ=", + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", "requires": { - "is-function": "~1.0.0" + "is-callable": "^1.1.3" } }, "for-in": { @@ -8885,8 +8885,7 @@ "is-callable": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz", - "integrity": "sha1-hut1OSgF3cM69xySoO7fdO52BLI=", - "dev": true + "integrity": "sha1-hut1OSgF3cM69xySoO7fdO52BLI=" }, "is-ci": { "version": "1.1.0", diff --git a/package.json b/package.json index e046e3029a4..3cd6d280409 100644 --- a/package.json +++ b/package.json @@ -89,8 +89,8 @@ "aphrodite": "1.1.0", "async": "^2.0.1", "bat-balance": "^1.0.7", - "bat-client": "^3.3.1", - "bat-publisher": "^2.0.15", + "bat-client": "^3.3.2", + "bat-publisher": "^2.0.17", "bignumber.js": "^4.0.4", "bloodhound-js": "brave/bloodhound", "clipboard-copy": "^1.0.0", diff --git a/test/unit/app/browser/api/ledgerTest.js b/test/unit/app/browser/api/ledgerTest.js index e054958de6c..ce61fa22c11 100644 --- a/test/unit/app/browser/api/ledgerTest.js +++ b/test/unit/app/browser/api/ledgerTest.js @@ -150,7 +150,8 @@ describe('ledger api unit tests', function () { } }, state: { - transactions: [] + transactions: [], + reconcileStamp: 1000 }, busyP: function () { return isBusy @@ -4032,4 +4033,46 @@ describe('ledger api unit tests', function () { }) }) }) + + describe('onFuzzing', function () { + let onLedgerFuzzingSpy + + before(function () { + onLedgerFuzzingSpy = sinon.spy(appActions, 'onLedgerFuzzing') + }) + + beforeEach(function () { + ledgerApi.setClient(ledgerClientObject) + }) + + afterEach(function () { + onLedgerFuzzingSpy.reset() + }) + + after(function () { + onLedgerFuzzingSpy.restore() + ledgerApi.setClient(undefined) + }) + + it('null case', function () { + ledgerApi.onFuzzing() + assert(onLedgerFuzzingSpy.withArgs(null, false).calledOnce) + }) + + it('client is not set', function () { + ledgerApi.setClient(undefined) + ledgerApi.onFuzzing() + assert(onLedgerFuzzingSpy.notCalled) + }) + + it('push back is not happening', function () { + ledgerApi.onFuzzing(null, true) + assert(onLedgerFuzzingSpy.withArgs(null, true).calledOnce) + }) + + it('pushing back', function () { + ledgerApi.onFuzzing(10, true) + assert(onLedgerFuzzingSpy.withArgs(1000, true).calledOnce) + }) + }) }) diff --git a/test/unit/app/browser/reducers/ledgerReducerTest.js b/test/unit/app/browser/reducers/ledgerReducerTest.js index 66843377d8f..0879632ce95 100644 --- a/test/unit/app/browser/reducers/ledgerReducerTest.js +++ b/test/unit/app/browser/reducers/ledgerReducerTest.js @@ -66,7 +66,8 @@ describe('ledgerReducer unit tests', function () { resetPublishers: () => {}, clearPaymentHistory: () => {}, deleteWallet: () => {}, - addNewLocation: dummyModifyState + addNewLocation: dummyModifyState, + synopsisNormalizer: dummyModifyState } fakeLedgerState = { resetPublishers: dummyModifyState, @@ -870,11 +871,20 @@ describe('ledgerReducer unit tests', function () { }) describe('APP_ON_LEDGER_FUZZING', function () { - let newState + let newState, synopsisNormalizerSpy - before(() => { + before(function () { newState = appState .setIn(['ledger', 'about', 'status'], ledgerStatuses.FUZZING) + synopsisNormalizerSpy = sinon.spy(fakeLedgerApi, 'synopsisNormalizer') + }) + + afterEach(function () { + synopsisNormalizerSpy.reset() + }) + + after(function () { + synopsisNormalizerSpy.restore() }) it('null case', function () { @@ -882,7 +892,8 @@ describe('ledgerReducer unit tests', function () { actionType: appConstants.APP_ON_LEDGER_FUZZING })) - assert.deepEqual(result.toJS(), newState.toJS()) + assert(synopsisNormalizerSpy.notCalled) + assert.deepEqual(result.toJS(), appState.toJS()) }) it('stamp is string', function () { @@ -891,7 +902,8 @@ describe('ledgerReducer unit tests', function () { newStamp: 'str' })) - assert.deepEqual(result.toJS(), newState.toJS()) + assert(synopsisNormalizerSpy.notCalled) + assert.deepEqual(result.toJS(), appState.toJS()) }) it('stamp is negative', function () { @@ -900,7 +912,8 @@ describe('ledgerReducer unit tests', function () { newStamp: -10 })) - assert.deepEqual(result.toJS(), newState.toJS()) + assert(synopsisNormalizerSpy.notCalled) + assert.deepEqual(result.toJS(), appState.toJS()) }) it('stamp is number (string)', function () { @@ -912,9 +925,19 @@ describe('ledgerReducer unit tests', function () { const expectedState = newState .setIn(['ledger', 'info', 'reconcileStamp'], 10) + assert(synopsisNormalizerSpy.notCalled) assert.deepEqual(result.toJS(), expectedState.toJS()) }) + it('stamp is 0', function () { + const result = ledgerReducer(appState, Immutable.fromJS({ + actionType: appConstants.APP_ON_LEDGER_FUZZING, + newStamp: 0 + })) + + assert.deepEqual(result.toJS(), appState.toJS()) + }) + it('reconcile stamp is set', function () { const result = ledgerReducer(appState, Immutable.fromJS({ actionType: appConstants.APP_ON_LEDGER_FUZZING, @@ -924,6 +947,36 @@ describe('ledgerReducer unit tests', function () { const expectedState = newState .setIn(['ledger', 'info', 'reconcileStamp'], 10) + assert(synopsisNormalizerSpy.notCalled) + assert.deepEqual(result.toJS(), expectedState.toJS()) + }) + + it('pruned is false', function () { + const result = ledgerReducer(appState, Immutable.fromJS({ + actionType: appConstants.APP_ON_LEDGER_FUZZING, + newStamp: 10, + pruned: false + })) + + const expectedState = newState + .setIn(['ledger', 'info', 'reconcileStamp'], 10) + + assert(synopsisNormalizerSpy.notCalled) + assert.deepEqual(result.toJS(), expectedState.toJS()) + }) + + it('pruned is true', function () { + const result = ledgerReducer(appState, Immutable.fromJS({ + actionType: appConstants.APP_ON_LEDGER_FUZZING, + newStamp: 10, + pruned: true + })) + + const expectedState = newState + .setIn(['ledger', 'info', 'reconcileStamp'], 10) + .set('unittest', true) + + assert(synopsisNormalizerSpy.withArgs(sinon.match.any, null, true, true)) assert.deepEqual(result.toJS(), expectedState.toJS()) }) })