2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import configureStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
2021-04-28 21:53:59 +02:00
|
|
|
import enLocale from '../../app/_locales/en/messages.json';
|
|
|
|
import MetaMaskController from '../../app/scripts/metamask-controller';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionStatus } from '../../shared/constants/transaction';
|
2023-01-20 16:14:40 +01:00
|
|
|
import { HardwareDeviceNames } from '../../shared/constants/hardware-wallets';
|
2021-06-08 17:25:48 +02:00
|
|
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
2023-03-09 22:00:28 +01:00
|
|
|
import { ORIGIN_METAMASK } from '../../shared/constants/app';
|
2023-04-03 17:31:04 +02:00
|
|
|
import { MetaMetricsNetworkEventSource } from '../../shared/constants/metametrics';
|
2021-03-16 22:00:08 +01:00
|
|
|
import * as actions from './actions';
|
2022-09-05 16:55:34 +02:00
|
|
|
import { _setBackgroundConnection } from './action-queue';
|
2021-02-04 19:15:23 +01:00
|
|
|
|
|
|
|
const middleware = [thunk];
|
2021-02-02 09:55:12 +01:00
|
|
|
const defaultState = {
|
|
|
|
metamask: {
|
|
|
|
currentLocale: 'test',
|
|
|
|
selectedAddress: '0xFirstAddress',
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: { chainId: '0x1' },
|
2021-06-23 23:35:25 +02:00
|
|
|
accounts: {
|
|
|
|
'0xFirstAddress': {
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
},
|
2022-08-16 08:12:00 +02:00
|
|
|
identities: {
|
|
|
|
'0xFirstAddress': {},
|
|
|
|
},
|
2021-06-23 23:35:25 +02:00
|
|
|
cachedBalances: {
|
|
|
|
'0x1': {
|
|
|
|
'0xFirstAddress': '0x0',
|
|
|
|
},
|
|
|
|
},
|
2020-10-06 20:28:38 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const mockStore = (state = defaultState) => configureStore(middleware)(state);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
const baseMockState = defaultState.metamask;
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Actions', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let background;
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-09-29 05:26:01 +02:00
|
|
|
const currentNetworkId = '5';
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(async () => {
|
2021-02-02 09:55:12 +01:00
|
|
|
background = sinon.createStubInstance(MetaMaskController, {
|
2021-06-23 23:35:25 +02:00
|
|
|
getState: sinon.stub().callsFake((cb) => cb(null, baseMockState)),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2023-03-20 14:19:50 +01:00
|
|
|
|
|
|
|
background.signMessage = sinon.stub();
|
|
|
|
background.signPersonalMessage = sinon.stub();
|
|
|
|
background.signTypedMessage = sinon.stub();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#tryUnlockMetamask', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-11-30 16:43:49 +01:00
|
|
|
it('calls submitPassword', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
const submitPassword = background.submitPassword.callsFake((_, cb) =>
|
|
|
|
cb(),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'UNLOCK_IN_PROGRESS' },
|
|
|
|
{ type: 'UNLOCK_SUCCEEDED', value: undefined },
|
|
|
|
{
|
|
|
|
type: 'UPDATE_METAMASK_STATE',
|
2021-06-23 23:35:25 +02:00
|
|
|
value: baseMockState,
|
2021-02-02 09:55:12 +01:00
|
|
|
},
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.tryUnlockMetamask());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(submitPassword.callCount).toStrictEqual(1);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors on submitPassword will fail', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.submitPassword.callsFake((_, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'UNLOCK_IN_PROGRESS' },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'UNLOCK_FAILED', value: 'error' },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.tryUnlockMetamask('test')),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#createNewVaultAndRestore', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls createNewVaultAndRestore', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-07-31 20:26:40 +02:00
|
|
|
const createNewVaultAndRestore =
|
|
|
|
background.createNewVaultAndRestore.callsFake((_, __, cb) => cb());
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.unMarkPasswordForgotten.callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-07-30 23:37:40 +02:00
|
|
|
await store.dispatch(
|
|
|
|
actions.createNewVaultAndRestore('password', 'test'),
|
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(createNewVaultAndRestore.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls the expected actions', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.createNewVaultAndRestore.callsFake((_, __, cb) => cb());
|
|
|
|
background.unMarkPasswordForgotten.callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2021-02-02 09:55:12 +01:00
|
|
|
{
|
|
|
|
type: 'UPDATE_METAMASK_STATE',
|
2021-06-23 23:35:25 +02:00
|
|
|
value: baseMockState,
|
2021-02-02 09:55:12 +01:00
|
|
|
},
|
|
|
|
{ type: 'SHOW_ACCOUNTS_PAGE' },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-07-30 23:37:40 +02:00
|
|
|
await store.dispatch(
|
|
|
|
actions.createNewVaultAndRestore('password', 'test'),
|
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when callback in createNewVaultAndRestore throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.createNewVaultAndRestore.callsFake((_, __, cb) =>
|
|
|
|
cb(new Error('error')),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
2021-07-30 23:37:40 +02:00
|
|
|
store.dispatch(actions.createNewVaultAndRestore('password', 'test')),
|
2021-04-15 20:01:46 +02:00
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#requestRevealSeedWords', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-10-23 02:23:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls verifyPassword in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
const verifyPassword = background.verifyPassword.callsFake((_, cb) =>
|
|
|
|
cb(),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
const verifySeedPhrase = background.verifySeedPhrase.callsFake((cb) =>
|
2021-07-30 23:37:40 +02:00
|
|
|
cb(null, Array.from(Buffer.from('test').values())),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.requestRevealSeedWords());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(verifyPassword.callCount).toStrictEqual(1);
|
|
|
|
expect(verifySeedPhrase.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('displays warning error message then callback in background errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.verifyPassword.callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
background.verifySeedPhrase.callsFake((cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.requestRevealSeedWords()),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#removeAccount', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls removeAccount in background and expect actions to show account', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-10-23 02:23:18 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.getState.callsFake((cb) =>
|
|
|
|
cb(null, {
|
|
|
|
currentLocale: 'test',
|
|
|
|
selectedAddress: '0xAnotherAddress',
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2021-06-23 23:35:25 +02:00
|
|
|
chainId: '0x1',
|
|
|
|
},
|
|
|
|
accounts: {
|
|
|
|
'0xAnotherAddress': {
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cachedBalances: {
|
|
|
|
'0x1': {
|
|
|
|
'0xAnotherAddress': '0x0',
|
|
|
|
},
|
|
|
|
},
|
2021-02-02 09:55:12 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const removeAccount = background.removeAccount.callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2020-01-16 18:43:40 +01:00
|
|
|
'SHOW_LOADING_INDICATION',
|
2020-04-29 19:10:51 +02:00
|
|
|
'SELECTED_ADDRESS_CHANGED',
|
2021-06-23 23:35:25 +02:00
|
|
|
'ACCOUNT_CHANGED',
|
|
|
|
'SELECTED_ACCOUNT_CHANGED',
|
2020-01-16 18:43:40 +01:00
|
|
|
'UPDATE_METAMASK_STATE',
|
|
|
|
'HIDE_LOADING_INDICATION',
|
|
|
|
'SHOW_ACCOUNTS_PAGE',
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
|
|
|
actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(removeAccount.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
const actionTypes = store.getActions().map((action) => action.type);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actionTypes).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('displays warning error message when removeAccount callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-10-23 02:23:18 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.removeAccount.callsFake((_, cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-04-15 20:01:46 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2019-10-23 02:23:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(
|
2020-11-03 00:41:28 +01:00
|
|
|
actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'),
|
2021-04-15 20:01:46 +02:00
|
|
|
),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#resetAccount', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('resets account', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const resetAccount = background.resetAccount.callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'SHOW_ACCOUNTS_PAGE' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.resetAccount());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(resetAccount.callCount).toStrictEqual(1);
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('throws if resetAccount throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.resetAccount.callsFake((cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(store.dispatch(actions.resetAccount())).rejects.toThrow(
|
|
|
|
'error',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#importNewAccount', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls importAccountWithStrategies in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-07-31 20:26:40 +02:00
|
|
|
const importAccountWithStrategy =
|
|
|
|
background.importAccountWithStrategy.callsFake((_, __, cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb();
|
2022-07-31 20:26:40 +02:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
2023-03-06 18:48:28 +01:00
|
|
|
actions.importNewAccount(
|
|
|
|
'Private Key',
|
|
|
|
['c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3'],
|
|
|
|
'',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(importAccountWithStrategy.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('displays warning error message when importAccount in background callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.importAccountWithStrategy.callsFake((_, __, cb) =>
|
|
|
|
cb(new Error('error')),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'SHOW_LOADING_INDICATION',
|
2023-03-06 18:48:28 +01:00
|
|
|
payload: undefined,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(store.dispatch(actions.importNewAccount())).rejects.toThrow(
|
|
|
|
'error',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#addNewAccount', () => {
|
|
|
|
it('adds a new account', async () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
const store = mockStore({
|
|
|
|
metamask: { identities: {}, ...defaultState.metamask },
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-08-16 08:12:00 +02:00
|
|
|
const addNewAccount = background.addNewAccount.callsFake((_, cb) =>
|
2021-02-02 09:55:12 +01:00
|
|
|
cb(null, {
|
|
|
|
identities: {},
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-08-16 08:12:00 +02:00
|
|
|
await store.dispatch(actions.addNewAccount(1));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(addNewAccount.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('displays warning error message when addNewAccount in background callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-08-16 08:12:00 +02:00
|
|
|
background.addNewAccount.callsFake((_, cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-08-16 08:12:00 +02:00
|
|
|
await expect(store.dispatch(actions.addNewAccount(1))).rejects.toThrow(
|
2021-04-15 20:01:46 +02:00
|
|
|
'error',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#checkHardwareStatus', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls checkHardwareStatus in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
const checkHardwareStatus = background.checkHardwareStatus.callsFake(
|
|
|
|
(_, __, cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb();
|
2021-02-02 09:55:12 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
2023-01-20 16:14:40 +01:00
|
|
|
actions.checkHardwareStatus(
|
|
|
|
HardwareDeviceNames.ledger,
|
|
|
|
`m/44'/60'/0'/0`,
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(checkHardwareStatus.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('shows loading indicator and displays error', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.checkHardwareStatus.callsFake((_, __, cb) =>
|
|
|
|
cb(new Error('error')),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2019-09-26 20:52:51 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.checkHardwareStatus()),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#forgetDevice', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls forgetDevice in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const forgetDevice = background.forgetDevice.callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-01-20 16:14:40 +01:00
|
|
|
await store.dispatch(actions.forgetDevice(HardwareDeviceNames.ledger));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(forgetDevice.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('shows loading indicator and displays error', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.forgetDevice.callsFake((_, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2019-09-26 20:52:51 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(store.dispatch(actions.forgetDevice())).rejects.toThrow(
|
|
|
|
'error',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#connectHardware', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls connectHardware in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
const connectHardware = background.connectHardware.callsFake(
|
|
|
|
(_, __, ___, cb) => cb(),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-11-05 17:13:29 +01:00
|
|
|
background.establishLedgerTransportPreference.callsFake((cb) => cb());
|
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
2023-01-20 16:14:40 +01:00
|
|
|
actions.connectHardware(
|
|
|
|
HardwareDeviceNames.ledger,
|
|
|
|
0,
|
|
|
|
`m/44'/60'/0'/0`,
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(connectHardware.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('shows loading indicator and displays error', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.connectHardware.callsFake((_, __, ___, cb) =>
|
|
|
|
cb(new Error('error')),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-11-05 17:13:29 +01:00
|
|
|
background.establishLedgerTransportPreference.callsFake((cb) => cb());
|
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2019-09-26 20:52:51 +02:00
|
|
|
const expectedActions = [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'SHOW_LOADING_INDICATION',
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: 'Looking for your Ledger...',
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
2023-01-20 16:14:40 +01:00
|
|
|
store.dispatch(actions.connectHardware(HardwareDeviceNames.ledger)),
|
2021-04-15 20:01:46 +02:00
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#unlockHardwareWalletAccount', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls unlockHardwareWalletAccount in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2022-07-31 20:26:40 +02:00
|
|
|
const unlockHardwareWalletAccount =
|
|
|
|
background.unlockHardwareWalletAccount.callsFake(
|
|
|
|
(_, __, ___, ____, cb) => cb(),
|
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
2021-03-09 21:39:16 +01:00
|
|
|
actions.unlockHardwareWalletAccounts(
|
|
|
|
[0],
|
2023-01-20 16:14:40 +01:00
|
|
|
HardwareDeviceNames.ledger,
|
2021-03-09 21:39:16 +01:00
|
|
|
`m/44'/60'/0'/0`,
|
|
|
|
'',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(unlockHardwareWalletAccount.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('shows loading indicator and displays error', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
background.unlockHardwareWalletAccount.callsFake((_, __, ___, ____, cb) =>
|
2021-02-02 09:55:12 +01:00
|
|
|
cb(new Error('error')),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2019-09-26 20:52:51 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-03-09 21:39:16 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.unlockHardwareWalletAccounts([null])),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setCurrentCurrency', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setCurrentCurrency', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-05-20 04:57:51 +02:00
|
|
|
background.setCurrentCurrency = sinon.stub().callsFake((_, cb) => cb());
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setCurrentCurrency('jpy'));
|
2021-05-07 16:02:22 +02:00
|
|
|
expect(background.setCurrentCurrency.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('throws if setCurrentCurrency throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-05-20 04:57:51 +02:00
|
|
|
background.setCurrentCurrency = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setCurrentCurrency());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#updateTransaction', () => {
|
2019-09-26 20:52:51 +02:00
|
|
|
const txParams = {
|
2020-11-03 00:41:28 +01:00
|
|
|
from: '0x1',
|
2021-06-08 17:25:48 +02:00
|
|
|
gas: GAS_LIMITS.SIMPLE,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasPrice: '0x3b9aca00',
|
|
|
|
to: '0x2',
|
|
|
|
value: '0x0',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const txData = {
|
|
|
|
id: '1',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('updates transaction', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const updateTransactionStub = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
updateTransaction: updateTransactionStub,
|
2021-06-23 23:35:25 +02:00
|
|
|
getState: sinon.stub().callsFake((cb) => cb(null, baseMockState)),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.updateTransaction(txData));
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const resultantActions = store.getActions();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(updateTransactionStub.callCount).toStrictEqual(1);
|
|
|
|
expect(resultantActions[1]).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
type: 'UPDATE_TRANSACTION_PARAMS',
|
|
|
|
id: txData.id,
|
|
|
|
value: txParams,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('rejects with error message', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.getApi.returns({
|
|
|
|
updateTransaction: (_, callback) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
callback(new Error('error'));
|
2021-02-02 09:55:12 +01:00
|
|
|
},
|
|
|
|
getState: sinon.stub().callsFake((cb) =>
|
|
|
|
cb(null, {
|
|
|
|
currentLocale: 'test',
|
|
|
|
selectedAddress: '0xFirstAddress',
|
|
|
|
}),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2021-04-15 20:01:46 +02:00
|
|
|
{
|
|
|
|
type: 'UPDATE_TRANSACTION_PARAMS',
|
|
|
|
id: '1',
|
|
|
|
value: {
|
|
|
|
from: '0x1',
|
2021-06-08 17:25:48 +02:00
|
|
|
gas: GAS_LIMITS.SIMPLE,
|
2021-04-15 20:01:46 +02:00
|
|
|
gasPrice: '0x3b9aca00',
|
|
|
|
to: '0x2',
|
|
|
|
value: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'GO_HOME' },
|
|
|
|
];
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.updateTransaction(txData)),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-26 20:52:51 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#lockMetamask', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setLocked', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const backgroundSetLocked = background.setLocked.callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.lockMetamask());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(backgroundSetLocked.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns display warning error with value when setLocked in background callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.setLocked.callsFake((cb) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'LOCK_METAMASK' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await store.dispatch(actions.lockMetamask());
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setSelectedAddress', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setSelectedAddress in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const setSelectedAddressSpy = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setSelectedAddress: setSelectedAddressSpy,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
|
|
|
actions.setSelectedAddress(
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setSelectedAddressSpy.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when setSelectedAddress throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const setSelectedAddressSpy = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setSelectedAddress: setSelectedAddressSpy,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setSelectedAddress());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-02-02 23:00:05 +01:00
|
|
|
describe('#setSelectedAccount', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-02-02 23:00:05 +01:00
|
|
|
it('#setSelectedAccount', async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const store = mockStore({
|
|
|
|
activeTab: {},
|
|
|
|
metamask: { alertEnabledness: {}, selectedAddress: '0x123' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const setSelectedAddressSpy = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setSelectedAddress: setSelectedAddressSpy,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-02-02 23:00:05 +01:00
|
|
|
await store.dispatch(actions.setSelectedAccount());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setSelectedAddressSpy.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
it('displays warning if setSelectedAccount throws', async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const store = mockStore({
|
|
|
|
activeTab: {},
|
|
|
|
metamask: { alertEnabledness: {}, selectedAddress: '0x123' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const setSelectedAddressSpy = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setSelectedAddress: setSelectedAddressSpy,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-02-02 23:00:05 +01:00
|
|
|
await store.dispatch(actions.setSelectedAccount());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#addToken', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls addToken in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
const addTokenStub = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, __, ___, ____, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
addToken: addTokenStub,
|
2021-09-10 19:37:19 +02:00
|
|
|
getState: sinon.stub().callsFake((cb) => cb(null, baseMockState)),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-03-29 23:05:36 +02:00
|
|
|
await store.dispatch(
|
|
|
|
actions.addToken({
|
|
|
|
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
|
|
|
|
symbol: 'LINK',
|
|
|
|
decimals: 18,
|
|
|
|
}),
|
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(addTokenStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('expected actions', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const tokenDetails = {
|
|
|
|
address: 'tokenAddress',
|
|
|
|
symbol: 'token',
|
|
|
|
decimal: 18,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const addTokenStub = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, __, ___, ____, cb) => cb(null, tokenDetails));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
addToken: addTokenStub,
|
2021-09-10 19:37:19 +02:00
|
|
|
getState: sinon.stub().callsFake((cb) => cb(null, baseMockState)),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2021-02-02 09:55:12 +01:00
|
|
|
{
|
2021-09-10 19:37:19 +02:00
|
|
|
type: 'UPDATE_METAMASK_STATE',
|
|
|
|
value: baseMockState,
|
2021-02-02 09:55:12 +01:00
|
|
|
},
|
2021-09-10 19:37:19 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-03-29 23:05:36 +02:00
|
|
|
await store.dispatch(
|
|
|
|
actions.addToken({
|
|
|
|
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
|
|
|
|
symbol: 'LINK',
|
|
|
|
decimals: 18,
|
|
|
|
}),
|
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
describe('#ignoreTokens', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
it('calls ignoreTokens in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
const ignoreTokensStub = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
2022-07-18 16:43:30 +02:00
|
|
|
ignoreTokens: ignoreTokensStub,
|
2021-09-10 19:37:19 +02:00
|
|
|
getState: sinon.stub().callsFake((cb) => cb(null, baseMockState)),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
await store.dispatch(
|
|
|
|
actions.ignoreTokens({ tokensToIgnore: '0x0000001' }),
|
|
|
|
);
|
|
|
|
expect(ignoreTokensStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
it('should display warning when ignoreTokens in background fails', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
2022-07-18 16:43:30 +02:00
|
|
|
ignoreTokens: sinon.stub().callsFake((_, cb) => cb(new Error('error'))),
|
2021-09-10 19:37:19 +02:00
|
|
|
getState: sinon.stub().callsFake((cb) => cb(null, baseMockState)),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-09-10 19:37:19 +02:00
|
|
|
{
|
|
|
|
type: 'UPDATE_METAMASK_STATE',
|
|
|
|
value: baseMockState,
|
|
|
|
},
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-07-18 16:43:30 +02:00
|
|
|
await store.dispatch(
|
|
|
|
actions.ignoreTokens({ tokensToIgnore: '0x0000001' }),
|
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setProviderType', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setProviderType', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const setProviderTypeStub = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setProviderType: setProviderTypeStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setProviderType());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setProviderTypeStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('displays warning when setProviderType throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setProviderType: sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb(new Error('error'))),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{
|
|
|
|
type: 'DISPLAY_WARNING',
|
|
|
|
payload: 'Had a problem changing networks!',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setProviderType());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
describe('#setActiveNetwork', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
it('calls setActiveNetwork in the background with the correct arguments', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
const setCurrentNetworkStub = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
background.getApi.returns({
|
|
|
|
setActiveNetwork: setCurrentNetworkStub,
|
|
|
|
});
|
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
await store.dispatch(actions.setActiveNetwork('networkConfigurationId'));
|
|
|
|
expect(
|
|
|
|
setCurrentNetworkStub.calledOnceWith('networkConfigurationId'),
|
|
|
|
).toBe(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
it('displays warning when setActiveNetwork throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
const setCurrentNetworkStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
background.getApi.returns({
|
|
|
|
setActiveNetwork: setCurrentNetworkStub,
|
|
|
|
});
|
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{
|
|
|
|
type: 'DISPLAY_WARNING',
|
|
|
|
payload: 'Had a problem changing networks!',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
await store.dispatch(actions.setActiveNetwork());
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#editAndSetNetworkConfiguration', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes then re-adds the given network configuration', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const removeNetworkConfigurationStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
const upsertNetworkConfigurationStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
removeNetworkConfiguration: removeNetworkConfigurationStub,
|
|
|
|
upsertNetworkConfiguration: upsertNetworkConfigurationStub,
|
|
|
|
});
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
const networkConfiguration = {
|
|
|
|
rpcUrl: 'newRpc',
|
|
|
|
chainId: '0x',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'nickname',
|
|
|
|
rpcPrefs: { blockExplorerUrl: 'etherscan.io' },
|
|
|
|
};
|
|
|
|
|
|
|
|
await store.dispatch(
|
|
|
|
actions.editAndSetNetworkConfiguration(
|
|
|
|
{
|
|
|
|
...networkConfiguration,
|
|
|
|
networkConfigurationId: 'networkConfigurationId',
|
|
|
|
},
|
|
|
|
{ source: 'https://test-dapp.com' },
|
|
|
|
),
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
removeNetworkConfigurationStub.calledOnceWith('networkConfigurationId'),
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
upsertNetworkConfigurationStub.calledOnceWith(networkConfiguration, {
|
|
|
|
setActive: true,
|
|
|
|
referrer: ORIGIN_METAMASK,
|
|
|
|
source: 'https://test-dapp.com',
|
|
|
|
}),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays warning when removeNetworkConfiguration throws', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const upsertNetworkConfigurationStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
const removeNetworkConfigurationStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
removeNetworkConfiguration: removeNetworkConfigurationStub,
|
|
|
|
upsertNetworkConfiguration: upsertNetworkConfigurationStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
const expectedActions = [
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'Had a problem removing network!' },
|
|
|
|
];
|
|
|
|
|
|
|
|
await store.dispatch(
|
|
|
|
actions.editAndSetNetworkConfiguration(
|
|
|
|
{
|
|
|
|
networkConfigurationId: 'networkConfigurationId',
|
|
|
|
rpcUrl: 'newRpc',
|
|
|
|
chainId: '0x',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'nickname',
|
|
|
|
rpcPrefs: { blockExplorerUrl: 'etherscan.io' },
|
|
|
|
},
|
|
|
|
{ source: 'https://test-dapp.com' },
|
|
|
|
),
|
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2023-03-09 22:00:28 +01:00
|
|
|
|
|
|
|
it('throws when no options object is passed as a second argument', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
await expect(() =>
|
|
|
|
store.dispatch(
|
|
|
|
actions.editAndSetNetworkConfiguration({
|
|
|
|
networkConfigurationId: 'networkConfigurationId',
|
|
|
|
rpcUrl: 'newRpc',
|
|
|
|
chainId: '0x',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'nickname',
|
|
|
|
rpcPrefs: { blockExplorerUrl: 'etherscan.io' },
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
).toThrow(
|
|
|
|
"Cannot destructure property 'source' of 'undefined' as it is undefined.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#upsertNetworkConfiguration', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls upsertNetworkConfiguration in the background with the correct arguments', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const upsertNetworkConfigurationStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
upsertNetworkConfiguration: upsertNetworkConfigurationStub,
|
|
|
|
});
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
const networkConfiguration = {
|
|
|
|
rpcUrl: 'newRpc',
|
|
|
|
chainId: '0x',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'nickname',
|
|
|
|
rpcPrefs: { blockExplorerUrl: 'etherscan.io' },
|
|
|
|
};
|
|
|
|
|
|
|
|
await store.dispatch(
|
|
|
|
actions.upsertNetworkConfiguration(networkConfiguration, {
|
2023-04-03 17:31:04 +02:00
|
|
|
source: MetaMetricsNetworkEventSource.CustomNetworkForm,
|
2023-03-09 22:00:28 +01:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
upsertNetworkConfigurationStub.calledOnceWith(networkConfiguration, {
|
|
|
|
referrer: ORIGIN_METAMASK,
|
2023-04-03 17:31:04 +02:00
|
|
|
source: MetaMetricsNetworkEventSource.CustomNetworkForm,
|
2023-03-09 22:00:28 +01:00
|
|
|
setActive: undefined,
|
|
|
|
}),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws when no options object is passed as a second argument', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
await expect(() =>
|
|
|
|
store.dispatch(
|
|
|
|
actions.upsertNetworkConfiguration({
|
|
|
|
networkConfigurationId: 'networkConfigurationId',
|
|
|
|
rpcUrl: 'newRpc',
|
|
|
|
chainId: '0x',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'nickname',
|
|
|
|
rpcPrefs: { blockExplorerUrl: 'etherscan.io' },
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
).toThrow(
|
|
|
|
"Cannot destructure property 'setActive' of 'undefined' as it is undefined.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#requestUserApproval', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls requestUserApproval in the background with the correct arguments', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const requestUserApprovalStub = sinon.stub().callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
requestUserApproval: requestUserApprovalStub,
|
|
|
|
});
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
const networkConfiguration = {
|
|
|
|
rpcUrl: 'newRpc',
|
|
|
|
chainId: '0x',
|
|
|
|
ticker: 'ETH',
|
|
|
|
nickname: 'nickname',
|
|
|
|
rpcPrefs: { blockExplorerUrl: 'etherscan.io' },
|
|
|
|
};
|
|
|
|
|
|
|
|
await store.dispatch(
|
|
|
|
actions.requestUserApproval({
|
|
|
|
origin: ORIGIN_METAMASK,
|
|
|
|
type: 'test',
|
|
|
|
requestData: networkConfiguration,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
requestUserApprovalStub.calledOnceWith({
|
|
|
|
origin: ORIGIN_METAMASK,
|
|
|
|
type: 'test',
|
|
|
|
requestData: networkConfiguration,
|
|
|
|
}),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#removeNetworkConfiguration', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls removeNetworkConfiguration in the background with the correct arguments', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const removeNetworkConfigurationStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
removeNetworkConfiguration: removeNetworkConfigurationStub,
|
|
|
|
});
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
await store.dispatch(
|
|
|
|
actions.removeNetworkConfiguration('testNetworkConfigurationId'),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
removeNetworkConfigurationStub.calledOnceWith(
|
|
|
|
'testNetworkConfigurationId',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#setSelectedNetworkConfigurationId', () => {
|
|
|
|
it('sets appState.networkConfigurationId to provided value', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const networkConfigurationId = 'testNetworkConfigurationId';
|
|
|
|
|
|
|
|
store.dispatch(
|
|
|
|
actions.setSelectedNetworkConfigurationId(networkConfigurationId),
|
|
|
|
);
|
|
|
|
|
|
|
|
const resultantActions = store.getActions();
|
|
|
|
|
|
|
|
expect(resultantActions[0]).toStrictEqual({
|
|
|
|
type: 'SET_SELECTED_NETWORK_CONFIGURATION_ID',
|
|
|
|
payload: networkConfigurationId,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#setNewNetworkAdded', () => {
|
|
|
|
it('sets appState.setNewNetworkAdded to provided value', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const newNetworkAddedDetails = {
|
|
|
|
networkConfigurationId: 'testNetworkConfigurationId',
|
|
|
|
nickname: 'test-chain',
|
|
|
|
};
|
|
|
|
|
|
|
|
store.dispatch(actions.setNewNetworkAdded(newNetworkAddedDetails));
|
|
|
|
|
|
|
|
const resultantActions = store.getActions();
|
|
|
|
|
|
|
|
expect(resultantActions[0]).toStrictEqual({
|
|
|
|
type: 'SET_NEW_NETWORK_ADDED',
|
|
|
|
payload: newNetworkAddedDetails,
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#addToAddressBook', () => {
|
|
|
|
it('calls setAddressBook', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const setAddressBookStub = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, __, ___, ____, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setAddressBook: setAddressBookStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-16 17:05:13 +02:00
|
|
|
await store.dispatch(actions.addToAddressBook('0x0000'));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setAddressBookStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#exportAccount', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns expected actions for successful action', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const testPrivKey = 'a-test-priv-key';
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const verifyPasswordStub = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const exportAccountStub = sinon
|
|
|
|
.stub()
|
2023-01-17 16:01:12 +01:00
|
|
|
.callsFake((_, _2, cb) => cb(null, testPrivKey));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
verifyPassword: verifyPasswordStub,
|
|
|
|
exportAccount: exportAccountStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'SHOW_PRIVATE_KEY',
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: testPrivKey,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
2021-02-02 09:55:12 +01:00
|
|
|
actions.exportAccount('a-test-password', '0xAddress'),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(verifyPasswordStub.callCount).toStrictEqual(1);
|
|
|
|
expect(exportAccountStub.callCount).toStrictEqual(1);
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns action errors when first func callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const verifyPasswordStub = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
verifyPassword: verifyPasswordStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'Incorrect Password.' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.exportAccount('a-test-password', '0xAddress')),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns action errors when second func callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const verifyPasswordStub = sinon.stub().callsFake((_, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const exportAccountStub = sinon
|
|
|
|
.stub()
|
2023-01-17 16:01:12 +01:00
|
|
|
.callsFake((_, _2, cb) => cb(new Error('error')));
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
verifyPassword: verifyPasswordStub,
|
|
|
|
exportAccount: exportAccountStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'DISPLAY_WARNING',
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: 'Had a problem exporting the account.',
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.exportAccount('a-test-password', '0xAddress')),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setAccountLabel', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setAccountLabel', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const setAccountLabelStub = sinon.stub().callsFake((_, __, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setAccountLabel: setAccountLabelStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
await store.dispatch(
|
|
|
|
actions.setAccountLabel(
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
'test',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setAccountLabelStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns action errors when func callback errors', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setAccountLabel: sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, __, cb) => cb(new Error('error'))),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(
|
2021-02-02 09:55:12 +01:00
|
|
|
actions.setAccountLabel(
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
'test',
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setFeatureFlag', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setFeatureFlag in the background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const setFeatureFlagStub = sinon.stub().callsFake((_, __, cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setFeatureFlag: setFeatureFlagStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setFeatureFlag());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setFeatureFlagStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when setFeatureFlag in background throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setFeatureFlag: sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, __, cb) => cb(new Error('error'))),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(store.dispatch(actions.setFeatureFlag())).rejects.toThrow(
|
|
|
|
'error',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setCompletedOnboarding', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('completes onboarding', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
|
|
|
const completeOnboardingStub = sinon.stub().callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
completeOnboarding: completeOnboardingStub,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setCompletedOnboarding());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(completeOnboardingStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-03-21 02:26:48 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when setCompletedOnboarding in background throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-02 09:55:12 +01:00
|
|
|
background.getApi.returns({
|
|
|
|
completeOnboarding: sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((cb) => cb(new Error('error'))),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.setCompletedOnboarding()),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2023-07-26 14:13:28 +02:00
|
|
|
describe('#setParticipateInMetaMetrics', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
window.sentry = {
|
|
|
|
toggleSession: jest.fn(),
|
|
|
|
endSession: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
it('sets participateInMetaMetrics to true', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setParticipateInMetaMetricsStub = jest.fn((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setParticipateInMetaMetrics: setParticipateInMetaMetricsStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
await store.dispatch(actions.setParticipateInMetaMetrics(true));
|
|
|
|
expect(setParticipateInMetaMetricsStub).toHaveBeenCalledWith(
|
|
|
|
true,
|
|
|
|
expect.anything(),
|
|
|
|
);
|
|
|
|
expect(window.sentry.toggleSession).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setUseBlockie', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls setUseBlockie in background', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-12-08 22:36:53 +01:00
|
|
|
const setUseBlockieStub = sinon.stub().callsFake((_, cb) => cb());
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection({ setUseBlockie: setUseBlockieStub });
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setUseBlockie());
|
2021-12-08 22:36:53 +01:00
|
|
|
expect(setUseBlockieStub.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when setUseBlockie in background throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-12-08 22:36:53 +01:00
|
|
|
const setUseBlockieStub = sinon.stub().callsFake((_, cb) => {
|
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection({ setUseBlockie: setUseBlockieStub });
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setUseBlockie());
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2022-12-01 22:16:04 +01:00
|
|
|
describe('#setUsePhishDetect', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls setUsePhishDetect in background', () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setUsePhishDetectStub = sinon.stub().callsFake((_, cb) => cb());
|
|
|
|
_setBackgroundConnection({
|
|
|
|
setUsePhishDetect: setUsePhishDetectStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
store.dispatch(actions.setUsePhishDetect());
|
|
|
|
expect(setUsePhishDetectStub.callCount).toStrictEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('errors when setUsePhishDetect in background throws', () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setUsePhishDetectStub = sinon.stub().callsFake((_, cb) => {
|
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
|
|
|
|
|
|
|
_setBackgroundConnection({
|
|
|
|
setUsePhishDetect: setUsePhishDetectStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2022-12-01 22:16:04 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2022-12-01 22:16:04 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
store.dispatch(actions.setUsePhishDetect());
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#setUseMultiAccountBalanceChecker', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls setUseMultiAccountBalanceChecker in background', () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setUseMultiAccountBalanceCheckerStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb());
|
|
|
|
_setBackgroundConnection({
|
|
|
|
setUseMultiAccountBalanceChecker: setUseMultiAccountBalanceCheckerStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
store.dispatch(actions.setUseMultiAccountBalanceChecker());
|
|
|
|
expect(setUseMultiAccountBalanceCheckerStub.callCount).toStrictEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('errors when setUseMultiAccountBalanceChecker in background throws', () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setUseMultiAccountBalanceCheckerStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => {
|
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
|
|
|
|
|
|
|
_setBackgroundConnection({
|
|
|
|
setUseMultiAccountBalanceChecker: setUseMultiAccountBalanceCheckerStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2022-12-01 22:16:04 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2022-12-01 22:16:04 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
store.dispatch(actions.setUseMultiAccountBalanceChecker());
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-04 19:28:37 +02:00
|
|
|
describe('#setUse4ByteResolution', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls setUse4ByteResolution in background', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setUse4ByteResolutionStub = sinon.stub().callsFake((_, cb) => cb());
|
|
|
|
_setBackgroundConnection({
|
|
|
|
setUse4ByteResolution: setUse4ByteResolutionStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
await store.dispatch(actions.setUse4ByteResolution());
|
|
|
|
expect(setUse4ByteResolutionStub.callCount).toStrictEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('errors when setUse4ByteResolution in background throws', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setUse4ByteResolutionStub = sinon.stub().callsFake((_, cb) => {
|
|
|
|
cb(new Error('error'));
|
|
|
|
});
|
|
|
|
|
|
|
|
_setBackgroundConnection({
|
|
|
|
setUse4ByteResolution: setUse4ByteResolutionStub,
|
|
|
|
});
|
|
|
|
|
|
|
|
const expectedActions = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
];
|
|
|
|
|
|
|
|
await store.dispatch(actions.setUse4ByteResolution());
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#updateCurrentLocale', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
sinon.stub(window, 'fetch').resolves({
|
|
|
|
json: async () => enLocale,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls expected actions', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-12-08 22:36:53 +01:00
|
|
|
const setCurrentLocaleStub = sinon.stub().callsFake((_, cb) => cb());
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection({
|
2021-12-08 22:36:53 +01:00
|
|
|
setCurrentLocale: setCurrentLocaleStub,
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'SET_CURRENT_LOCALE',
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: { locale: 'test', messages: enLocale },
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.updateCurrentLocale('test'));
|
2021-12-08 22:36:53 +01:00
|
|
|
expect(setCurrentLocaleStub.callCount).toStrictEqual(1);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when setCurrentLocale throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-12-08 22:36:53 +01:00
|
|
|
const setCurrentLocaleStub = sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((_, cb) => cb(new Error('error')));
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection({
|
2021-12-08 22:36:53 +01:00
|
|
|
setCurrentLocale: setCurrentLocaleStub,
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2018-10-10 16:32:26 +02:00
|
|
|
const expectedActions = [
|
2023-02-03 18:56:44 +01:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', payload: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', payload: 'error' },
|
2020-12-18 06:34:43 +01:00
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await store.dispatch(actions.updateCurrentLocale('test'));
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#markPasswordForgotten', () => {
|
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls markPasswordForgotten', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.markPasswordForgotten.callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.markPasswordForgotten());
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(background.markPasswordForgotten.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when markPasswordForgotten throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.markPasswordForgotten.callsFake((cb) =>
|
|
|
|
cb(new Error('error')),
|
|
|
|
);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
const expectedActions = [
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{
|
|
|
|
type: 'UPDATE_METAMASK_STATE',
|
2021-06-23 23:35:25 +02:00
|
|
|
value: baseMockState,
|
2021-02-02 09:55:12 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
await expect(
|
|
|
|
store.dispatch(actions.markPasswordForgotten('test')),
|
|
|
|
).rejects.toThrow('error');
|
|
|
|
|
|
|
|
expect(store.getActions()).toStrictEqual(expectedActions);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#unMarkPasswordForgotten', () => {
|
|
|
|
it('calls unMarkPasswordForgotten', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
background.unMarkPasswordForgotten.callsFake((cb) => cb());
|
2021-02-02 09:55:12 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background);
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
store.dispatch(actions.unMarkPasswordForgotten());
|
2018-10-10 16:32:26 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(background.unMarkPasswordForgotten.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-03-16 22:00:08 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#displayWarning', () => {
|
|
|
|
it('sets appState.warning to provided value', async () => {
|
2021-03-16 22:00:08 +01:00
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const warningText = 'This is a sample warning message';
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
store.dispatch(actions.displayWarning(warningText));
|
2021-03-16 22:00:08 +01:00
|
|
|
|
|
|
|
const resultantActions = store.getActions();
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(resultantActions[0]).toStrictEqual({
|
2021-03-16 22:00:08 +01:00
|
|
|
type: 'DISPLAY_WARNING',
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: warningText,
|
2021-03-16 22:00:08 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#cancelTx', () => {
|
|
|
|
it('creates COMPLETED_TX with the cancelled transaction ID', async () => {
|
2021-03-16 22:00:08 +01:00
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
background.getApi.returns({
|
2023-06-13 11:17:32 +02:00
|
|
|
rejectPendingApproval: sinon.stub().callsFake((_1, _2, cb) => {
|
2021-03-16 22:00:08 +01:00
|
|
|
cb();
|
|
|
|
}),
|
|
|
|
getState: sinon.stub().callsFake((cb) =>
|
|
|
|
cb(null, {
|
|
|
|
currentLocale: 'test',
|
|
|
|
selectedAddress: '0xFirstAddress',
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2021-06-23 23:35:25 +02:00
|
|
|
chainId: '0x1',
|
|
|
|
},
|
|
|
|
accounts: {
|
|
|
|
'0xFirstAddress': {
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cachedBalances: {
|
|
|
|
'0x1': {
|
|
|
|
'0xFirstAddress': '0x0',
|
|
|
|
},
|
|
|
|
},
|
2021-03-16 22:00:08 +01:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2021-03-16 22:00:08 +01:00
|
|
|
|
|
|
|
const txId = 1457634084250832;
|
|
|
|
|
|
|
|
await store.dispatch(actions.cancelTx({ id: txId }));
|
|
|
|
const resultantActions = store.getActions();
|
|
|
|
const expectedAction = resultantActions.find(
|
|
|
|
(action) => action.type === 'COMPLETED_TX',
|
|
|
|
);
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(expectedAction.value.id).toStrictEqual(txId);
|
2021-03-16 22:00:08 +01:00
|
|
|
});
|
|
|
|
});
|
2022-05-16 20:36:19 +02:00
|
|
|
|
2023-02-23 17:39:48 +01:00
|
|
|
describe('Desktop', () => {
|
|
|
|
describe('#setDesktopEnabled', () => {
|
|
|
|
it('calls background setDesktopEnabled method', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
const setDesktopEnabled = sinon.stub().callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
setDesktopEnabled,
|
|
|
|
getState: sinon.stub().callsFake((cb) =>
|
|
|
|
cb(null, {
|
|
|
|
desktopEnabled: true,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
_setBackgroundConnection(background.getApi());
|
|
|
|
|
|
|
|
await store.dispatch(actions.setDesktopEnabled(true));
|
|
|
|
|
|
|
|
expect(setDesktopEnabled.calledOnceWith(true)).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|