A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/test/unit/ui/app/reducers/app.spec.js

375 lines
9.5 KiB

import assert from 'assert';
import reduceApp from '../../../../../ui/app/ducks/app/app';
import * as actionConstants from '../../../../../ui/app/store/actionConstants';
const actions = actionConstants;
6 years ago
describe('App State', function () {
6 years ago
const metamaskState = {
selectedAddress: '0xAddress',
identities: {
'0xAddress': {
name: 'account 1',
address: '0xAddress',
6 years ago
},
},
};
6 years ago
it('App init state', function () {
const initState = reduceApp(metamaskState, {});
6 years ago
assert(initState);
});
6 years ago
it('sets networkDropdownOpen dropdown to true', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.NETWORK_DROPDOWN_OPEN,
});
6 years ago
assert.equal(state.networkDropdownOpen, true);
});
6 years ago
it('sets networkDropdownOpen dropdown to false', function () {
const dropdown = { networkDropdowopen: true };
const state = { ...metamaskState, ...dropdown };
6 years ago
const newState = reduceApp(state, {
type: actions.NETWORK_DROPDOWN_CLOSE,
});
6 years ago
assert.equal(newState.networkDropdownOpen, false);
});
6 years ago
it('opens sidebar', function () {
6 years ago
const value = {
transitionName: 'sidebar-right',
type: 'wallet-view',
isOpen: true,
};
const state = reduceApp(metamaskState, {
6 years ago
type: actions.SIDEBAR_OPEN,
value,
});
6 years ago
assert.deepEqual(state.sidebar, value);
});
6 years ago
it('closes sidebar', function () {
const openSidebar = { sidebar: { isOpen: true } };
const state = { ...metamaskState, ...openSidebar };
6 years ago
const newState = reduceApp(state, {
type: actions.SIDEBAR_CLOSE,
});
6 years ago
assert.equal(newState.sidebar.isOpen, false);
});
6 years ago
it('opens alert', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.ALERT_OPEN,
value: 'test message',
});
6 years ago
assert.equal(state.alertOpen, true);
assert.equal(state.alertMessage, 'test message');
});
6 years ago
it('closes alert', function () {
const alert = { alertOpen: true, alertMessage: 'test message' };
const state = { ...metamaskState, ...alert };
6 years ago
const newState = reduceApp(state, {
type: actions.ALERT_CLOSE,
});
6 years ago
assert.equal(newState.alertOpen, false);
assert.equal(newState.alertMessage, null);
});
6 years ago
it('detects qr code data', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.QR_CODE_DETECTED,
value: 'qr data',
});
6 years ago
assert.equal(state.qrCodeData, 'qr data');
});
6 years ago
it('opens modal', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.MODAL_OPEN,
payload: {
name: 'test',
},
});
6 years ago
assert.equal(state.modal.open, true);
assert.equal(state.modal.modalState.name, 'test');
});
6 years ago
it('closes modal, but moves open modal state to previous modal state', function () {
const opensModal = {
modal: {
open: true,
modalState: {
name: 'test',
},
},
};
const state = { ...metamaskState, appState: { ...opensModal } };
6 years ago
const newState = reduceApp(state, {
type: actions.MODAL_CLOSE,
});
6 years ago
assert.equal(newState.modal.open, false);
assert.equal(newState.modal.modalState.name, null);
});
6 years ago
it('shows send token page', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_SEND_TOKEN_PAGE,
});
6 years ago
assert.equal(state.warning, null);
});
6 years ago
it('locks Metamask', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.LOCK_METAMASK,
});
6 years ago
assert.equal(state.warning, null);
});
6 years ago
it('goes home', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.GO_HOME,
});
6 years ago
assert.equal(state.accountDetail.subview, 'transactions');
assert.equal(state.accountDetail.accountExport, 'none');
assert.equal(state.accountDetail.privateKey, '');
assert.equal(state.warning, null);
});
6 years ago
it('shows account detail', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_ACCOUNT_DETAIL,
value: 'context address',
});
assert.equal(state.forgottenPassword, null); // default
assert.equal(state.accountDetail.subview, 'transactions'); // default
assert.equal(state.accountDetail.accountExport, 'none'); // default
assert.equal(state.accountDetail.privateKey, ''); // default
});
6 years ago
it('clears account details', function () {
const exportPrivKeyModal = {
accountDetail: {
subview: 'export',
accountExport: 'completed',
privateKey: 'a-priv-key',
},
};
const state = { ...metamaskState, appState: { ...exportPrivKeyModal } };
const newState = reduceApp(state, {
type: actions.CLEAR_ACCOUNT_DETAILS,
});
assert.deepStrictEqual(newState.accountDetail, {});
});
it('shoes account page', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_ACCOUNTS_PAGE,
});
6 years ago
assert.equal(state.isLoading, false);
assert.equal(state.warning, null);
assert.equal(state.scrollToBottom, false);
assert.equal(state.forgottenPassword, false);
});
6 years ago
it('shows confirm tx page', function () {
6 years ago
const txs = {
unapprovedTxs: {
1: {
id: 1,
},
2: {
id: 2,
},
},
};
const oldState = { ...metamaskState, ...txs };
6 years ago
const state = reduceApp(oldState, {
type: actions.SHOW_CONF_TX_PAGE,
id: 2,
});
6 years ago
assert.equal(state.txId, 2);
assert.equal(state.warning, null);
assert.equal(state.isLoading, false);
});
6 years ago
it('completes tx continues to show pending txs current view context', function () {
6 years ago
const txs = {
unapprovedTxs: {
1: {
id: 1,
},
2: {
id: 2,
},
},
};
6 years ago
const oldState = { ...metamaskState, ...txs };
6 years ago
const state = reduceApp(oldState, {
type: actions.COMPLETED_TX,
value: {
id: 1,
},
});
6 years ago
assert.equal(state.txId, null);
assert.equal(state.warning, null);
});
6 years ago
it('returns to account detail page when no unconf actions completed tx', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.COMPLETED_TX,
value: {
unconfirmedActionsCount: 0,
},
});
6 years ago
assert.equal(state.warning, null);
assert.equal(state.accountDetail.subview, 'transactions');
});
6 years ago
it('sets default warning when unlock fails', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.UNLOCK_FAILED,
});
6 years ago
assert.equal(state.warning, 'Incorrect password. Try again.');
});
6 years ago
it('sets errors when unlock fails', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.UNLOCK_FAILED,
value: 'errors',
});
6 years ago
assert.equal(state.warning, 'errors');
});
6 years ago
it('sets warning to empty string when unlock succeeds', function () {
const errorState = { warning: 'errors' };
const oldState = { ...metamaskState, ...errorState };
6 years ago
const state = reduceApp(oldState, {
type: actions.UNLOCK_SUCCEEDED,
});
6 years ago
assert.equal(state.warning, '');
});
6 years ago
it('sets hardware wallet default hd path', function () {
6 years ago
const hdPaths = {
trezor: "m/44'/60'/0'/0",
ledger: "m/44'/60'/0'",
};
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SET_HARDWARE_WALLET_DEFAULT_HD_PATH,
value: {
device: 'ledger',
path: "m/44'/60'/0'",
},
});
6 years ago
assert.deepEqual(state.defaultHdPaths, hdPaths);
});
6 years ago
it('shows loading message', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.SHOW_LOADING,
value: 'loading',
});
6 years ago
assert.equal(state.isLoading, true);
assert.equal(state.loadingMessage, 'loading');
});
6 years ago
it('hides loading message', function () {
const loadingState = { isLoading: true };
const oldState = { ...metamaskState, ...loadingState };
6 years ago
const state = reduceApp(oldState, {
type: actions.HIDE_LOADING,
});
6 years ago
assert.equal(state.isLoading, false);
});
6 years ago
it('displays warning', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.DISPLAY_WARNING,
value: 'warning',
});
6 years ago
assert.equal(state.isLoading, false);
assert.equal(state.warning, 'warning');
});
6 years ago
it('hides warning', function () {
const displayWarningState = { warning: 'warning' };
const oldState = { ...metamaskState, ...displayWarningState };
6 years ago
const state = reduceApp(oldState, {
type: actions.HIDE_WARNING,
});
6 years ago
assert.equal(state.warning, undefined);
});
6 years ago
it('shows private key', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SHOW_PRIVATE_KEY,
value: 'private key',
});
6 years ago
assert.equal(state.accountDetail.subview, 'export');
assert.equal(state.accountDetail.accountExport, 'completed');
assert.equal(state.accountDetail.privateKey, 'private key');
});
6 years ago
it('set mouse user state', function () {
6 years ago
const state = reduceApp(metamaskState, {
type: actions.SET_MOUSE_USER_STATE,
value: true,
});
6 years ago
assert.equal(state.isMouseUser, true);
});
6 years ago
it('sets gas loading', function () {
const state = reduceApp(metamaskState, {
6 years ago
type: actions.GAS_LOADING_STARTED,
});
6 years ago
assert.equal(state.gasIsLoading, true);
});
6 years ago
it('unsets gas loading', function () {
const gasLoadingState = { gasIsLoading: true };
const oldState = { ...metamaskState, ...gasLoadingState };
6 years ago
const state = reduceApp(oldState, {
type: actions.GAS_LOADING_FINISHED,
});
6 years ago
assert.equal(state.gasIsLoading, false);
});
});