aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-01-25 12:38:13 +0800
committerGitHub <noreply@github.com>2017-01-25 12:38:13 +0800
commitd30612a2168b02c39a3eaa86f29e47d9edda07d8 (patch)
tree27eab17687c0c7a1b2583f51abf8064fa54de82a /test/unit
parent4f39e8192cd94ad45d68992d5d1129f1612b1aa6 (diff)
parent0f33acb80ca90e07e6f7b7c083f52a1f4344c48e (diff)
downloadtangerine-wallet-browser-d30612a2168b02c39a3eaa86f29e47d9edda07d8.tar.gz
tangerine-wallet-browser-d30612a2168b02c39a3eaa86f29e47d9edda07d8.tar.zst
tangerine-wallet-browser-d30612a2168b02c39a3eaa86f29e47d9edda07d8.zip
Merge pull request #999 from MetaMask/obs-store2
background - introduce ObservableStore (mark II)
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/config-manager-test.js26
-rw-r--r--test/unit/idStore-migration-test.js8
-rw-r--r--test/unit/metamask-controller-test.js6
-rw-r--r--test/unit/migrations-test.js48
4 files changed, 44 insertions, 44 deletions
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index 77d431d5f..fa3929599 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -1,24 +1,23 @@
// polyfill fetch
global.fetch = global.fetch || require('isomorphic-fetch')
+
const assert = require('assert')
const extend = require('xtend')
const rp = require('request-promise')
const nock = require('nock')
const configManagerGen = require('../lib/mock-config-manager')
-const STORAGE_KEY = 'metamask-persistance-key'
describe('config-manager', function() {
var configManager
beforeEach(function() {
- window.localStorage = {} // Hacking localStorage support into JSDom
configManager = configManagerGen()
})
describe('currency conversions', function() {
describe('#getCurrentFiat', function() {
- it('should return false if no previous key exists', function() {
+ it('should return undefined if no previous key exists', function() {
var result = configManager.getCurrentFiat()
assert.ok(!result)
})
@@ -26,14 +25,14 @@ describe('config-manager', function() {
describe('#setCurrentFiat', function() {
it('should make getCurrentFiat return true once set', function() {
- assert.equal(configManager.getCurrentFiat(), false)
+ assert.equal(configManager.getCurrentFiat(), undefined)
configManager.setCurrentFiat('USD')
var result = configManager.getCurrentFiat()
assert.equal(result, 'USD')
})
it('should work with other currencies as well', function() {
- assert.equal(configManager.getCurrentFiat(), false)
+ assert.equal(configManager.getCurrentFiat(), undefined)
configManager.setCurrentFiat('JPY')
var result = configManager.getCurrentFiat()
assert.equal(result, 'JPY')
@@ -41,7 +40,7 @@ describe('config-manager', function() {
})
describe('#getConversionRate', function() {
- it('should return false if non-existent', function() {
+ it('should return undefined if non-existent', function() {
var result = configManager.getConversionRate()
assert.ok(!result)
})
@@ -54,7 +53,7 @@ describe('config-manager', function() {
.get('/api/ticker/eth-USD')
.reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}')
- assert.equal(configManager.getConversionRate(), false)
+ assert.equal(configManager.getConversionRate(), 0)
var promise = new Promise(
function (resolve, reject) {
configManager.setCurrentFiat('USD')
@@ -75,7 +74,7 @@ describe('config-manager', function() {
it('should work for JPY as well.', function() {
this.timeout(15000)
- assert.equal(configManager.getConversionRate(), false)
+ assert.equal(configManager.getConversionRate(), 0)
var jpyMock = nock('https://www.cryptonator.com')
.get('/api/ticker/eth-JPY')
@@ -103,7 +102,7 @@ describe('config-manager', function() {
describe('confirmation', function() {
describe('#getConfirmedDisclaimer', function() {
- it('should return false if no previous key exists', function() {
+ it('should return undefined if no previous key exists', function() {
var result = configManager.getConfirmedDisclaimer()
assert.ok(!result)
})
@@ -111,16 +110,16 @@ describe('config-manager', function() {
describe('#setConfirmedDisclaimer', function() {
it('should make getConfirmedDisclaimer return true once set', function() {
- assert.equal(configManager.getConfirmedDisclaimer(), false)
+ assert.equal(configManager.getConfirmedDisclaimer(), undefined)
configManager.setConfirmedDisclaimer(true)
var result = configManager.getConfirmedDisclaimer()
assert.equal(result, true)
})
- it('should be able to set false', function() {
- configManager.setConfirmedDisclaimer(false)
+ it('should be able to set undefined', function() {
+ configManager.setConfirmedDisclaimer(undefined)
var result = configManager.getConfirmedDisclaimer()
- assert.equal(result, false)
+ assert.equal(result, undefined)
})
it('should persist to local storage', function() {
@@ -132,7 +131,6 @@ describe('config-manager', function() {
})
describe('#setConfig', function() {
- window.localStorage = {} // Hacking localStorage support into JSDom
it('should set the config key', function () {
var testConfig = {
diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js
index 54f38fb2f..38667fc3e 100644
--- a/test/unit/idStore-migration-test.js
+++ b/test/unit/idStore-migration-test.js
@@ -1,5 +1,6 @@
const async = require('async')
const assert = require('assert')
+const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const ConfigManager = require('../../app/scripts/lib/config-manager')
@@ -42,10 +43,9 @@ describe('IdentityStore to KeyringController migration', function() {
beforeEach(function(done) {
this.sinon = sinon.sandbox.create()
window.localStorage = {} // Hacking localStorage support into JSDom
- configManager = new ConfigManager({
- loadData,
- setData: (d) => { window.localStorage = d }
- })
+ let store = new ObservableStore(loadData())
+ store.subscribe(setData)
+ configManager = new ConfigManager({ store })
idStore = new IdentityStore({
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index a6164c9a0..24d9ddd67 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -10,9 +10,11 @@ describe('MetaMaskController', function() {
showUnconfirmedMessage: noop,
unlockAccountMessage: noop,
showUnapprovedTx: noop,
- setData,
- loadData,
+ // initial state
+ initState: loadData(),
})
+ // setup state persistence
+ controller.store.subscribe(setData)
beforeEach(function() {
// sinon allows stubbing methods that are easily verified
diff --git a/test/unit/migrations-test.js b/test/unit/migrations-test.js
index 9ea8d5c5a..715a5feb0 100644
--- a/test/unit/migrations-test.js
+++ b/test/unit/migrations-test.js
@@ -1,34 +1,34 @@
-var assert = require('assert')
-var path = require('path')
+const assert = require('assert')
+const path = require('path')
-var wallet1 = require(path.join('..', 'lib', 'migrations', '001.json'))
+const wallet1 = require(path.join('..', 'lib', 'migrations', '001.json'))
-var migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002'))
-var migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003'))
-var migration4 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '004'))
+const migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002'))
+const migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003'))
+const migration4 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '004'))
-describe('wallet1 is migrated successfully', function() {
+const oldTestRpc = 'https://rawtestrpc.metamask.io/'
+const newTestRpc = 'https://testrpc.metamask.io/'
- it('should convert providers', function(done) {
+describe('wallet1 is migrated successfully', function() {
+ it('should convert providers', function() {
wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null }
- var firstResult = migration2.migrate(wallet1.data)
- assert.equal(firstResult.config.provider.type, 'rpc', 'provider should be rpc')
- assert.equal(firstResult.config.provider.rpcTarget, 'https://rpc.metamask.io/', 'main provider should be our rpc')
-
- var oldTestRpc = 'https://rawtestrpc.metamask.io/'
- var newTestRpc = 'https://testrpc.metamask.io/'
- firstResult.config.provider.rpcTarget = oldTestRpc
-
- var secondResult = migration3.migrate(firstResult)
- assert.equal(secondResult.config.provider.rpcTarget, newTestRpc)
-
- var thirdResult = migration4.migrate(secondResult)
- assert.equal(secondResult.config.provider.rpcTarget, null)
- assert.equal(secondResult.config.provider.type, 'testnet')
-
- done()
+ return migration2.migrate(wallet1)
+ .then((firstResult) => {
+ assert.equal(firstResult.data.config.provider.type, 'rpc', 'provider should be rpc')
+ assert.equal(firstResult.data.config.provider.rpcTarget, 'https://rpc.metamask.io/', 'main provider should be our rpc')
+ firstResult.data.config.provider.rpcTarget = oldTestRpc
+ return migration3.migrate(firstResult)
+ }).then((secondResult) => {
+ assert.equal(secondResult.data.config.provider.rpcTarget, newTestRpc)
+ return migration4.migrate(secondResult)
+ }).then((thirdResult) => {
+ assert.equal(thirdResult.data.config.provider.rpcTarget, null)
+ assert.equal(thirdResult.data.config.provider.type, 'testnet')
+ })
+
})
})