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.
430 lines
11 KiB
430 lines
11 KiB
4 years ago
|
import sinon from 'sinon';
|
||
5 years ago
|
import {
|
||
7 years ago
|
getGasLimit,
|
||
|
getGasPrice,
|
||
|
getGasTotal,
|
||
|
getPrimaryCurrency,
|
||
5 years ago
|
getSendToken,
|
||
|
getSendTokenContract,
|
||
7 years ago
|
getSendAmount,
|
||
5 years ago
|
sendAmountIsInError,
|
||
7 years ago
|
getSendEditingTransactionId,
|
||
|
getSendErrors,
|
||
|
getSendFrom,
|
||
|
getSendFromBalance,
|
||
|
getSendFromObject,
|
||
|
getSendMaxModeState,
|
||
|
getSendTo,
|
||
|
getTokenBalance,
|
||
5 years ago
|
gasFeeIsInError,
|
||
|
getGasLoadingError,
|
||
|
getGasButtonGroupShown,
|
||
|
getTitleKey,
|
||
|
isSendFormInError,
|
||
4 years ago
|
} from './send';
|
||
4 years ago
|
import mockState from './send-selectors-test-data';
|
||
4 years ago
|
import {
|
||
|
accountsWithSendEtherInfoSelector,
|
||
|
getCurrentAccountWithSendEtherInfo,
|
||
|
} from '.';
|
||
7 years ago
|
|
||
4 years ago
|
describe('send selectors', () => {
|
||
4 years ago
|
const tempGlobalEth = { ...global.eth };
|
||
4 years ago
|
beforeEach(() => {
|
||
7 years ago
|
global.eth = {
|
||
|
contract: sinon.stub().returns({
|
||
4 years ago
|
at: (address) => `mockAt:${address}`,
|
||
7 years ago
|
}),
|
||
4 years ago
|
};
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
global.eth = tempGlobalEth;
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('accountsWithSendEtherInfoSelector()', () => {
|
||
|
it('should return an array of account objects with name info from identities', () => {
|
||
|
expect(accountsWithSendEtherInfoSelector(mockState)).toStrictEqual([
|
||
4 years ago
|
{
|
||
|
code: '0x',
|
||
|
balance: '0x47c9d71831c76efe',
|
||
|
nonce: '0x1b',
|
||
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
||
|
name: 'Send Account 1',
|
||
|
},
|
||
|
{
|
||
|
code: '0x',
|
||
|
balance: '0x37452b1315889f80',
|
||
|
nonce: '0xa',
|
||
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
|
name: 'Send Account 2',
|
||
|
},
|
||
|
{
|
||
|
code: '0x',
|
||
|
balance: '0x30c9d71831c76efe',
|
||
|
nonce: '0x1c',
|
||
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
||
|
name: 'Send Account 3',
|
||
|
},
|
||
|
{
|
||
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
|
name: 'Send Account 4',
|
||
|
},
|
||
4 years ago
|
]);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getCurrentAccountWithSendEtherInfo()', () => {
|
||
|
it('should return the currently selected account with identity info', () => {
|
||
|
expect(getCurrentAccountWithSendEtherInfo(mockState)).toStrictEqual({
|
||
4 years ago
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
|
name: 'Send Account 4',
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getGasLimit()', () => {
|
||
|
it('should return the send.gasLimit', () => {
|
||
|
expect(getGasLimit(mockState)).toStrictEqual('0xFFFF');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getGasPrice()', () => {
|
||
|
it('should return the send.gasPrice', () => {
|
||
|
expect(getGasPrice(mockState)).toStrictEqual('0xaa');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getGasTotal()', () => {
|
||
|
it('should return the send.gasTotal', () => {
|
||
|
expect(getGasTotal(mockState)).toStrictEqual('a9ff56');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getPrimaryCurrency()', () => {
|
||
|
it('should return the symbol of the send token', () => {
|
||
|
expect(
|
||
4 years ago
|
getPrimaryCurrency({
|
||
|
metamask: { send: { token: { symbol: 'DEF' } } },
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual('DEF');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendToken()', () => {
|
||
|
it('should return the current send token if set', () => {
|
||
|
expect(
|
||
5 years ago
|
getSendToken({
|
||
|
metamask: {
|
||
|
send: {
|
||
|
token: {
|
||
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
||
|
decimals: 4,
|
||
|
symbol: 'DEF',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual({
|
||
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
||
|
decimals: 4,
|
||
|
symbol: 'DEF',
|
||
|
});
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendTokenContract()', () => {
|
||
|
it('should return the contract at the send token address', () => {
|
||
|
expect(
|
||
5 years ago
|
getSendTokenContract({
|
||
|
metamask: {
|
||
|
send: {
|
||
|
token: {
|
||
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
||
|
decimals: 4,
|
||
|
symbol: 'DEF',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual('mockAt:0x8d6b81208414189a58339873ab429b6c47ab92d3');
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should return null if send token is not set', () => {
|
||
4 years ago
|
const modifiedMetamaskState = { ...mockState.metamask, send: {} };
|
||
4 years ago
|
expect(
|
||
4 years ago
|
getSendTokenContract({ ...mockState, metamask: modifiedMetamaskState }),
|
||
4 years ago
|
).toBeNull();
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendAmount()', () => {
|
||
|
it('should return the send.amount', () => {
|
||
|
expect(getSendAmount(mockState)).toStrictEqual('0x080');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendEditingTransactionId()', () => {
|
||
|
it('should return the send.editingTransactionId', () => {
|
||
|
expect(getSendEditingTransactionId(mockState)).toStrictEqual(97531);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendErrors()', () => {
|
||
|
it('should return the send.errors', () => {
|
||
|
expect(getSendErrors(mockState)).toStrictEqual({ someError: null });
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('getSendFrom()', () => {
|
||
|
it('should return the send.from', () => {
|
||
|
expect(getSendFrom(mockState)).toStrictEqual(
|
||
5 years ago
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendFromBalance()', () => {
|
||
|
it('should get the send.from balance if it exists', () => {
|
||
|
expect(getSendFromBalance(mockState)).toStrictEqual('0x37452b1315889f80');
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should get the selected account balance if the send.from does not exist', () => {
|
||
7 years ago
|
const editedMockState = {
|
||
4 years ago
|
metamask: {
|
||
|
...mockState.metamask,
|
||
7 years ago
|
send: {
|
||
|
from: null,
|
||
|
},
|
||
4 years ago
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
expect(getSendFromBalance(editedMockState)).toStrictEqual('0x0');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendFromObject()', () => {
|
||
|
it('should return send.from if it exists', () => {
|
||
|
expect(getSendFromObject(mockState)).toStrictEqual({
|
||
4 years ago
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
|
balance: '0x37452b1315889f80',
|
||
|
code: '0x',
|
||
|
nonce: '0xa',
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should return the current account if send.from does not exist', () => {
|
||
7 years ago
|
const editedMockState = {
|
||
4 years ago
|
metamask: {
|
||
|
...mockState.metamask,
|
||
7 years ago
|
send: {
|
||
|
from: null,
|
||
|
},
|
||
4 years ago
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
expect(getSendFromObject(editedMockState)).toStrictEqual({
|
||
4 years ago
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendMaxModeState()', () => {
|
||
|
it('should return send.maxModeOn', () => {
|
||
|
expect(getSendMaxModeState(mockState)).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getSendTo()', () => {
|
||
|
it('should return send.to', () => {
|
||
|
expect(getSendTo(mockState)).toStrictEqual('0x987fedabc');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('getTokenBalance()', () => {
|
||
|
it('should', () => {
|
||
|
expect(getTokenBalance(mockState)).toStrictEqual(3434);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('send-amount-row selectors', () => {
|
||
|
describe('sendAmountIsInError()', () => {
|
||
|
it('should return true if send.errors.amount is truthy', () => {
|
||
5 years ago
|
const state = {
|
||
|
send: {
|
||
|
errors: {
|
||
|
amount: 'abc',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
expect(sendAmountIsInError(state)).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return false if send.errors.amount is falsy', () => {
|
||
5 years ago
|
const state = {
|
||
|
send: {
|
||
|
errors: {
|
||
|
amount: null,
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
expect(sendAmountIsInError(state)).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('send-gas-row selectors', () => {
|
||
|
describe('getGasLoadingError()', () => {
|
||
|
it('should return send.errors.gasLoading', () => {
|
||
5 years ago
|
const state = {
|
||
|
send: {
|
||
|
errors: {
|
||
|
gasLoading: 'abc',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
expect(getGasLoadingError(state)).toStrictEqual('abc');
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('gasFeeIsInError()', () => {
|
||
|
it('should return true if send.errors.gasFee is truthy', () => {
|
||
5 years ago
|
const state = {
|
||
|
send: {
|
||
|
errors: {
|
||
|
gasFee: 'def',
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
expect(gasFeeIsInError(state)).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return false send.errors.gasFee is falsely', () => {
|
||
5 years ago
|
const state = {
|
||
|
send: {
|
||
|
errors: {
|
||
|
gasFee: null,
|
||
|
},
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
expect(gasFeeIsInError(state)).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('getGasButtonGroupShown()', () => {
|
||
|
it('should return send.gasButtonGroupShown', () => {
|
||
5 years ago
|
const state = {
|
||
|
send: {
|
||
|
gasButtonGroupShown: 'foobar',
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
expect(getGasButtonGroupShown(state)).toStrictEqual('foobar');
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('send-header selectors', () => {
|
||
5 years ago
|
const getMetamaskSendMockState = (send) => {
|
||
|
return {
|
||
|
metamask: {
|
||
|
send: { ...send },
|
||
|
},
|
||
4 years ago
|
};
|
||
|
};
|
||
5 years ago
|
|
||
4 years ago
|
describe('getTitleKey()', () => {
|
||
|
it('should return the correct key when "to" is empty', () => {
|
||
|
expect(getTitleKey(getMetamaskSendMockState({}))).toStrictEqual(
|
||
4 years ago
|
'addRecipient',
|
||
4 years ago
|
);
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return the correct key when getSendEditingTransactionId is truthy', () => {
|
||
|
expect(
|
||
5 years ago
|
getTitleKey(
|
||
|
getMetamaskSendMockState({
|
||
|
to: true,
|
||
|
editingTransactionId: true,
|
||
5 years ago
|
token: {},
|
||
4 years ago
|
}),
|
||
4 years ago
|
),
|
||
4 years ago
|
).toStrictEqual('edit');
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is truthy', () => {
|
||
|
expect(
|
||
5 years ago
|
getTitleKey(
|
||
|
getMetamaskSendMockState({
|
||
|
to: true,
|
||
|
editingTransactionId: false,
|
||
5 years ago
|
token: {},
|
||
4 years ago
|
}),
|
||
4 years ago
|
),
|
||
4 years ago
|
).toStrictEqual('sendTokens');
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is falsy', () => {
|
||
|
expect(
|
||
5 years ago
|
getTitleKey(
|
||
|
getMetamaskSendMockState({
|
||
|
to: true,
|
||
|
editingTransactionId: false,
|
||
5 years ago
|
token: null,
|
||
4 years ago
|
}),
|
||
4 years ago
|
),
|
||
4 years ago
|
).toStrictEqual('send');
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('send-footer selectors', () => {
|
||
5 years ago
|
const getSendMockState = (send) => {
|
||
|
return {
|
||
|
send: { ...send },
|
||
4 years ago
|
};
|
||
|
};
|
||
5 years ago
|
|
||
4 years ago
|
describe('isSendFormInError()', () => {
|
||
|
it('should return true if any of the values of the object returned by getSendErrors are truthy', () => {
|
||
|
expect(
|
||
4 years ago
|
isSendFormInError(
|
||
|
getSendMockState({
|
||
|
errors: [true],
|
||
|
}),
|
||
|
),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
it('should return false if all of the values of the object returned by getSendErrors are falsy', () => {
|
||
|
expect(
|
||
4 years ago
|
isSendFormInError(
|
||
|
getSendMockState({
|
||
|
errors: [],
|
||
|
}),
|
||
|
),
|
||
4 years ago
|
).toStrictEqual(false);
|
||
|
expect(
|
||
4 years ago
|
isSendFormInError(
|
||
|
getSendMockState({
|
||
|
errors: [false],
|
||
|
}),
|
||
|
),
|
||
4 years ago
|
).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|