diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-08-24 02:12:46 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-08-24 02:12:46 +0800 |
commit | b3b62d97a367ebcd1b69555a97311fca19b3a27f (patch) | |
tree | bab3bb390c4367ceca11c6158f519fb087ce68ca /test/unit/tx-state-history-helper.js | |
parent | a1618ca1b4ef6568cd0c9660c56adeb8659af2bb (diff) | |
parent | 9203b4edf9df8b616877c57970fb01a7fb87924b (diff) | |
download | tangerine-wallet-browser-b3b62d97a367ebcd1b69555a97311fca19b3a27f.tar.gz tangerine-wallet-browser-b3b62d97a367ebcd1b69555a97311fca19b3a27f.tar.zst tangerine-wallet-browser-b3b62d97a367ebcd1b69555a97311fca19b3a27f.zip |
Merge branch 'master' into useLocalNonce
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') + }) + }) + }) +}) |