aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-01-29 14:59:28 +0800
committerFrankie <frankie.diamond@gmail.com>2017-01-29 14:59:28 +0800
commitfdee1e3701a84fe1321de348ec2d11bf5361a62d (patch)
tree1844d6c25cc824c9303ab79103525cab08d5e0b3 /test
parent8be68575bbef1dcc89b51355abaee90dbf018387 (diff)
parent47b48c0e02b2b9508813abfda0d89a1bbe677694 (diff)
downloadtangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.tar
tangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.tar.gz
tangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.tar.bz2
tangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.tar.lz
tangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.tar.xz
tangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.tar.zst
tangerine-wallet-browser-fdee1e3701a84fe1321de348ec2d11bf5361a62d.zip
Merge branch 'dev' into messageManagerCleanUp
Diffstat (limited to 'test')
-rw-r--r--test/unit/idStore-migration-test.js61
-rw-r--r--test/unit/keyring-controller-test.js56
-rw-r--r--test/unit/metamask-controller-test.js68
3 files changed, 31 insertions, 154 deletions
diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js
index 38667fc3e..3aaf4bb94 100644
--- a/test/unit/idStore-migration-test.js
+++ b/test/unit/idStore-migration-test.js
@@ -4,12 +4,13 @@ const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const ConfigManager = require('../../app/scripts/lib/config-manager')
+const firstTimeState = require('../../app/scripts/first-time-state')
const delegateCallCode = require('../lib/example-code.json').delegateCallCode
+const clone = require('clone')
// The old way:
const IdentityStore = require('../../app/scripts/lib/idStore')
const STORAGE_KEY = 'metamask-config'
-const extend = require('xtend')
// The new ways:
var KeyringController = require('../../app/scripts/keyring-controller')
@@ -42,12 +43,9 @@ describe('IdentityStore to KeyringController migration', function() {
// and THEN create a new one, before we can run tests on it.
beforeEach(function(done) {
this.sinon = sinon.sandbox.create()
- window.localStorage = {} // Hacking localStorage support into JSDom
- let store = new ObservableStore(loadData())
- store.subscribe(setData)
+ let store = new ObservableStore(clone(firstTimeState))
configManager = new ConfigManager({ store })
-
idStore = new IdentityStore({
configManager: configManager,
ethStore: {
@@ -91,56 +89,9 @@ describe('IdentityStore to KeyringController migration', function() {
assert(!state.lostAccounts, 'no lost accounts')
done()
})
+ .catch((err) => {
+ done(err)
+ })
})
})
})
-
-function loadData () {
- var oldData = getOldStyleData()
- var newData
- try {
- newData = JSON.parse(window.localStorage[STORAGE_KEY])
- } catch (e) {}
-
- var data = extend({
- meta: {
- version: 0,
- },
- data: {
- config: {
- provider: {
- type: 'testnet',
- },
- },
- },
- }, oldData || null, newData || null)
- return data
-}
-
-function setData (data) {
- window.localStorage[STORAGE_KEY] = JSON.stringify(data)
-}
-
-function getOldStyleData () {
- var config, wallet, seedWords
-
- var result = {
- meta: { version: 0 },
- data: {},
- }
-
- try {
- config = JSON.parse(window.localStorage['config'])
- result.data.config = config
- } catch (e) {}
- try {
- wallet = JSON.parse(window.localStorage['lightwallet'])
- result.data.wallet = wallet
- } catch (e) {}
- try {
- seedWords = window.localStorage['seedWords']
- result.data.seedWords = seedWords
- } catch (e) {}
-
- return result
-}
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index d6d2db817..347aa2bdf 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -1,6 +1,6 @@
-var assert = require('assert')
-var KeyringController = require('../../app/scripts/keyring-controller')
-var configManagerGen = require('../lib/mock-config-manager')
+const assert = require('assert')
+const KeyringController = require('../../app/scripts/keyring-controller')
+const configManagerGen = require('../lib/mock-config-manager')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const async = require('async')
@@ -55,17 +55,16 @@ describe('KeyringController', function() {
this.timeout(10000)
it('should set a vault on the configManager', function(done) {
- keyringController.configManager.setVault(null)
- assert(!keyringController.configManager.getVault(), 'no previous vault')
+ keyringController.store.updateState({ vault: null })
+ assert(!keyringController.store.getState().vault, 'no previous vault')
keyringController.createNewVaultAndKeychain(password)
.then(() => {
- const vault = keyringController.configManager.getVault()
+ const vault = keyringController.store.getState().vault
assert(vault, 'vault created')
done()
})
.catch((reason) => {
- assert.ifError(reason)
- done()
+ done(reason)
})
})
})
@@ -96,8 +95,7 @@ describe('KeyringController', function() {
done()
})
.catch((reason) => {
- assert.ifError(reason)
- done()
+ done(reason)
})
})
})
@@ -109,9 +107,6 @@ describe('KeyringController', function() {
const identities = keyringController.identities
const identity = identities[fakeAddress]
assert.equal(identity.address, fakeAddress)
-
- const nick = keyringController.configManager.nicknameForWallet(fakeAddress)
- assert.equal(typeof nick, 'string')
})
})
@@ -122,34 +117,17 @@ describe('KeyringController', function() {
keyringController.identities[ethUtil.addHexPrefix(account)] = {}
keyringController.saveAccountLabel(account, nick)
.then((label) => {
- assert.equal(label, nick)
- const persisted = keyringController.configManager.nicknameForWallet(account)
- assert.equal(persisted, nick)
- done()
- })
- .catch((reason) => {
- assert.ifError(reason)
- done()
- })
- })
-
- this.timeout(10000)
- it('retrieves the persisted nickname', function(done) {
- const account = addresses[0]
- var nick = 'Test nickname'
- keyringController.configManager.setNicknameForWallet(account, nick)
- keyringController.createNewVaultAndRestore(password, seedWords)
- .then((state) => {
-
- const identity = keyringController.identities['0x' + account]
- assert.equal(identity.name, nick)
-
- assert(accounts)
- done()
+ try {
+ assert.equal(label, nick)
+ const persisted = keyringController.store.getState().walletNicknames[account]
+ assert.equal(persisted, nick)
+ done()
+ } catch (err) {
+ done()
+ }
})
.catch((reason) => {
- assert.ifError(reason)
- done()
+ done(reason)
})
})
})
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index 24d9ddd67..78b9e9df7 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -1,7 +1,9 @@
-var assert = require('assert')
-var MetaMaskController = require('../../app/scripts/metamask-controller')
-var sinon = require('sinon')
-var extend = require('xtend')
+const assert = require('assert')
+const sinon = require('sinon')
+const clone = require('clone')
+const MetaMaskController = require('../../app/scripts/metamask-controller')
+const firstTimeState = require('../../app/scripts/first-time-state')
+
const STORAGE_KEY = 'metamask-config'
describe('MetaMaskController', function() {
@@ -11,15 +13,12 @@ describe('MetaMaskController', function() {
unlockAccountMessage: noop,
showUnapprovedTx: noop,
// initial state
- initState: loadData(),
+ initState: clone(firstTimeState),
})
- // setup state persistence
- controller.store.subscribe(setData)
beforeEach(function() {
// sinon allows stubbing methods that are easily verified
this.sinon = sinon.sandbox.create()
- window.localStorage = {} // Hacking localStorage support into JSDom
})
afterEach(function() {
@@ -27,55 +26,4 @@ describe('MetaMaskController', function() {
this.sinon.restore()
})
-})
-
-
-function loadData () {
- var oldData = getOldStyleData()
- var newData
- try {
- newData = JSON.parse(window.localStorage[STORAGE_KEY])
- } catch (e) {}
-
- var data = extend({
- meta: {
- version: 0,
- },
- data: {
- config: {
- provider: {
- type: 'testnet',
- },
- },
- },
- }, oldData || null, newData || null)
- return data
-}
-
-function getOldStyleData () {
- var config, wallet, seedWords
-
- var result = {
- meta: { version: 0 },
- data: {},
- }
-
- try {
- config = JSON.parse(window.localStorage['config'])
- result.data.config = config
- } catch (e) {}
- try {
- wallet = JSON.parse(window.localStorage['lightwallet'])
- result.data.wallet = wallet
- } catch (e) {}
- try {
- seedWords = window.localStorage['seedWords']
- result.data.seedWords = seedWords
- } catch (e) {}
-
- return result
-}
-
-function setData (data) {
- window.localStorage[STORAGE_KEY] = JSON.stringify(data)
-}
+}) \ No newline at end of file