diff options
author | kumavis <aaron@kumavis.me> | 2017-08-15 09:46:04 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2017-08-15 09:46:04 +0800 |
commit | fdffb6fedc6a29a2f952f7db669bdc2907afb854 (patch) | |
tree | 35a996001d2e32950c1e7bd0ee8fb37d0b345bd8 /test/unit/tx-state-history-helper.js | |
parent | 68c6b2d666719476bff78cbc107a56be3b86dbe1 (diff) | |
download | tangerine-wallet-browser-fdffb6fedc6a29a2f952f7db669bdc2907afb854.tar.gz tangerine-wallet-browser-fdffb6fedc6a29a2f952f7db669bdc2907afb854.tar.zst tangerine-wallet-browser-fdffb6fedc6a29a2f952f7db669bdc2907afb854.zip |
introduce tx-state-history-helper and diff-based history
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..2ac91c39f --- /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('history-differ', 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') + }) + }) + }) +}) |