|
|
|
@ -1,9 +1,4 @@ |
|
|
|
|
/* eslint-disable */ |
|
|
|
|
// Used to inspect long objects
|
|
|
|
|
// util.inspect({JSON}, false, null))
|
|
|
|
|
// const util = require('util')
|
|
|
|
|
import assert from 'assert' |
|
|
|
|
|
|
|
|
|
import sinon from 'sinon' |
|
|
|
|
import { cloneDeep } from 'lodash' |
|
|
|
|
import nock from 'nock' |
|
|
|
@ -14,14 +9,13 @@ import EthQuery from 'eth-query' |
|
|
|
|
import Eth from 'ethjs' |
|
|
|
|
import KeyringController from 'eth-keyring-controller' |
|
|
|
|
import { createTestProviderTools } from '../../../stub/provider' |
|
|
|
|
const provider = createTestProviderTools({ scaffold: {}}).provider |
|
|
|
|
|
|
|
|
|
import enLocale from '../../../../app/_locales/en/messages.json' |
|
|
|
|
import * as actions from '../../../../ui/app/store/actions' |
|
|
|
|
import MetaMaskController from '../../../../app/scripts/metamask-controller' |
|
|
|
|
import firstTimeState from '../../localhostState' |
|
|
|
|
import devState from '../../../data/2-state.json' |
|
|
|
|
|
|
|
|
|
const provider = createTestProviderTools({ scaffold: {} }).provider |
|
|
|
|
const middleware = [thunk] |
|
|
|
|
const mockStore = configureStore(middleware) |
|
|
|
|
|
|
|
|
@ -133,9 +127,9 @@ describe('Actions', () => { |
|
|
|
|
await store.dispatch(actions.tryUnlockMetamask('test')) |
|
|
|
|
assert.fail('Should have thrown error') |
|
|
|
|
} catch (_) { |
|
|
|
|
const actions = store.getActions() |
|
|
|
|
const warning = actions.filter(action => action.type === 'DISPLAY_WARNING') |
|
|
|
|
const unlockFailed = actions.filter(action => action.type === 'UNLOCK_FAILED') |
|
|
|
|
const actions1 = store.getActions() |
|
|
|
|
const warning = actions1.filter(action => action.type === 'DISPLAY_WARNING') |
|
|
|
|
const unlockFailed = actions1.filter(action => action.type === 'UNLOCK_FAILED') |
|
|
|
|
assert.deepEqual(warning, displayWarningError) |
|
|
|
|
assert.deepEqual(unlockFailed, unlockFailedError) |
|
|
|
|
} |
|
|
|
@ -450,7 +444,7 @@ describe('Actions', () => { |
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
checkHardwareStatusSpy.callsFake((deviceName, hdPath, callback) => { |
|
|
|
|
checkHardwareStatusSpy.callsFake((_, __, callback) => { |
|
|
|
|
callback(new Error('error')) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -492,7 +486,7 @@ describe('Actions', () => { |
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
forgetDeviceSpy.callsFake((deviceName, callback) => { |
|
|
|
|
forgetDeviceSpy.callsFake((_, callback) => { |
|
|
|
|
callback(new Error('error')) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -534,7 +528,7 @@ describe('Actions', () => { |
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
connectHardwareSpy.callsFake((deviceName, page, hdPath, callback) => { |
|
|
|
|
connectHardwareSpy.callsFake((_, __, ___, callback) => { |
|
|
|
|
callback(new Error('error')) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -568,7 +562,7 @@ describe('Actions', () => { |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('shows loading indicator and displays error', async() => { |
|
|
|
|
it('shows loading indicator and displays error', async () => { |
|
|
|
|
const store = mockStore() |
|
|
|
|
|
|
|
|
|
const expectedActions = [ |
|
|
|
@ -576,7 +570,7 @@ describe('Actions', () => { |
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
unlockHardwareWalletAccountSpy.callsFake((deviceName, page, hdPath, callback) => { |
|
|
|
|
unlockHardwareWalletAccountSpy.callsFake((_, __, ___, callback) => { |
|
|
|
|
callback(new Error('error')) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -646,7 +640,9 @@ describe('Actions', () => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('calls signMsg in background', () => { |
|
|
|
|
const store = mockStore() |
|
|
|
|
const store = mockStore({ |
|
|
|
|
metamask: {}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
signMessageSpy = sinon.spy(background, 'signMessage') |
|
|
|
|
store.dispatch(actions.signMsg(msgParams)) |
|
|
|
@ -655,7 +651,9 @@ describe('Actions', () => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('errors when signMessage in background throws', async () => { |
|
|
|
|
const store = mockStore() |
|
|
|
|
const store = mockStore({ |
|
|
|
|
metamask: {}, |
|
|
|
|
}) |
|
|
|
|
const expectedActions = [ |
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined }, |
|
|
|
|
{ type: 'UPDATE_METAMASK_STATE', value: undefined }, |
|
|
|
@ -700,7 +698,9 @@ describe('Actions', () => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('calls signPersonalMessage', () => { |
|
|
|
|
const store = mockStore() |
|
|
|
|
const store = mockStore({ |
|
|
|
|
metamask: {}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
signPersonalMessageSpy = sinon.spy(background, 'signPersonalMessage') |
|
|
|
|
|
|
|
|
@ -741,19 +741,19 @@ describe('Actions', () => { |
|
|
|
|
data: JSON.stringify({ |
|
|
|
|
'types': { |
|
|
|
|
'EIP712Domain': [ |
|
|
|
|
{'name': 'name', 'type': 'string'}, |
|
|
|
|
{'name': 'version', 'type': 'string'}, |
|
|
|
|
{'name': 'chainId', 'type': 'uint256'}, |
|
|
|
|
{'name': 'verifyingContract', 'type': 'address'}, |
|
|
|
|
{ 'name': 'name', 'type': 'string' }, |
|
|
|
|
{ 'name': 'version', 'type': 'string' }, |
|
|
|
|
{ 'name': 'chainId', 'type': 'uint256' }, |
|
|
|
|
{ 'name': 'verifyingContract', 'type': 'address' }, |
|
|
|
|
], |
|
|
|
|
'Person': [ |
|
|
|
|
{'name': 'name', 'type': 'string'}, |
|
|
|
|
{'name': 'wallet', 'type': 'address'}, |
|
|
|
|
{ 'name': 'name', 'type': 'string' }, |
|
|
|
|
{ 'name': 'wallet', 'type': 'address' }, |
|
|
|
|
], |
|
|
|
|
'Mail': [ |
|
|
|
|
{'name': 'from', 'type': 'Person'}, |
|
|
|
|
{'name': 'to', 'type': 'Person'}, |
|
|
|
|
{'name': 'contents', 'type': 'string'}, |
|
|
|
|
{ 'name': 'from', 'type': 'Person' }, |
|
|
|
|
{ 'name': 'to', 'type': 'Person' }, |
|
|
|
|
{ 'name': 'contents', 'type': 'string' }, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
'primaryType': 'Mail', |
|
|
|
@ -952,7 +952,7 @@ describe('Actions', () => { |
|
|
|
|
|
|
|
|
|
const txData = { id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: txParams } |
|
|
|
|
|
|
|
|
|
beforeEach( async () => { |
|
|
|
|
beforeEach(async () => { |
|
|
|
|
await metamaskController.txController.txStateManager.addTx(txData) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -976,7 +976,7 @@ describe('Actions', () => { |
|
|
|
|
const store = mockStore() |
|
|
|
|
|
|
|
|
|
updateTransactionSpy = sinon.stub(background, 'updateTransaction') |
|
|
|
|
updateTransactionSpy.callsFake((res, callback) => { |
|
|
|
|
updateTransactionSpy.callsFake((_, callback) => { |
|
|
|
|
callback(new Error('error')) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -1347,7 +1347,7 @@ describe('Actions', () => { |
|
|
|
|
nock('https://shapeshift.io') |
|
|
|
|
.defaultReplyHeaders({ 'access-control-allow-origin': '*' }) |
|
|
|
|
.get('/marketinfo/btc_eth') |
|
|
|
|
.reply(200, {pair: 'BTC_ETH', rate: 25.68289016, minerFee: 0.00176, limit: 0.67748474, minimum: 0.00013569, maxLimit: 0.67758573}) |
|
|
|
|
.reply(200, { pair: 'BTC_ETH', rate: 25.68289016, minerFee: 0.00176, limit: 0.67748474, minimum: 0.00013569, maxLimit: 0.67758573 }) |
|
|
|
|
|
|
|
|
|
nock('https://shapeshift.io') |
|
|
|
|
.defaultReplyHeaders({ 'access-control-allow-origin': '*' }) |
|
|
|
@ -1515,7 +1515,7 @@ describe('Actions', () => { |
|
|
|
|
|
|
|
|
|
const expectedActions = [ |
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined }, |
|
|
|
|
{ type: 'SET_CURRENT_LOCALE', value: { locale: 'en', messages: enLocale }}, |
|
|
|
|
{ type: 'SET_CURRENT_LOCALE', value: { locale: 'en', messages: enLocale } }, |
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|