feature/default_network_editable
Thomas Huang 8 years ago committed by kumavis
parent 8af41f1b05
commit 13e6672028
  1. 2
      app/scripts/background.js
  2. 4
      app/scripts/lib/migrator/index.js
  3. 2
      test/lib/mock-store.js
  4. 6
      test/unit/components/bn-as-decimal-input-test.js
  5. 31
      test/unit/components/pending-tx-test.js
  6. 1
      test/unit/explorer-link-test.js
  7. 2
      test/unit/migrator-test.js
  8. 8
      test/unit/network-contoller-test.js
  9. 1
      test/unit/tx-controller-test.js

@ -31,7 +31,7 @@ const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
// initialization flow // initialization flow
initialize().catch(console.error) initialize().catch(console.error)
async function initialize() { async function initialize () {
const initState = await loadStateFromPersistence() const initState = await loadStateFromPersistence()
await setupController(initState) await setupController(initState)
console.log('MetaMask initialization complete.') console.log('MetaMask initialization complete.')

@ -14,8 +14,8 @@ class Migrator {
async migrateData (versionedData = this.generateInitialState()) { async migrateData (versionedData = this.generateInitialState()) {
const pendingMigrations = this.migrations.filter(migrationIsPending) const pendingMigrations = this.migrations.filter(migrationIsPending)
for (let index in pendingMigrations) { for (const index in pendingMigrations) {
let migration = pendingMigrations[index] const migration = pendingMigrations[index]
versionedData = await migration.migrate(versionedData) versionedData = await migration.migrate(versionedData)
if (!versionedData.data) throw new Error('Migrator - migration returned empty data') if (!versionedData.data) throw new Error('Migrator - migration returned empty data')
if (versionedData.version !== undefined && versionedData.meta.version !== migration.version) throw new Error('Migrator - Migration did not update version number correctly') if (versionedData.version !== undefined && versionedData.meta.version !== migration.version) throw new Error('Migrator - Migration did not update version number correctly')

@ -2,7 +2,7 @@ const createStore = require('redux').createStore
const applyMiddleware = require('redux').applyMiddleware const applyMiddleware = require('redux').applyMiddleware
const thunkMiddleware = require('redux-thunk') const thunkMiddleware = require('redux-thunk')
const createLogger = require('redux-logger') const createLogger = require('redux-logger')
const rootReducer = function() {} const rootReducer = function () {}
module.exports = configureStore module.exports = configureStore

@ -18,7 +18,7 @@ describe('BnInput', function () {
} }
const value = new BN(valueStr, 10) const value = new BN(valueStr, 10)
let inputStr = '2.3' const inputStr = '2.3'
let targetStr = '23' let targetStr = '23'
while (targetStr.length < 19) { while (targetStr.length < 19) {
@ -43,9 +43,9 @@ describe('BnInput', function () {
const component = additions.renderIntoDocument(inputComponent) const component = additions.renderIntoDocument(inputComponent)
renderer.render(inputComponent) renderer.render(inputComponent)
const input = additions.find(component, 'input.hex-input')[0] const input = additions.find(component, 'input.hex-input')[0]
ReactTestUtils.Simulate.change(input, { preventDefault() {}, target: { ReactTestUtils.Simulate.change(input, { preventDefault () {}, target: {
value: inputStr, value: inputStr,
checkValidity() { return true } }, checkValidity () { return true } },
}) })
}) })
}) })

@ -15,23 +15,22 @@ describe('PendingTx', function () {
const gasPrice = '0x4A817C800' // 20 Gwei const gasPrice = '0x4A817C800' // 20 Gwei
const txData = { const txData = {
'id':5021615666270214, 'id': 5021615666270214,
'time':1494458763011, 'time': 1494458763011,
'status':'unapproved', 'status': 'unapproved',
'metamaskNetworkId':'1494442339676', 'metamaskNetworkId': '1494442339676',
'txParams':{ 'txParams': {
'from':'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826', 'from': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b826',
'to':'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb', 'to': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'value':'0xde0b6b3a7640000', 'value': '0xde0b6b3a7640000',
gasPrice, gasPrice,
'gas':'0x7b0c'}, 'gas': '0x7b0c'},
'gasLimitSpecified':false, 'gasLimitSpecified': false,
'estimatedGas':'0x5208', 'estimatedGas': '0x5208',
} }
it('should use updated values when edited.', function (done) { it('should use updated values when edited.', function (done) {
const renderer = ReactTestUtils.createRenderer() const renderer = ReactTestUtils.createRenderer()
const newGasPrice = '0x77359400' const newGasPrice = '0x77359400'
@ -40,7 +39,6 @@ describe('PendingTx', function () {
accounts: identities, accounts: identities,
txData, txData,
sendTransaction: (txMeta, event) => { sendTransaction: (txMeta, event) => {
// Assert changes: // Assert changes:
const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice) const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice)
assert.notEqual(result, gasPrice, 'gas price should change') assert.notEqual(result, gasPrice, 'gas price should change')
@ -60,17 +58,16 @@ describe('PendingTx', function () {
ReactTestUtils.Simulate.change(input, { ReactTestUtils.Simulate.change(input, {
target: { target: {
value: 2, value: 2,
checkValidity() { return true }, checkValidity () { return true },
}, },
}) })
const form = additions.find(component, 'form')[0] const form = additions.find(component, 'form')[0]
form.checkValidity = () => true form.checkValidity = () => true
form.getFormEl = () => { return { checkValidity() { return true } } } form.getFormEl = () => { return { checkValidity () { return true } } }
ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() { ReactTestUtils.Simulate.submit(form, { preventDefault () {}, target: { checkValidity () {
return true return true
} } }) } } })
} catch (e) { } catch (e) {
console.log('WHAAAA') console.log('WHAAAA')
console.error(e) console.error(e)

@ -11,5 +11,4 @@ describe('explorer-link', function () {
var result = linkGen('hash', '42') var result = linkGen('hash', '42')
assert.notEqual(result.indexOf('kovan'), -1, 'kovan injected') assert.notEqual(result.indexOf('kovan'), -1, 'kovan injected')
}) })
}) })

@ -28,7 +28,7 @@ const migrations = [
}, },
}, },
] ]
const versionedData = {meta: {version: 0}, data:{hello:'world'}} const versionedData = {meta: {version: 0}, data: {hello: 'world'}}
describe('Migrator', () => { describe('Migrator', () => {
const migrator = new Migrator({ migrations }) const migrator = new Migrator({ migrations })
it('migratedData version should be version 3', (done) => { it('migratedData version should be version 3', (done) => {

@ -27,7 +27,7 @@ describe('# Network Controller', function () {
}) })
}) })
describe('network', function () { describe('network', function () {
describe('#provider', function() { describe('#provider', function () {
it('provider should be updatable without reassignment', function () { it('provider should be updatable without reassignment', function () {
networkController.initializeProvider(networkController.providerInit) networkController.initializeProvider(networkController.providerInit)
const provider = networkController.provider const provider = networkController.provider
@ -37,7 +37,7 @@ describe('# Network Controller', function () {
}) })
describe('#getNetworkState', function () { describe('#getNetworkState', function () {
it('should return loading when new', function () { it('should return loading when new', function () {
let networkState = networkController.getNetworkState() const networkState = networkController.getNetworkState()
assert.equal(networkState, 'loading', 'network is loading') assert.equal(networkState, 'loading', 'network is loading')
}) })
}) })
@ -45,14 +45,14 @@ describe('# Network Controller', function () {
describe('#setNetworkState', function () { describe('#setNetworkState', function () {
it('should update the network', function () { it('should update the network', function () {
networkController.setNetworkState(1) networkController.setNetworkState(1)
let networkState = networkController.getNetworkState() const networkState = networkController.getNetworkState()
assert.equal(networkState, 1, 'network is 1') assert.equal(networkState, 1, 'network is 1')
}) })
}) })
describe('#getRpcAddressForType', function () { describe('#getRpcAddressForType', function () {
it('should return the right rpc address', function () { it('should return the right rpc address', function () {
let rpcTarget = networkController.getRpcAddressForType('mainnet') const rpcTarget = networkController.getRpcAddressForType('mainnet')
assert.equal(rpcTarget, 'https://mainnet.infura.io/metamask', 'returns the right rpcAddress') assert.equal(rpcTarget, 'https://mainnet.infura.io/metamask', 'returns the right rpcAddress')
}) })
}) })

@ -320,5 +320,4 @@ describe('Transaction Controller', function () {
}) })
}) })
}) })
}) })

Loading…
Cancel
Save