2018-05-05 17:11:53 +02:00
|
|
|
import assert from 'assert'
|
2018-05-14 14:13:55 +02:00
|
|
|
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,
|
2020-05-04 20:27:14 +02:00
|
|
|
} from '..'
|
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,
|
2020-05-04 20:27:14 +02:00
|
|
|
} from '../send'
|
2018-05-05 17:11:53 +02:00
|
|
|
import mockState from './send-selectors-test-data'
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send selectors', function () {
|
2018-05-14 14:57:36 +02:00
|
|
|
const tempGlobalEth = Object.assign({}, 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-02-15 21:34:12 +01:00
|
|
|
at: (address) => 'mockAt:' + address,
|
2018-05-14 14:57:36 +02:00
|
|
|
}),
|
2018-05-14 14:13:55 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2018-05-14 14:13:55 +02: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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
accountsWithSendEtherInfoSelector(mockState),
|
|
|
|
[
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x47c9d71831c76efe',
|
|
|
|
nonce: '0x1b',
|
|
|
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
|
|
|
name: 'Send Account 1',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
nonce: '0xa',
|
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
name: 'Send Account 2',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x30c9d71831c76efe',
|
|
|
|
nonce: '0x1c',
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
name: 'Send Account 3',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2020-07-14 17:20:41 +02: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 () {
|
2018-05-22 17:16:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getBlockGasLimit(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getConversionRate(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getCurrentAccountWithSendEtherInfo(mockState),
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
2020-07-14 17:20:41 +02: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 () {
|
2018-10-26 10:26:43 +02:00
|
|
|
assert.equal(
|
|
|
|
getNativeCurrency(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getCurrentNetwork(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getGasLimit(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getGasPrice(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getGasTotal(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
2020-05-29 19:46:10 +02:00
|
|
|
getPrimaryCurrency({ metamask: { send: { token: { symbol: 'DEF' } } } }),
|
2020-07-14 17:20:41 +02:00
|
|
|
'DEF',
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
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
|
|
|
},
|
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 () {
|
2018-05-14 14:13:55 +02:00
|
|
|
assert.equal(
|
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',
|
2018-05-14 14:13:55 +02: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 () {
|
|
|
|
const modifiedMetamaskState = Object.assign({}, mockState.metamask, { send: {} })
|
2018-05-14 14:13:55 +02:00
|
|
|
assert.equal(
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendTokenContract(Object.assign({}, mockState, { metamask: modifiedMetamaskState })),
|
2020-07-14 17:20:41 +02:00
|
|
|
null,
|
2018-05-14 14:13:55 +02: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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getSendAmount(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getSendEditingTransactionId(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getSendErrors(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
{ someError: null },
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
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 () {
|
2018-08-16 09:43:13 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getSendHexDataFeatureFlagState(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
true,
|
2018-08-16 09:43:13 +02:00
|
|
|
)
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getSendFrom(mockState),
|
2020-03-11 19:40:35 +01:00
|
|
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getSendFromBalance(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 = {
|
|
|
|
metamask: Object.assign({}, mockState.metamask, {
|
|
|
|
send: {
|
|
|
|
from: null,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
assert.equal(
|
|
|
|
getSendFromBalance(editedMockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getSendFromObject(mockState),
|
|
|
|
{
|
2020-03-11 19:40:35 +01:00
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
code: '0x',
|
|
|
|
nonce: '0xa',
|
2020-07-14 17:20:41 +02: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 = {
|
|
|
|
metamask: Object.assign({}, mockState.metamask, {
|
|
|
|
send: {
|
|
|
|
from: null,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
assert.deepEqual(
|
|
|
|
getSendFromObject(editedMockState),
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
2020-07-14 17:20:41 +02: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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getSendMaxModeState(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getSendTo(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
'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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getSendToAccounts(mockState),
|
|
|
|
[
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x47c9d71831c76efe',
|
|
|
|
nonce: '0x1b',
|
|
|
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
|
|
|
name: 'Send Account 1',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
nonce: '0xa',
|
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
name: 'Send Account 2',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x30c9d71831c76efe',
|
|
|
|
nonce: '0x1c',
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
name: 'Send Account 3',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
|
|
|
|
name: 'Address Book Account 1',
|
2019-07-31 21:56:44 +02:00
|
|
|
chainId: '3',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2020-07-14 17:20:41 +02:00
|
|
|
],
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('getTokenBalance()', function () {
|
|
|
|
it('should', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.equal(
|
|
|
|
getTokenBalance(mockState),
|
2020-07-14 17:20:41 +02:00
|
|
|
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 () {
|
2018-05-05 17:11:53 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
getUnapprovedTxs(mockState),
|
|
|
|
{
|
2018-05-14 14:13:55 +02:00
|
|
|
4768706228115573: {
|
|
|
|
id: 4768706228115573,
|
|
|
|
time: 1487363153561,
|
|
|
|
status: 'unapproved',
|
|
|
|
gasMultiplier: 1,
|
|
|
|
metamaskNetworkId: '3',
|
|
|
|
txParams: {
|
|
|
|
from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
metamaskId: 4768706228115573,
|
|
|
|
metamaskNetworkId: '3',
|
|
|
|
gas: '0x5209',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2018-05-14 14:13:55 +02:00
|
|
|
txFee: '17e0186e60800',
|
|
|
|
txValue: 'de0b6b3a7640000',
|
|
|
|
maxCost: 'de234b52e4a0800',
|
|
|
|
gasPrice: '4a817c800',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2018-05-05 17:11:53 +02: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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(sendAmountIsInError(state), true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if send.errors.amount is falsy', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
amount: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(sendAmountIsInError(state), false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('send-gas-row selectors', function () {
|
|
|
|
|
|
|
|
describe('getGasLoadingError()', function () {
|
|
|
|
it('should return send.errors.gasLoading', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasLoading: 'abc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(getGasLoadingError(state), 'abc')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('gasFeeIsInError()', function () {
|
|
|
|
it('should return true if send.errors.gasFee is truthy', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasFee: 'def',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(gasFeeIsInError(state), true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false send.errors.gasFee is falsely', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasFee: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(gasFeeIsInError(state), false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getGasButtonGroupShown()', function () {
|
|
|
|
it('should return send.gasButtonGroupShown', function () {
|
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
gasButtonGroupShown: 'foobar',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(getGasButtonGroupShown(state), 'foobar')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('send-header selectors', function () {
|
|
|
|
|
|
|
|
const getMetamaskSendMockState = (send) => {
|
|
|
|
return {
|
|
|
|
metamask: {
|
|
|
|
send: { ...send },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('getTitleKey()', function () {
|
|
|
|
it('should return the correct key when "to" is empty', function () {
|
|
|
|
assert.equal(getTitleKey(getMetamaskSendMockState({})), 'addRecipient')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the correct key when getSendEditingTransactionId is truthy', function () {
|
|
|
|
assert.equal(
|
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: true,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: {},
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-05-04 17:22:34 +02:00
|
|
|
), 'edit')
|
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is truthy', function () {
|
2020-05-04 17:22:34 +02:00
|
|
|
assert.equal(
|
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: false,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: {},
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-05-04 17:22:34 +02:00
|
|
|
), 'sendTokens')
|
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is falsy', function () {
|
2020-05-04 17:22:34 +02:00
|
|
|
assert.equal(
|
|
|
|
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-05-04 17:22:34 +02:00
|
|
|
), 'sendETH')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('send-footer selectors', function () {
|
|
|
|
|
|
|
|
const getSendMockState = (send) => {
|
|
|
|
return {
|
|
|
|
send: { ...send },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('isSendFormInError()', function () {
|
|
|
|
it('should return true if any of the values of the object returned by getSendErrors are truthy', function () {
|
|
|
|
assert.equal(isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [ true ],
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-05-04 17:22:34 +02:00
|
|
|
), true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false if all of the values of the object returned by getSendErrors are falsy', function () {
|
|
|
|
assert.equal(isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [],
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-05-04 17:22:34 +02:00
|
|
|
), false)
|
|
|
|
assert.equal(isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [ false ],
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-05-04 17:22:34 +02:00
|
|
|
), false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|