Merge branch 'master' into history-notes

feature/default_network_editable
frankiebee 7 years ago
commit e08a727d44
  1. 3
      app/manifest.json
  2. 3
      app/scripts/lib/tx-state-history-helper.js
  3. 2
      package.json
  4. 22
      test/unit/tx-state-history-helper.js

@ -57,7 +57,8 @@
"permissions": [
"storage",
"clipboardWrite",
"http://localhost:8545/"
"http://localhost:8545/",
"https://*.infura.io/"
],
"web_accessible_resources": [
"scripts/inpage.js"

@ -24,7 +24,8 @@ function generateHistoryEntry(previousState, newState) {
return jsonDiffer.compare(previousState, newState)
}
function replayHistory(shortHistory) {
function replayHistory(_shortHistory) {
const shortHistory = clone(_shortHistory)
return shortHistory.reduce((val, entry) => jsonDiffer.applyPatch(val, entry).newDocument)
}

@ -141,7 +141,7 @@
"valid-url": "^1.0.9",
"vreme": "^3.0.2",
"web3": "^0.20.1",
"web3-provider-engine": "^13.2.12",
"web3-provider-engine": "^13.3.1",
"web3-stream-provider": "^3.0.1",
"xtend": "^4.0.1"
},

@ -20,4 +20,26 @@ describe('tx-state-history-helper', function () {
})
})
})
it('replaying history does not mutate the original obj', function () {
const initialState = { test: true, message: 'hello', value: 1 }
const diff1 = {
"op": "replace",
"path": "/message",
"value": "haay",
}
const diff2 = {
"op": "replace",
"path": "/value",
"value": 2,
}
const history = [initialState, diff1, diff2]
const beforeStateSnapshot = JSON.stringify(initialState)
const latestState = txStateHistoryHelper.replayHistory(history)
const afterStateSnapshot = JSON.stringify(initialState)
assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state')
assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run')
})
})

Loading…
Cancel
Save