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';
|
|
|
|
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
|
2022-02-16 21:54:30 +01:00
|
|
|
import { DEVICE_NAMES } from '../../shared/constants/hardware-wallets';
|
2021-06-08 17:25:48 +02:00
|
|
|
import { GAS_LIMITS } from '../../shared/constants/gas';
|
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',
|
|
|
|
provider: { 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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const currentNetworkId = '42';
|
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
|
|
|
});
|
|
|
|
});
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
2021-02-02 09:55:12 +01:00
|
|
|
{ type: 'FORGOT_PASSWORD', value: false },
|
|
|
|
{
|
|
|
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 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',
|
2021-06-23 23:35:25 +02:00
|
|
|
provider: {
|
|
|
|
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 = [
|
2021-04-15 20:01:46 +02:00
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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(
|
|
|
|
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',
|
|
|
|
value: 'This may take a while, please be patient.',
|
|
|
|
},
|
2018-10-10 16:32:26 +02:00
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
|
|
|
{ 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(
|
2022-02-16 21:54:30 +01:00
|
|
|
actions.checkHardwareStatus(DEVICE_NAMES.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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
|
|
|
|
2022-02-16 21:54:30 +01:00
|
|
|
await store.dispatch(actions.forgetDevice(DEVICE_NAMES.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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(
|
2022-02-16 21:54:30 +01:00
|
|
|
actions.connectHardware(DEVICE_NAMES.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',
|
|
|
|
value: 'Looking for your Ledger...',
|
|
|
|
},
|
2019-09-26 20:52:51 +02:00
|
|
|
{ type: 'DISPLAY_WARNING', value: '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(
|
2022-02-16 21:54:30 +01:00
|
|
|
store.dispatch(actions.connectHardware(DEVICE_NAMES.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],
|
2022-02-16 21:54:30 +01:00
|
|
|
DEVICE_NAMES.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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('#signMsg', () => {
|
2018-10-10 16:32:26 +02:00
|
|
|
const msgParams = {
|
2021-02-02 09:55:12 +01:00
|
|
|
metamaskId: 123,
|
2018-10-10 16:32:26 +02:00
|
|
|
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
2022-07-31 20:26:40 +02:00
|
|
|
data: '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0',
|
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 signMsg 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 signMessage = background.signMessage.callsFake((_, cb) =>
|
2021-06-23 23:35:25 +02:00
|
|
|
cb(null, defaultState.metamask),
|
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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.signMsg(msgParams));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(signMessage.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 signMessage in background 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.signMessage.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 expect(store.dispatch(actions.signMsg(msgParams))).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('#signPersonalMsg', () => {
|
2018-10-10 16:32:26 +02:00
|
|
|
const msgParams = {
|
|
|
|
from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
2022-07-31 20:26:40 +02:00
|
|
|
data: '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0',
|
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 signPersonalMessage', 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 signPersonalMessage = background.signPersonalMessage.callsFake(
|
2021-06-23 23:35:25 +02:00
|
|
|
(_, cb) => cb(null, defaultState.metamask),
|
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.signPersonalMsg(msgParams));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(signPersonalMessage.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 signPersonalMessage throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.signPersonalMessage.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 expect(
|
|
|
|
store.dispatch(actions.signPersonalMsg(msgParams)),
|
|
|
|
).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('#signTypedMsg', () => {
|
2019-09-26 20:52:51 +02:00
|
|
|
const msgParamsV3 = {
|
|
|
|
from: '0x0DCD5D886577d5081B0c52e242Ef29E70Be3E7bc',
|
|
|
|
data: JSON.stringify({
|
2020-11-03 00:41:28 +01:00
|
|
|
types: {
|
|
|
|
EIP712Domain: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'version', type: 'string' },
|
|
|
|
{ name: 'chainId', type: 'uint256' },
|
|
|
|
{ name: 'verifyingContract', type: 'address' },
|
2019-09-26 20:52:51 +02:00
|
|
|
],
|
2020-11-03 00:41:28 +01:00
|
|
|
Person: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'wallet', type: 'address' },
|
2019-09-26 20:52:51 +02:00
|
|
|
],
|
2020-11-03 00:41:28 +01:00
|
|
|
Mail: [
|
|
|
|
{ name: 'from', type: 'Person' },
|
|
|
|
{ name: 'to', type: 'Person' },
|
|
|
|
{ name: 'contents', type: 'string' },
|
2019-09-26 20:52:51 +02:00
|
|
|
],
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
primaryType: 'Mail',
|
|
|
|
domain: {
|
|
|
|
name: 'Ether Mainl',
|
|
|
|
version: '1',
|
|
|
|
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
2019-09-26 20:52:51 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
message: {
|
|
|
|
from: {
|
|
|
|
name: 'Cow',
|
|
|
|
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
2019-09-26 20:52:51 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
to: {
|
|
|
|
name: 'Bob',
|
|
|
|
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
2019-09-26 20:52:51 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
contents: 'Hello, Bob!',
|
2019-09-26 20:52:51 +02:00
|
|
|
},
|
|
|
|
}),
|
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('calls signTypedMsg in background with no 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
|
|
|
const signTypedMsg = background.signTypedMessage.callsFake((_, cb) =>
|
2021-06-23 23:35:25 +02:00
|
|
|
cb(null, defaultState.metamask),
|
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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.signTypedMsg(msgParamsV3));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(signTypedMsg.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('returns expected actions with error', 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.signTypedMessage.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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.signTypedMsg())).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('#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',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{
|
|
|
|
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: 'TRANSACTION_ERROR', message: 'error' },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
|
|
|
{ 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#showAccountDetail', () => {
|
|
|
|
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('#showAccountDetail', 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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.showAccountDetail());
|
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('displays warning if setSelectedAddress 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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.showAccountDetail());
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 = [
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#setRpcTarget', () => {
|
|
|
|
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 setRpcTarget', 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.setCustomRpc.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-02-04 19:15:23 +01:00
|
|
|
await store.dispatch(actions.setRpcTarget('http://localhost:8545'));
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(background.setCustomRpc.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 setRpcTarget throws', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = mockStore();
|
2021-02-02 09:55:12 +01:00
|
|
|
|
|
|
|
background.setCustomRpc.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 = [
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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.setRpcTarget());
|
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('#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()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake((_, 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'SHOW_PRIVATE_KEY',
|
2021-02-02 09:55:12 +01:00
|
|
|
value: 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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()
|
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,
|
|
|
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'DISPLAY_WARNING',
|
|
|
|
value: 'Had a problem exporting the account.',
|
|
|
|
},
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
|
|
|
{ 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
|
|
|
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'HIDE_LOADING_INDICATION' },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: 'error' },
|
|
|
|
{ type: 'SET_USE_BLOCKIE', value: undefined },
|
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
|
|
|
|
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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
type: 'SET_CURRENT_LOCALE',
|
2021-02-02 09:55:12 +01:00
|
|
|
value: { 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 = [
|
|
|
|
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
|
|
|
{ type: 'DISPLAY_WARNING', value: '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-02-04 19:15:23 +01:00
|
|
|
const resultantActions = store.getActions();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(resultantActions[1]).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
type: 'FORGOT_PASSWORD',
|
|
|
|
value: true,
|
2021-02-04 19:15:23 +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: 'FORGOT_PASSWORD', value: true },
|
|
|
|
{
|
|
|
|
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-02-04 19:15:23 +01:00
|
|
|
const resultantActions = store.getActions();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(resultantActions[0]).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
type: 'FORGOT_PASSWORD',
|
|
|
|
value: false,
|
2021-02-04 19:15:23 +01: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',
|
|
|
|
value: warningText,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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({
|
|
|
|
cancelTransaction: sinon.stub().callsFake((_, cb) => {
|
|
|
|
cb();
|
|
|
|
}),
|
|
|
|
getState: sinon.stub().callsFake((cb) =>
|
|
|
|
cb(null, {
|
|
|
|
currentLocale: 'test',
|
|
|
|
selectedAddress: '0xFirstAddress',
|
2021-06-23 23:35:25 +02:00
|
|
|
provider: {
|
|
|
|
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
|
|
|
|
|
|
|
describe('#cancelMsgs', () => {
|
|
|
|
it('creates COMPLETED_TX with the cancelled messages IDs', async () => {
|
|
|
|
const store = mockStore();
|
|
|
|
|
|
|
|
const cancelTypedMessageStub = sinon.stub().callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
const cancelPersonalMessageStub = sinon.stub().callsFake((_, cb) => cb());
|
|
|
|
|
|
|
|
background.getApi.returns({
|
|
|
|
cancelTypedMessage: cancelTypedMessageStub,
|
|
|
|
cancelPersonalMessage: cancelPersonalMessageStub,
|
|
|
|
getState: sinon.stub().callsFake((cb) =>
|
|
|
|
cb(null, {
|
|
|
|
currentLocale: 'test',
|
|
|
|
selectedAddress: '0xFirstAddress',
|
|
|
|
provider: {
|
|
|
|
chainId: '0x1',
|
|
|
|
},
|
|
|
|
accounts: {
|
|
|
|
'0xFirstAddress': {
|
|
|
|
balance: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cachedBalances: {
|
|
|
|
'0x1': {
|
|
|
|
'0xFirstAddress': '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
const msgsList = [
|
|
|
|
{ id: 7648683973086304, status: 'unapproved', type: 'personal_sign' },
|
|
|
|
{
|
|
|
|
id: 7648683973086303,
|
|
|
|
status: 'unapproved',
|
|
|
|
type: 'eth_signTypedData',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
_setBackgroundConnection(background.getApi());
|
2022-05-16 20:36:19 +02:00
|
|
|
|
|
|
|
await store.dispatch(actions.cancelMsgs(msgsList));
|
|
|
|
const resultantActions = store.getActions();
|
|
|
|
const expectedActions = resultantActions.filter(
|
|
|
|
(action) => action.type === 'COMPLETED_TX',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(expectedActions[0].value.id).toStrictEqual(msgsList[0]);
|
|
|
|
expect(expectedActions[1].value.id).toStrictEqual(msgsList[1]);
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|