mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
tests - remove persistence and start with initial state
This commit is contained in:
parent
ad9531d521
commit
3afd0ef27d
@ -29,15 +29,7 @@ ConfigManager.prototype.setConfig = function (config) {
|
|||||||
|
|
||||||
ConfigManager.prototype.getConfig = function () {
|
ConfigManager.prototype.getConfig = function () {
|
||||||
var data = this.getData()
|
var data = this.getData()
|
||||||
if ('config' in data) {
|
return data.config
|
||||||
return data.config
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
provider: {
|
|
||||||
type: 'testnet',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.prototype.setRpcTarget = function (rpcUrl) {
|
ConfigManager.prototype.setRpcTarget = function (rpcUrl) {
|
||||||
|
@ -4,12 +4,13 @@ const ObservableStore = require('obs-store')
|
|||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const BN = ethUtil.BN
|
const BN = ethUtil.BN
|
||||||
const ConfigManager = require('../../app/scripts/lib/config-manager')
|
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 delegateCallCode = require('../lib/example-code.json').delegateCallCode
|
||||||
|
const clone = require('clone')
|
||||||
|
|
||||||
// The old way:
|
// The old way:
|
||||||
const IdentityStore = require('../../app/scripts/lib/idStore')
|
const IdentityStore = require('../../app/scripts/lib/idStore')
|
||||||
const STORAGE_KEY = 'metamask-config'
|
const STORAGE_KEY = 'metamask-config'
|
||||||
const extend = require('xtend')
|
|
||||||
|
|
||||||
// The new ways:
|
// The new ways:
|
||||||
var KeyringController = require('../../app/scripts/keyring-controller')
|
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.
|
// and THEN create a new one, before we can run tests on it.
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
this.sinon = sinon.sandbox.create()
|
this.sinon = sinon.sandbox.create()
|
||||||
window.localStorage = {} // Hacking localStorage support into JSDom
|
let store = new ObservableStore(clone(firstTimeState))
|
||||||
let store = new ObservableStore(loadData())
|
|
||||||
store.subscribe(setData)
|
|
||||||
configManager = new ConfigManager({ store })
|
configManager = new ConfigManager({ store })
|
||||||
|
|
||||||
|
|
||||||
idStore = new IdentityStore({
|
idStore = new IdentityStore({
|
||||||
configManager: configManager,
|
configManager: configManager,
|
||||||
ethStore: {
|
ethStore: {
|
||||||
@ -94,53 +92,3 @@ describe('IdentityStore to KeyringController migration', function() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
var assert = require('assert')
|
const assert = require('assert')
|
||||||
var MetaMaskController = require('../../app/scripts/metamask-controller')
|
const sinon = require('sinon')
|
||||||
var sinon = require('sinon')
|
const clone = require('clone')
|
||||||
var extend = require('xtend')
|
const MetaMaskController = require('../../app/scripts/metamask-controller')
|
||||||
|
const firstTimeState = require('../../app/scripts/first-time-state')
|
||||||
|
|
||||||
const STORAGE_KEY = 'metamask-config'
|
const STORAGE_KEY = 'metamask-config'
|
||||||
|
|
||||||
describe('MetaMaskController', function() {
|
describe('MetaMaskController', function() {
|
||||||
@ -11,15 +13,12 @@ describe('MetaMaskController', function() {
|
|||||||
unlockAccountMessage: noop,
|
unlockAccountMessage: noop,
|
||||||
showUnapprovedTx: noop,
|
showUnapprovedTx: noop,
|
||||||
// initial state
|
// initial state
|
||||||
initState: loadData(),
|
initState: clone(firstTimeState),
|
||||||
})
|
})
|
||||||
// setup state persistence
|
|
||||||
controller.store.subscribe(setData)
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
// sinon allows stubbing methods that are easily verified
|
// sinon allows stubbing methods that are easily verified
|
||||||
this.sinon = sinon.sandbox.create()
|
this.sinon = sinon.sandbox.create()
|
||||||
window.localStorage = {} // Hacking localStorage support into JSDom
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@ -28,54 +27,3 @@ describe('MetaMaskController', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user