diff options
author | Chi Kei Chan <chikeichan@gmail.com> | 2017-09-19 02:28:10 +0800 |
---|---|---|
committer | Chi Kei Chan <chikeichan@gmail.com> | 2017-09-19 02:28:10 +0800 |
commit | 6c5865d564167c1097d6010e47d1e82a75087fd1 (patch) | |
tree | 9ced5adba4b6e5b77724f19a086a10981ba7e375 /test/unit/tx-state-history-helper.js | |
parent | 54bbf8d8590014b92e7857f30bdc2d8f3779431a (diff) | |
parent | 693655e2da7cacf5a5326b50bddc37bcece9422e (diff) | |
download | tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.tar tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.tar.gz tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.tar.bz2 tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.tar.lz tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.tar.xz tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.tar.zst tangerine-wallet-browser-6c5865d564167c1097d6010e47d1e82a75087fd1.zip |
Merge branch 'master' into nm
Diffstat (limited to 'test/unit/tx-state-history-helper.js')
-rw-r--r-- | test/unit/tx-state-history-helper.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js new file mode 100644 index 000000000..5bb6c9bee --- /dev/null +++ b/test/unit/tx-state-history-helper.js @@ -0,0 +1,23 @@ +const assert = require('assert') +const txStateHistoryHelper = require('../../app/scripts/lib/tx-state-history-helper') +const testVault = require('../data/v17-long-history.json') + + +describe('tx-state-history-helper', function () { + it('migrates history to diffs and can recover original values', function () { + testVault.data.TransactionController.transactions.forEach((tx, index) => { + const newHistory = txStateHistoryHelper.migrateFromSnapshotsToDiffs(tx.history) + newHistory.forEach((newEntry, index) => { + if (index === 0) { + assert.equal(Array.isArray(newEntry), false, 'initial history item IS NOT a json patch obj') + } else { + assert.equal(Array.isArray(newEntry), true, 'non-initial history entry IS a json patch obj') + } + const oldEntry = tx.history[index] + const historySubset = newHistory.slice(0, index + 1) + const reconstructedValue = txStateHistoryHelper.replayHistory(historySubset) + assert.deepEqual(oldEntry, reconstructedValue, 'was able to reconstruct old entry from diffs') + }) + }) + }) +}) |