aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/migrations')
-rw-r--r--test/unit/migrations/029-test.js38
-rw-r--r--test/unit/migrations/030-test.js37
-rw-r--r--test/unit/migrations/031-test.js56
3 files changed, 131 insertions, 0 deletions
diff --git a/test/unit/migrations/029-test.js b/test/unit/migrations/029-test.js
new file mode 100644
index 000000000..a2876487b
--- /dev/null
+++ b/test/unit/migrations/029-test.js
@@ -0,0 +1,38 @@
+const assert = require('assert')
+const migration29 = require('../../../app/scripts/migrations/029')
+const properTime = (new Date()).getTime()
+const storage = {
+ 'meta': {},
+ 'data': {
+ 'TransactionController': {
+ 'transactions': [
+ { 'status': 'approved', id: 1, submittedTime: 0 },
+ { 'status': 'approved', id: 2, submittedTime: properTime },
+ { 'status': 'confirmed', id: 3, submittedTime: properTime },
+ { 'status': 'submitted', id: 4, submittedTime: properTime },
+ { 'status': 'submitted', id: 5, submittedTime: 0 },
+ ],
+ },
+ },
+}
+
+describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => {
+ it('should auto fail transactions more than 12 hours old', (done) => {
+ migration29.migrate(storage)
+ .then((migratedData) => {
+ const txs = migratedData.data.TransactionController.transactions
+ const [ txMeta1 ] = txs
+ assert.equal(migratedData.meta.version, 29)
+
+ assert.equal(txMeta1.status, 'failed', 'old tx is auto failed')
+ assert(txMeta1.err.message.includes('too long'), 'error message assigned')
+
+ txs.forEach((tx) => {
+ if (tx.id === 1) return
+ assert.notEqual(tx.status, 'failed', 'other tx is not auto failed')
+ })
+
+ done()
+ }).catch(done)
+ })
+})
diff --git a/test/unit/migrations/030-test.js b/test/unit/migrations/030-test.js
new file mode 100644
index 000000000..ca410342f
--- /dev/null
+++ b/test/unit/migrations/030-test.js
@@ -0,0 +1,37 @@
+const assert = require('assert')
+const migrationTemplate = require('../../../app/scripts/migrations/030.js')
+const storage = {
+ meta: {},
+ data: {
+ NetworkController: {
+ network: 'fail',
+ provider: {
+ chainId: 'fail',
+ nickname: '',
+ rpcTarget: 'https://api.myetherwallet.com/eth',
+ ticker: 'ETH',
+ type: 'rinkeby',
+ },
+ },
+ PreferencesController: {
+ frequentRpcListDetail: [
+ {chainId: 'fail', nickname: '', rpcUrl: 'http://127.0.0.1:8545', ticker: ''},
+ {chainId: '1', nickname: '', rpcUrl: 'https://api.myetherwallet.com/eth', ticker: 'ETH'},
+ ],
+ },
+ },
+}
+
+describe('storage is migrated successfully', () => {
+ it('should work', (done) => {
+ migrationTemplate.migrate(storage)
+ .then((migratedData) => {
+ assert.equal(migratedData.meta.version, 30)
+ assert.equal(migratedData.data.PreferencesController.frequentRpcListDetail[0].chainId, undefined)
+ assert.equal(migratedData.data.PreferencesController.frequentRpcListDetail[1].chainId, '1')
+ assert.equal(migratedData.data.NetworkController.provider.chainId, undefined)
+ assert.equal(migratedData.data.NetworkController.network, undefined)
+ done()
+ }).catch(done)
+ })
+})
diff --git a/test/unit/migrations/031-test.js b/test/unit/migrations/031-test.js
new file mode 100644
index 000000000..c85fd7af4
--- /dev/null
+++ b/test/unit/migrations/031-test.js
@@ -0,0 +1,56 @@
+const assert = require('assert')
+const migration31 = require('../../../app/scripts/migrations/031')
+
+ describe('migration #31', () => {
+ it('should set completedOnboarding to true if vault exists', done => {
+ const oldStorage = {
+ 'meta': {},
+ 'data': {
+ 'PreferencesController': {
+ 'tokens': [{address: '0xa', symbol: 'A', decimals: 4}, {address: '0xb', symbol: 'B', decimals: 4}],
+ 'identities': {
+ '0x6d14': {},
+ '0x3695': {},
+ },
+ },
+ 'KeyringController': {
+ 'vault': {
+ 'data': 'test0',
+ 'iv': 'test1',
+ 'salt': 'test2',
+ },
+ },
+ },
+ }
+
+ migration31.migrate(oldStorage)
+ .then(newStorage => {
+ assert.equal(newStorage.data.PreferencesController.completedOnboarding, true)
+ done()
+ })
+ .catch(done)
+ })
+
+ it('should set completedOnboarding to false if vault does not exist', done => {
+ const oldStorage = {
+ 'meta': {},
+ 'data': {
+ 'PreferencesController': {
+ 'tokens': [{address: '0xa', symbol: 'A', decimals: 4}, {address: '0xb', symbol: 'B', decimals: 4}],
+ 'identities': {
+ '0x6d14': {},
+ '0x3695': {},
+ },
+ },
+ 'KeyringController': {},
+ },
+ }
+
+ migration31.migrate(oldStorage)
+ .then(newStorage => {
+ assert.equal(newStorage.data.PreferencesController.completedOnboarding, false)
+ done()
+ })
+ .catch(done)
+ })
+})