2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import sinon from 'sinon';
|
2020-01-09 04:34:58 +01:00
|
|
|
import {
|
2018-05-05 17:11:53 +02:00
|
|
|
accountsWithSendEtherInfoSelector,
|
2020-03-06 22:34:56 +01:00
|
|
|
getCurrentAccountWithSendEtherInfo,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '..';
|
|
|
|
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
|
2020-03-06 22:34:56 +01:00
|
|
|
import {
|
2018-05-22 17:16:53 +02:00
|
|
|
getBlockGasLimit,
|
2018-05-05 17:11:53 +02:00
|
|
|
getConversionRate,
|
|
|
|
getCurrentNetwork,
|
2018-10-26 10:26:43 +02:00
|
|
|
getNativeCurrency,
|
2018-05-05 17:11:53 +02:00
|
|
|
getGasLimit,
|
|
|
|
getGasPrice,
|
|
|
|
getGasTotal,
|
|
|
|
getPrimaryCurrency,
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken,
|
|
|
|
getSendTokenContract,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendAmount,
|
2020-05-04 17:22:34 +02:00
|
|
|
sendAmountIsInError,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendEditingTransactionId,
|
|
|
|
getSendErrors,
|
|
|
|
getSendFrom,
|
|
|
|
getSendFromBalance,
|
|
|
|
getSendFromObject,
|
2018-08-16 09:43:13 +02:00
|
|
|
getSendHexDataFeatureFlagState,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendMaxModeState,
|
|
|
|
getSendTo,
|
|
|
|
getSendToAccounts,
|
|
|
|
getTokenBalance,
|
|
|
|
getUnapprovedTxs,
|
2020-05-04 17:22:34 +02:00
|
|
|
gasFeeIsInError,
|
|
|
|
getGasLoadingError,
|
|
|
|
getGasButtonGroupShown,
|
|
|
|
getTitleKey,
|
|
|
|
isSendFormInError,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../send';
|
|
|
|
import mockState from './send-selectors-test-data';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send selectors', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const tempGlobalEth = { ...global.eth };
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2018-05-14 14:13:55 +02:00
|
|
|
global.eth = {
|
|
|
|
contract: sinon.stub().returns({
|
2020-08-19 18:27:05 +02:00
|
|
|
at: (address) => `mockAt:${address}`,
|
2018-05-14 14:57:36 +02:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
});
|
2018-05-14 14:13:55 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
global.eth = tempGlobalEth;
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('accountsWithSendEtherInfoSelector()', function () {
|
|
|
|
it('should return an array of account objects with name info from identities', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(accountsWithSendEtherInfoSelector(mockState), [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
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',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getBlockGasLimit', function () {
|
|
|
|
it('should return the current block gas limit', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepStrictEqual(getBlockGasLimit(mockState), '0x4c1878');
|
|
|
|
});
|
|
|
|
});
|
2018-05-22 17:16:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getConversionRate()', function () {
|
|
|
|
it('should return the eth conversion rate', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepStrictEqual(getConversionRate(mockState), 1200.88200327);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getCurrentAccountWithSendEtherInfo()', function () {
|
|
|
|
it('should return the currently selected account with identity info', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(getCurrentAccountWithSendEtherInfo(mockState), {
|
2020-11-03 00:41:28 +01:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getNativeCurrency()', function () {
|
|
|
|
it('should return the ticker symbol of the selected network', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getNativeCurrency(mockState), 'ETH');
|
|
|
|
});
|
|
|
|
});
|
2018-10-26 10:26:43 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getCurrentNetwork()', function () {
|
|
|
|
it('should return the id of the currently selected network', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getCurrentNetwork(mockState), '3');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getGasLimit()', function () {
|
|
|
|
it('should return the send.gasLimit', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getGasLimit(mockState), '0xFFFF');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getGasPrice()', function () {
|
|
|
|
it('should return the send.gasPrice', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getGasPrice(mockState), '0xaa');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getGasTotal()', function () {
|
|
|
|
it('should return the send.gasTotal', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getGasTotal(mockState), 'a9ff56');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getPrimaryCurrency()', function () {
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should return the symbol of the send token', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
getPrimaryCurrency({
|
|
|
|
metamask: { send: { token: { symbol: 'DEF' } } },
|
|
|
|
}),
|
2020-07-14 17:20:41 +02:00
|
|
|
'DEF',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
describe('getSendToken()', function () {
|
|
|
|
it('should return the current send token if set', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken({
|
|
|
|
metamask: {
|
|
|
|
send: {
|
|
|
|
token: {
|
|
|
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
decimals: 4,
|
|
|
|
symbol: 'DEF',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2018-05-05 17:11:53 +02:00
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
decimals: 4,
|
|
|
|
symbol: 'DEF',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
describe('getSendTokenContract()', function () {
|
|
|
|
it('should return the contract at the send token address', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendTokenContract({
|
|
|
|
metamask: {
|
|
|
|
send: {
|
|
|
|
token: {
|
|
|
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
decimals: 4,
|
|
|
|
symbol: 'DEF',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2020-07-14 17:20:41 +02:00
|
|
|
'mockAt:0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should return null if send token is not set', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const modifiedMetamaskState = { ...mockState.metamask, send: {} };
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-08-19 18:27:05 +02:00
|
|
|
getSendTokenContract({ ...mockState, metamask: modifiedMetamaskState }),
|
2020-07-14 17:20:41 +02:00
|
|
|
null,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendAmount()', function () {
|
|
|
|
it('should return the send.amount', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getSendAmount(mockState), '0x080');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendEditingTransactionId()', function () {
|
|
|
|
it('should return the send.editingTransactionId', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getSendEditingTransactionId(mockState), 97531);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendErrors()', function () {
|
|
|
|
it('should return the send.errors', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepStrictEqual(getSendErrors(mockState), { someError: null });
|
|
|
|
});
|
|
|
|
});
|
2018-08-16 09:43:13 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendHexDataFeatureFlagState()', function () {
|
|
|
|
it('should return the sendHexData feature flag state', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepStrictEqual(getSendHexDataFeatureFlagState(mockState), true);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendFrom()', function () {
|
|
|
|
it('should return the send.from', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendFrom(mockState),
|
2020-03-11 19:40:35 +01:00
|
|
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendFromBalance()', function () {
|
|
|
|
it('should get the send.from balance if it exists', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getSendFromBalance(mockState), '0x37452b1315889f80');
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should get the selected account balance if the send.from does not exist', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
const editedMockState = {
|
2020-08-19 18:27:05 +02:00
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
2018-05-05 17:11:53 +02:00
|
|
|
send: {
|
|
|
|
from: null,
|
|
|
|
},
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
assert.strictEqual(getSendFromBalance(editedMockState), '0x0');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendFromObject()', function () {
|
|
|
|
it('should return send.from if it exists', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(getSendFromObject(mockState), {
|
2020-11-03 00:41:28 +01:00
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
code: '0x',
|
|
|
|
nonce: '0xa',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-03-11 19:40:35 +01:00
|
|
|
it('should return the current account if send.from does not exist', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
const editedMockState = {
|
2020-08-19 18:27:05 +02:00
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
2018-05-05 17:11:53 +02:00
|
|
|
send: {
|
|
|
|
from: null,
|
|
|
|
},
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(getSendFromObject(editedMockState), {
|
2020-11-03 00:41:28 +01:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendMaxModeState()', function () {
|
|
|
|
it('should return send.maxModeOn', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getSendMaxModeState(mockState), false);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendTo()', function () {
|
|
|
|
it('should return send.to', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getSendTo(mockState), '0x987fedabc');
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getSendToAccounts()', function () {
|
|
|
|
it('should return an array including all the users accounts and the address book', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(getSendToAccounts(mockState), [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
|
|
|
|
name: 'Address Book Account 1',
|
|
|
|
chainId: '0x3',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getTokenBalance()', function () {
|
|
|
|
it('should', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getTokenBalance(mockState), 3434);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getUnapprovedTxs()', function () {
|
|
|
|
it('should return the unapproved txs', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(getUnapprovedTxs(mockState), {
|
2020-11-03 00:41:28 +01:00
|
|
|
4768706228115573: {
|
|
|
|
id: 4768706228115573,
|
|
|
|
time: 1487363153561,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasMultiplier: 1,
|
|
|
|
metamaskNetworkId: '3',
|
|
|
|
txParams: {
|
|
|
|
from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
metamaskId: 4768706228115573,
|
2018-05-14 14:13:55 +02:00
|
|
|
metamaskNetworkId: '3',
|
2020-11-03 00:41:28 +01:00
|
|
|
gas: '0x5209',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
txFee: '17e0186e60800',
|
|
|
|
txValue: 'de0b6b3a7640000',
|
|
|
|
maxCost: 'de234b52e4a0800',
|
|
|
|
gasPrice: '4a817c800',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('send-amount-row selectors', function () {
|
|
|
|
describe('sendAmountIsInError()', function () {
|
|
|
|
it('should return true if send.errors.amount is truthy', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
amount: 'abc',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(sendAmountIsInError(state), true);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
it('should return false if send.errors.amount is falsy', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
amount: null,
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(sendAmountIsInError(state), false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('send-gas-row selectors', function () {
|
|
|
|
describe('getGasLoadingError()', function () {
|
|
|
|
it('should return send.errors.gasLoading', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasLoading: 'abc',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getGasLoadingError(state), 'abc');
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('gasFeeIsInError()', function () {
|
|
|
|
it('should return true if send.errors.gasFee is truthy', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasFee: 'def',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(gasFeeIsInError(state), true);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
it('should return false send.errors.gasFee is falsely', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasFee: null,
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(gasFeeIsInError(state), false);
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('getGasButtonGroupShown()', function () {
|
|
|
|
it('should return send.gasButtonGroupShown', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
gasButtonGroupShown: 'foobar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(getGasButtonGroupShown(state), 'foobar');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('send-header selectors', function () {
|
|
|
|
const getMetamaskSendMockState = (send) => {
|
|
|
|
return {
|
|
|
|
metamask: {
|
|
|
|
send: { ...send },
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('getTitleKey()', function () {
|
|
|
|
it('should return the correct key when "to" is empty', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
getTitleKey(getMetamaskSendMockState({})),
|
|
|
|
'addRecipient',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
it('should return the correct key when getSendEditingTransactionId is truthy', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-05-04 17:22:34 +02:00
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: true,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: {},
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
|
|
|
'edit',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is truthy', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-05-04 17:22:34 +02:00
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: false,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: {},
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
|
|
|
'sendTokens',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is falsy', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-05-04 17:22:34 +02:00
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: false,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: null,
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
|
|
|
'sendETH',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('send-footer selectors', function () {
|
|
|
|
const getSendMockState = (send) => {
|
|
|
|
return {
|
|
|
|
send: { ...send },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
describe('isSendFormInError()', function () {
|
|
|
|
it('should return true if any of the values of the object returned by getSendErrors are truthy', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [true],
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
true,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
|
|
|
it('should return false if all of the values of the object returned by getSendErrors are falsy', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [],
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
false,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [false],
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
false,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|