aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/tx-state-history-helper.js
diff options
context:
space:
mode:
authorKevin Serrano <kevin.serrano@consensys.net>2017-09-06 00:03:44 +0800
committerKevin Serrano <kevin.serrano@consensys.net>2017-09-06 00:03:44 +0800
commite647337a8a34d8fb4b5a8081888ec32ce5fd27a0 (patch)
tree2060fcf05407d4cec876332a70d25418237a724d /test/unit/tx-state-history-helper.js
parent45fc1d6ec356232e51fe4a9cc1f01929e35e8014 (diff)
parent2885a9547187ce1ad0fb3bed1935387d901942a8 (diff)
downloadtangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.tar
tangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.tar.gz
tangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.tar.bz2
tangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.tar.lz
tangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.tar.xz
tangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.tar.zst
tangerine-wallet-browser-e647337a8a34d8fb4b5a8081888ec32ce5fd27a0.zip
Resolve merge conflict from master
Diffstat (limited to 'test/unit/tx-state-history-helper.js')
-rw-r--r--test/unit/tx-state-history-helper.js23
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')
+ })
+ })
+ })
+})