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.
407 lines
8.7 KiB
407 lines
8.7 KiB
4 years ago
|
import * as actionConstants from '../../store/actionConstants';
|
||
|
import reduceMetamask from './metamask';
|
||
6 years ago
|
|
||
4 years ago
|
describe('MetaMask Reducers', () => {
|
||
|
it('init state', () => {
|
||
4 years ago
|
const initState = reduceMetamask(undefined, {});
|
||
4 years ago
|
expect.anything(initState);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('locks MetaMask', () => {
|
||
6 years ago
|
const unlockMetaMaskState = {
|
||
5 years ago
|
isUnlocked: true,
|
||
|
selectedAddress: 'test address',
|
||
4 years ago
|
};
|
||
6 years ago
|
const lockMetaMask = reduceMetamask(unlockMetaMaskState, {
|
||
5 years ago
|
type: actionConstants.LOCK_METAMASK,
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
expect(lockMetaMask.isUnlocked).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('sets rpc target', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SET_RPC_TARGET,
|
||
|
value: 'https://custom.rpc',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.provider.rpcUrl).toStrictEqual('https://custom.rpc');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('sets provider type', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SET_PROVIDER_TYPE,
|
||
|
value: 'provider type',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.provider.type).toStrictEqual('provider type');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('shows account detail', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SHOW_ACCOUNT_DETAIL,
|
||
|
value: 'test address',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.isUnlocked).toStrictEqual(true);
|
||
|
expect(state.isInitialized).toStrictEqual(true);
|
||
|
expect(state.selectedAddress).toStrictEqual('test address');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('sets account label', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SET_ACCOUNT_LABEL,
|
||
|
value: {
|
||
|
account: 'test account',
|
||
|
label: 'test label',
|
||
|
},
|
||
6 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.identities).toStrictEqual({
|
||
4 years ago
|
'test account': { name: 'test label' },
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates tokens', () => {
|
||
6 years ago
|
const newTokens = {
|
||
4 years ago
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
decimals: 18,
|
||
|
symbol: 'META',
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_TOKENS,
|
||
|
newTokens,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.tokens).toStrictEqual(newTokens);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates send gas limit', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_GAS_LIMIT,
|
||
|
value: '0xGasLimit',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.gasLimit).toStrictEqual('0xGasLimit');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates send gas price', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_GAS_PRICE,
|
||
|
value: '0xGasPrice',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.gasPrice).toStrictEqual('0xGasPrice');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('toggles account menu', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.TOGGLE_ACCOUNT_MENU,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.isAccountMenuOpen).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates gas total', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_GAS_TOTAL,
|
||
|
value: '0xGasTotal',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.gasTotal).toStrictEqual('0xGasTotal');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates send token balance', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND_TOKEN_BALANCE,
|
||
|
value: '0xTokenBalance',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.tokenBalance).toStrictEqual('0xTokenBalance');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates data', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND_HEX_DATA,
|
||
|
value: '0xData',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.data).toStrictEqual('0xData');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates send to', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND_TO,
|
||
|
value: {
|
||
|
to: '0xAddress',
|
||
|
nickname: 'nickname',
|
||
|
},
|
||
6 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.to).toStrictEqual('0xAddress');
|
||
|
expect(state.send.toNickname).toStrictEqual('nickname');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('update send amount', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND_AMOUNT,
|
||
|
value: '0xAmount',
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.amount).toStrictEqual('0xAmount');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates max mode', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_MAX_MODE,
|
||
|
value: true,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send.maxModeOn).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('update send', () => {
|
||
6 years ago
|
const value = {
|
||
|
gasLimit: '0xGasLimit',
|
||
|
gasPrice: '0xGasPrice',
|
||
|
gasTotal: '0xGasTotal',
|
||
|
tokenBalance: '0xBalance',
|
||
|
from: '0xAddress',
|
||
|
to: '0xAddress',
|
||
|
toNickname: '',
|
||
|
maxModeOn: false,
|
||
|
amount: '0xAmount',
|
||
|
memo: '0xMemo',
|
||
|
errors: {},
|
||
|
editingTransactionId: 22,
|
||
5 years ago
|
ensResolution: null,
|
||
|
ensResolutionError: '',
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
const sendState = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND,
|
||
|
value,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(sendState.send).toStrictEqual(value);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('clears send', () => {
|
||
6 years ago
|
const initStateSend = {
|
||
4 years ago
|
send: {
|
||
4 years ago
|
gasLimit: null,
|
||
6 years ago
|
gasPrice: null,
|
||
|
gasTotal: null,
|
||
|
tokenBalance: null,
|
||
|
from: '',
|
||
|
to: '',
|
||
|
amount: '0x0',
|
||
|
memo: '',
|
||
|
errors: {},
|
||
|
maxModeOn: false,
|
||
|
editingTransactionId: null,
|
||
4 years ago
|
toNickname: '',
|
||
|
},
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
const sendState = {
|
||
|
send: {
|
||
|
gasLimit: '0xGasLimit',
|
||
|
gasPrice: '0xGasPrice',
|
||
|
gasTotal: '0xGasTotal',
|
||
|
tokenBalance: '0xBalance',
|
||
|
from: '0xAddress',
|
||
|
to: '0xAddress',
|
||
|
toNickname: '',
|
||
|
maxModeOn: false,
|
||
|
amount: '0xAmount',
|
||
|
memo: '0xMemo',
|
||
|
errors: {},
|
||
|
editingTransactionId: 22,
|
||
|
},
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
6 years ago
|
const state = reduceMetamask(sendState, {
|
||
5 years ago
|
type: actionConstants.CLEAR_SEND,
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.send).toStrictEqual(initStateSend.send);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates value of tx by id', () => {
|
||
6 years ago
|
const oldState = {
|
||
5 years ago
|
currentNetworkTxList: [
|
||
5 years ago
|
{
|
||
|
id: 1,
|
||
|
txParams: 'foo',
|
||
|
},
|
||
|
],
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
const state = reduceMetamask(oldState, {
|
||
5 years ago
|
type: actionConstants.UPDATE_TRANSACTION_PARAMS,
|
||
6 years ago
|
id: 1,
|
||
|
value: 'bar',
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.currentNetworkTxList[0].txParams).toStrictEqual('bar');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('sets blockies', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SET_USE_BLOCKIE,
|
||
|
value: true,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.useBlockie).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('updates an arbitrary feature flag', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_FEATURE_FLAGS,
|
||
|
value: {
|
||
|
foo: true,
|
||
|
},
|
||
6 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.featureFlags.foo).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('close welcome screen', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.CLOSE_WELCOME_SCREEN,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.welcomeScreenSeen).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('sets current locale', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SET_CURRENT_LOCALE,
|
||
|
value: { locale: 'ge' },
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.currentLocale).toStrictEqual('ge');
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('sets pending tokens', () => {
|
||
6 years ago
|
const payload = {
|
||
4 years ago
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
decimals: 18,
|
||
|
symbol: 'META',
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
const pendingTokensState = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.SET_PENDING_TOKENS,
|
||
|
payload,
|
||
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(pendingTokensState.pendingTokens).toStrictEqual(payload);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('clears pending tokens', () => {
|
||
6 years ago
|
const payload = {
|
||
4 years ago
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
||
|
decimals: 18,
|
||
|
symbol: 'META',
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
const pendingTokensState = {
|
||
|
pendingTokens: payload,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
6 years ago
|
const state = reduceMetamask(pendingTokensState, {
|
||
5 years ago
|
type: actionConstants.CLEAR_PENDING_TOKENS,
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
expect(state.pendingTokens).toStrictEqual({});
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('update ensResolution', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND_ENS_RESOLUTION,
|
||
|
payload: '0x1337',
|
||
|
},
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
expect(state.send.ensResolution).toStrictEqual('0x1337');
|
||
|
expect(state.send.ensResolutionError).toStrictEqual('');
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('update ensResolutionError', () => {
|
||
4 years ago
|
const state = reduceMetamask(
|
||
|
{},
|
||
|
{
|
||
|
type: actionConstants.UPDATE_SEND_ENS_RESOLUTION_ERROR,
|
||
|
payload: 'ens name not found',
|
||
|
},
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
expect(state.send.ensResolutionError).toStrictEqual('ens name not found');
|
||
|
expect(state.send.ensResolution).toBeNull();
|
||
4 years ago
|
});
|
||
|
});
|