Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #14314 from NejcZdovc/fix/#14310-clear
Browse files Browse the repository at this point in the history
Clears old entries from the table
  • Loading branch information
NejcZdovc committed Jun 3, 2018
1 parent bd9920b commit 68388a2
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 30 deletions.
8 changes: 5 additions & 3 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -3305,6 +3306,7 @@ const getMethods = () => {
resetPublishers,
clearPaymentHistory,
getPaymentInfo,
synopsisNormalizer,
cacheRuleSet
}

Expand Down Expand Up @@ -3334,7 +3336,6 @@ const getMethods = () => {
currentMediaKey = key
},
getCurrentMediaKey: (key) => currentMediaKey,
synopsisNormalizer,
observeTransactions,
onWalletRecovery,
getStateInfo,
Expand All @@ -3348,6 +3349,7 @@ const getMethods = () => {
roundTripFromWindow,
onReferralCodeRead,
onVerifiedPStatus,
onFuzzing,
checkSeed,
shouldTrackTab
}
Expand Down
14 changes: 10 additions & 4 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,10 +1992,11 @@ const appActions = {
})
},

onLedgerFuzzing: function (newStamp) {
onLedgerFuzzing: function (newStamp, pruned) {
dispatch({
actionType: appConstants.APP_ON_LEDGER_FUZZING,
newStamp
newStamp,
pruned
})
},

Expand Down
23 changes: 11 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 44 additions & 1 deletion test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ describe('ledger api unit tests', function () {
}
},
state: {
transactions: []
transactions: [],
reconcileStamp: 1000
},
busyP: function () {
return isBusy
Expand Down Expand Up @@ -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)
})
})
})
65 changes: 59 additions & 6 deletions test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ describe('ledgerReducer unit tests', function () {
resetPublishers: () => {},
clearPaymentHistory: () => {},
deleteWallet: () => {},
addNewLocation: dummyModifyState
addNewLocation: dummyModifyState,
synopsisNormalizer: dummyModifyState
}
fakeLedgerState = {
resetPublishers: dummyModifyState,
Expand Down Expand Up @@ -870,19 +871,29 @@ 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 () {
const result = ledgerReducer(appState, Immutable.fromJS({
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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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,
Expand All @@ -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())
})
})
Expand Down

0 comments on commit 68388a2

Please sign in to comment.