mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Use default mock store in action tests (#8437)
A simple default store of `{ metamask: {} }` is now used for the actions tests. While I would prefer that any expectations about the store be included in each test, the mere existence of this `metamask` object seems like a fairly reasonable default, as it's (hopefully) impossible for it to be unset at runtime. The `2-state.json` test state file was deleted as well, as it was no longer used.
This commit is contained in:
parent
580a90d543
commit
78fc024636
@ -1,68 +0,0 @@
|
|||||||
{ "isInitialized": true,
|
|
||||||
"provider": { "type": "rpc", "rpcTarget": "http://localhost:8545" },
|
|
||||||
"network": "loading",
|
|
||||||
"accounts": {
|
|
||||||
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
|
|
||||||
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
|
|
||||||
"balance": "0x0"
|
|
||||||
},
|
|
||||||
"0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b": {
|
|
||||||
"address": "0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b",
|
|
||||||
"balance": "0x0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"currentBlockGasLimit": "",
|
|
||||||
"unapprovedTxs": {},
|
|
||||||
"currentNetworkTxList": [],
|
|
||||||
"unapprovedMsgs": {},
|
|
||||||
"unapprovedMsgCount": 0,
|
|
||||||
"unapprovedPersonalMsgs": {},
|
|
||||||
"unapprovedPersonalMsgCount": 0,
|
|
||||||
"unapprovedDecryptMsgs": {},
|
|
||||||
"unapprovedDecryptMsgCount": 0,
|
|
||||||
"unapprovedTypedMessages": {},
|
|
||||||
"unapprovedTypedMessagesCount": 0,
|
|
||||||
"isUnlocked": true,
|
|
||||||
"keyringTypes": [ "Simple Key Pair", "HD Key Tree" ],
|
|
||||||
"keyrings":[
|
|
||||||
{ "type": "HD Key Tree",
|
|
||||||
"accounts": [
|
|
||||||
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "Simple Key Pair",
|
|
||||||
"accounts": [
|
|
||||||
"0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"frequentRpcList": [],
|
|
||||||
"tokens": [],
|
|
||||||
"useBlockie": false,
|
|
||||||
"featureFlags": {},
|
|
||||||
"currentLocale": null,
|
|
||||||
"identities": {
|
|
||||||
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
|
|
||||||
"name": "Account 1",
|
|
||||||
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
|
|
||||||
},
|
|
||||||
"0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b": {
|
|
||||||
"name": "Account 2",
|
|
||||||
"address": "0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"lostIdentities": {},
|
|
||||||
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
|
|
||||||
"recentBlocks": [],
|
|
||||||
"addressBook": [],
|
|
||||||
"currentCurrency": "usd",
|
|
||||||
"conversionRate": 288.45,
|
|
||||||
"conversionDate": 1506444677,
|
|
||||||
"nextUnreadNotice": null,
|
|
||||||
"noActiveNotices": true,
|
|
||||||
"infuraNetworkStatus": {},
|
|
||||||
"seedWords": "debris dizzy just program just float decrease vacant alarm reduce speak stadium",
|
|
||||||
"forgottenPassword": null
|
|
||||||
}
|
|
@ -11,11 +11,11 @@ import enLocale from '../../../../app/_locales/en/messages.json'
|
|||||||
import * as actions from '../../../../ui/app/store/actions'
|
import * as actions from '../../../../ui/app/store/actions'
|
||||||
import MetaMaskController from '../../../../app/scripts/metamask-controller'
|
import MetaMaskController from '../../../../app/scripts/metamask-controller'
|
||||||
import firstTimeState from '../../localhostState'
|
import firstTimeState from '../../localhostState'
|
||||||
import devState from '../../../data/2-state.json'
|
|
||||||
|
|
||||||
const provider = createTestProviderTools({ scaffold: {} }).provider
|
const provider = createTestProviderTools({ scaffold: {} }).provider
|
||||||
const middleware = [thunk]
|
const middleware = [thunk]
|
||||||
const mockStore = configureStore(middleware)
|
const defaultState = { metamask: {} }
|
||||||
|
const mockStore = (state = defaultState) => configureStore(middleware)(state)
|
||||||
|
|
||||||
describe('Actions', function () {
|
describe('Actions', function () {
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
it('calls submitPassword and verifySeedPhrase', async function () {
|
it('calls submitPassword and verifySeedPhrase', async function () {
|
||||||
|
|
||||||
const store = mockStore({})
|
const store = mockStore()
|
||||||
|
|
||||||
submitPasswordSpy = sinon.spy(background, 'submitPassword')
|
submitPasswordSpy = sinon.spy(background, 'submitPassword')
|
||||||
verifySeedPhraseSpy = sinon.spy(background, 'verifySeedPhrase')
|
verifySeedPhraseSpy = sinon.spy(background, 'verifySeedPhrase')
|
||||||
@ -87,7 +87,7 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
it('errors on submitPassword will fail', async function () {
|
it('errors on submitPassword will fail', async function () {
|
||||||
|
|
||||||
const store = mockStore({})
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
@ -112,7 +112,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('displays warning error and unlock failed when verifySeed fails', async function () {
|
it('displays warning error and unlock failed when verifySeed fails', async function () {
|
||||||
const store = mockStore({})
|
const store = mockStore()
|
||||||
const displayWarningError = [ { type: 'DISPLAY_WARNING', value: 'error' } ]
|
const displayWarningError = [ { type: 'DISPLAY_WARNING', value: 'error' } ]
|
||||||
const unlockFailedError = [ { type: 'UNLOCK_FAILED', value: 'error' } ]
|
const unlockFailedError = [ { type: 'UNLOCK_FAILED', value: 'error' } ]
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
it('restores new vault', async function () {
|
it('restores new vault', async function () {
|
||||||
|
|
||||||
const store = mockStore({})
|
const store = mockStore()
|
||||||
|
|
||||||
createNewVaultAndRestoreSpy = sinon.spy(background, 'createNewVaultAndRestore')
|
createNewVaultAndRestoreSpy = sinon.spy(background, 'createNewVaultAndRestore')
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('errors when callback in createNewVaultAndRestore throws', async function () {
|
it('errors when callback in createNewVaultAndRestore throws', async function () {
|
||||||
const store = mockStore({})
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
@ -228,7 +228,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('calls removeAccount in background and expect actions to show account', async function () {
|
it('calls removeAccount in background and expect actions to show account', async function () {
|
||||||
const store = mockStore(devState)
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
'SHOW_LOADING_INDICATION',
|
'SHOW_LOADING_INDICATION',
|
||||||
@ -367,7 +367,7 @@ describe('Actions', function () {
|
|||||||
describe('#addNewAccount', function () {
|
describe('#addNewAccount', function () {
|
||||||
|
|
||||||
it('Adds a new account', async function () {
|
it('Adds a new account', async function () {
|
||||||
const store = mockStore({ metamask: devState })
|
const store = mockStore({ metamask: { identities: {} } })
|
||||||
|
|
||||||
const addNewAccountSpy = sinon.spy(background, 'addNewAccount')
|
const addNewAccountSpy = sinon.spy(background, 'addNewAccount')
|
||||||
|
|
||||||
@ -578,9 +578,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('calls signMsg in background', async function () {
|
it('calls signMsg in background', async function () {
|
||||||
const store = mockStore({
|
const store = mockStore()
|
||||||
metamask: {},
|
|
||||||
})
|
|
||||||
|
|
||||||
signMessageSpy = sinon.spy(background, 'signMessage')
|
signMessageSpy = sinon.spy(background, 'signMessage')
|
||||||
await store.dispatch(actions.signMsg(msgParams))
|
await store.dispatch(actions.signMsg(msgParams))
|
||||||
@ -589,9 +587,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('errors when signMessage in background throws', async function () {
|
it('errors when signMessage in background throws', async function () {
|
||||||
const store = mockStore({
|
const store = mockStore()
|
||||||
metamask: {},
|
|
||||||
})
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
{ type: 'HIDE_LOADING_INDICATION' },
|
||||||
@ -635,9 +631,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('calls signPersonalMessage', async function () {
|
it('calls signPersonalMessage', async function () {
|
||||||
const store = mockStore({
|
const store = mockStore()
|
||||||
metamask: {},
|
|
||||||
})
|
|
||||||
|
|
||||||
signPersonalMessageSpy = sinon.spy(background, 'signPersonalMessage')
|
signPersonalMessageSpy = sinon.spy(background, 'signPersonalMessage')
|
||||||
|
|
||||||
@ -726,8 +720,8 @@ describe('Actions', function () {
|
|||||||
|
|
||||||
it('calls signTypedMsg in background with no error', async function () {
|
it('calls signTypedMsg in background with no error', async function () {
|
||||||
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
||||||
.callsArgWith(1, null, devState)
|
.callsArgWith(1, null, defaultState)
|
||||||
const store = mockStore({ metamask: devState })
|
const store = mockStore()
|
||||||
|
|
||||||
await store.dispatch(actions.signTypedMsg(msgParamsV3))
|
await store.dispatch(actions.signTypedMsg(msgParamsV3))
|
||||||
assert(signTypedMsgSpy.calledOnce)
|
assert(signTypedMsgSpy.calledOnce)
|
||||||
@ -736,7 +730,7 @@ describe('Actions', function () {
|
|||||||
it('returns expected actions with error', async function () {
|
it('returns expected actions with error', async function () {
|
||||||
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
|
||||||
.callsArgWith(1, new Error('error'))
|
.callsArgWith(1, new Error('error'))
|
||||||
const store = mockStore({ metamask: devState })
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
{ type: 'HIDE_LOADING_INDICATION' },
|
||||||
@ -953,7 +947,7 @@ describe('Actions', function () {
|
|||||||
it('calls setSelectedAddress in background', async function () {
|
it('calls setSelectedAddress in background', async function () {
|
||||||
setSelectedAddressSpy = sinon.stub(background, 'setSelectedAddress')
|
setSelectedAddressSpy = sinon.stub(background, 'setSelectedAddress')
|
||||||
.callsArgWith(1, null)
|
.callsArgWith(1, null)
|
||||||
const store = mockStore({ metamask: devState })
|
const store = mockStore()
|
||||||
|
|
||||||
await store.dispatch(actions.setSelectedAddress('0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'))
|
await store.dispatch(actions.setSelectedAddress('0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'))
|
||||||
assert(setSelectedAddressSpy.calledOnce)
|
assert(setSelectedAddressSpy.calledOnce)
|
||||||
@ -1144,7 +1138,7 @@ describe('Actions', function () {
|
|||||||
describe('#addToAddressBook', function () {
|
describe('#addToAddressBook', function () {
|
||||||
it('calls setAddressBook', function () {
|
it('calls setAddressBook', function () {
|
||||||
const addToAddressBookSpy = sinon.stub(background, 'setAddressBook')
|
const addToAddressBookSpy = sinon.stub(background, 'setAddressBook')
|
||||||
const store = mockStore({ metamask: devState })
|
const store = mockStore()
|
||||||
store.dispatch(actions.addToAddressBook('test'))
|
store.dispatch(actions.addToAddressBook('test'))
|
||||||
assert(addToAddressBookSpy.calledOnce)
|
assert(addToAddressBookSpy.calledOnce)
|
||||||
addToAddressBookSpy.restore()
|
addToAddressBookSpy.restore()
|
||||||
@ -1160,7 +1154,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns expected actions for successful action', async function () {
|
it('returns expected actions for successful action', async function () {
|
||||||
const store = mockStore(devState)
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
{ type: 'HIDE_LOADING_INDICATION' },
|
||||||
@ -1177,7 +1171,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns action errors when first func callback errors', async function () {
|
it('returns action errors when first func callback errors', async function () {
|
||||||
const store = mockStore(devState)
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
{ type: 'HIDE_LOADING_INDICATION' },
|
||||||
@ -1198,7 +1192,7 @@ describe('Actions', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns action errors when second func callback errors', async function () {
|
it('returns action errors when second func callback errors', async function () {
|
||||||
const store = mockStore(devState)
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
{ type: 'HIDE_LOADING_INDICATION' },
|
||||||
|
Loading…
Reference in New Issue
Block a user