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.
594 lines
15 KiB
594 lines
15 KiB
7 years ago
|
import assert from 'assert'
|
||
7 years ago
|
import sinon from 'sinon'
|
||
5 years ago
|
import {
|
||
7 years ago
|
accountsWithSendEtherInfoSelector,
|
||
5 years ago
|
getCurrentAccountWithSendEtherInfo,
|
||
5 years ago
|
} from '..'
|
||
5 years ago
|
import {
|
||
7 years ago
|
getBlockGasLimit,
|
||
7 years ago
|
getConversionRate,
|
||
|
getCurrentNetwork,
|
||
6 years ago
|
getNativeCurrency,
|
||
7 years ago
|
getGasLimit,
|
||
|
getGasPrice,
|
||
|
getGasTotal,
|
||
|
getPrimaryCurrency,
|
||
|
getSelectedToken,
|
||
7 years ago
|
getSelectedTokenContract,
|
||
7 years ago
|
getSendAmount,
|
||
5 years ago
|
sendAmountIsInError,
|
||
7 years ago
|
getSendEditingTransactionId,
|
||
|
getSendErrors,
|
||
|
getSendFrom,
|
||
|
getSendFromBalance,
|
||
|
getSendFromObject,
|
||
6 years ago
|
getSendHexDataFeatureFlagState,
|
||
7 years ago
|
getSendMaxModeState,
|
||
|
getSendTo,
|
||
|
getSendToAccounts,
|
||
|
getTokenBalance,
|
||
|
getUnapprovedTxs,
|
||
5 years ago
|
gasFeeIsInError,
|
||
|
getGasLoadingError,
|
||
|
getGasButtonGroupShown,
|
||
|
getTitleKey,
|
||
|
isSendFormInError,
|
||
5 years ago
|
} from '../send'
|
||
7 years ago
|
import mockState from './send-selectors-test-data'
|
||
|
|
||
5 years ago
|
describe('send selectors', function () {
|
||
7 years ago
|
const tempGlobalEth = Object.assign({}, global.eth)
|
||
5 years ago
|
beforeEach(function () {
|
||
7 years ago
|
global.eth = {
|
||
|
contract: sinon.stub().returns({
|
||
5 years ago
|
at: (address) => 'mockAt:' + address,
|
||
7 years ago
|
}),
|
||
7 years ago
|
}
|
||
|
})
|
||
|
|
||
5 years ago
|
afterEach(function () {
|
||
7 years ago
|
global.eth = tempGlobalEth
|
||
|
})
|
||
7 years ago
|
|
||
5 years ago
|
describe('accountsWithSendEtherInfoSelector()', function () {
|
||
|
it('should return an array of account objects with name info from identities', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
accountsWithSendEtherInfoSelector(mockState),
|
||
|
[
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x47c9d71831c76efe',
|
||
|
nonce: '0x1b',
|
||
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
||
|
name: 'Send Account 1',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x37452b1315889f80',
|
||
|
nonce: '0xa',
|
||
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
|
name: 'Send Account 2',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x30c9d71831c76efe',
|
||
|
nonce: '0x1c',
|
||
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
||
|
name: 'Send Account 3',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
|
name: 'Send Account 4',
|
||
7 years ago
|
},
|
||
|
]
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getBlockGasLimit', function () {
|
||
|
it('should return the current block gas limit', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getBlockGasLimit(mockState),
|
||
|
'0x4c1878'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getConversionRate()', function () {
|
||
|
it('should return the eth conversion rate', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getConversionRate(mockState),
|
||
|
1200.88200327
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getCurrentAccountWithSendEtherInfo()', function () {
|
||
|
it('should return the currently selected account with identity info', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getCurrentAccountWithSendEtherInfo(mockState),
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
|
name: 'Send Account 4',
|
||
7 years ago
|
}
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getNativeCurrency()', function () {
|
||
|
it('should return the ticker symbol of the selected network', function () {
|
||
6 years ago
|
assert.equal(
|
||
|
getNativeCurrency(mockState),
|
||
|
'ETH'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getCurrentNetwork()', function () {
|
||
|
it('should return the id of the currently selected network', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getCurrentNetwork(mockState),
|
||
|
'3'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getGasLimit()', function () {
|
||
|
it('should return the send.gasLimit', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getGasLimit(mockState),
|
||
|
'0xFFFF'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getGasPrice()', function () {
|
||
|
it('should return the send.gasPrice', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getGasPrice(mockState),
|
||
|
'0xaa'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getGasTotal()', function () {
|
||
|
it('should return the send.gasTotal', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getGasTotal(mockState),
|
||
6 years ago
|
'a9ff56'
|
||
7 years ago
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getPrimaryCurrency()', function () {
|
||
|
it('should return the symbol of the selected token', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getPrimaryCurrency(mockState),
|
||
|
'DEF'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSelectedToken()', function () {
|
||
|
it('should return the currently selected token if selected', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getSelectedToken(mockState),
|
||
|
{
|
||
7 years ago
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
||
|
decimals: 4,
|
||
|
symbol: 'DEF',
|
||
7 years ago
|
}
|
||
|
)
|
||
|
})
|
||
|
|
||
5 years ago
|
it('should return the send token if none is currently selected, but a send token exists', function () {
|
||
7 years ago
|
const mockSendToken = {
|
||
7 years ago
|
address: '0x123456708414189a58339873ab429b6c47ab92d3',
|
||
|
decimals: 4,
|
||
|
symbol: 'JKL',
|
||
7 years ago
|
}
|
||
|
const editedMockState = {
|
||
|
metamask: Object.assign({}, mockState.metamask, {
|
||
|
selectedTokenAddress: null,
|
||
|
send: {
|
||
|
token: mockSendToken,
|
||
|
},
|
||
|
}),
|
||
|
}
|
||
|
assert.deepEqual(
|
||
|
getSelectedToken(editedMockState),
|
||
|
Object.assign({}, mockSendToken)
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSelectedTokenContract()', function () {
|
||
|
it('should return the contract at the selected token address', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getSelectedTokenContract(mockState),
|
||
|
'mockAt:0x8d6b81208414189a58339873ab429b6c47ab92d3'
|
||
|
)
|
||
|
})
|
||
7 years ago
|
|
||
5 years ago
|
it('should return null if no token is selected', function () {
|
||
7 years ago
|
const modifiedMetamaskState = Object.assign({}, mockState.metamask, { selectedTokenAddress: false })
|
||
|
assert.equal(
|
||
|
getSelectedTokenContract(Object.assign({}, mockState, { metamask: modifiedMetamaskState })),
|
||
|
null
|
||
|
)
|
||
|
})
|
||
|
})
|
||
7 years ago
|
|
||
5 years ago
|
describe('getSendAmount()', function () {
|
||
|
it('should return the send.amount', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getSendAmount(mockState),
|
||
|
'0x080'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendEditingTransactionId()', function () {
|
||
|
it('should return the send.editingTransactionId', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getSendEditingTransactionId(mockState),
|
||
|
97531
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendErrors()', function () {
|
||
|
it('should return the send.errors', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getSendErrors(mockState),
|
||
7 years ago
|
{ someError: null }
|
||
7 years ago
|
)
|
||
6 years ago
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendHexDataFeatureFlagState()', function () {
|
||
|
it('should return the sendHexData feature flag state', function () {
|
||
6 years ago
|
assert.deepEqual(
|
||
|
getSendHexDataFeatureFlagState(mockState),
|
||
|
true
|
||
|
)
|
||
7 years ago
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendFrom()', function () {
|
||
|
it('should return the send.from', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getSendFrom(mockState),
|
||
5 years ago
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
7 years ago
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendFromBalance()', function () {
|
||
|
it('should get the send.from balance if it exists', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getSendFromBalance(mockState),
|
||
5 years ago
|
'0x37452b1315889f80'
|
||
7 years ago
|
)
|
||
|
})
|
||
|
|
||
5 years ago
|
it('should get the selected account balance if the send.from does not exist', function () {
|
||
7 years ago
|
const editedMockState = {
|
||
|
metamask: Object.assign({}, mockState.metamask, {
|
||
|
send: {
|
||
|
from: null,
|
||
|
},
|
||
|
}),
|
||
|
}
|
||
|
assert.equal(
|
||
|
getSendFromBalance(editedMockState),
|
||
|
'0x0'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendFromObject()', function () {
|
||
|
it('should return send.from if it exists', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getSendFromObject(mockState),
|
||
|
{
|
||
5 years ago
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
|
balance: '0x37452b1315889f80',
|
||
|
code: '0x',
|
||
|
nonce: '0xa',
|
||
7 years ago
|
}
|
||
|
)
|
||
|
})
|
||
|
|
||
5 years ago
|
it('should return the current account if send.from does not exist', function () {
|
||
7 years ago
|
const editedMockState = {
|
||
|
metamask: Object.assign({}, mockState.metamask, {
|
||
|
send: {
|
||
|
from: null,
|
||
|
},
|
||
|
}),
|
||
|
}
|
||
|
assert.deepEqual(
|
||
|
getSendFromObject(editedMockState),
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
7 years ago
|
}
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendMaxModeState()', function () {
|
||
|
it('should return send.maxModeOn', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getSendMaxModeState(mockState),
|
||
|
false
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendTo()', function () {
|
||
|
it('should return send.to', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getSendTo(mockState),
|
||
|
'0x987fedabc'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getSendToAccounts()', function () {
|
||
|
it('should return an array including all the users accounts and the address book', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getSendToAccounts(mockState),
|
||
|
[
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x47c9d71831c76efe',
|
||
|
nonce: '0x1b',
|
||
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
||
|
name: 'Send Account 1',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x37452b1315889f80',
|
||
|
nonce: '0xa',
|
||
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
|
name: 'Send Account 2',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x30c9d71831c76efe',
|
||
|
nonce: '0x1c',
|
||
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
||
|
name: 'Send Account 3',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
code: '0x',
|
||
|
balance: '0x0',
|
||
|
nonce: '0x0',
|
||
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
||
|
name: 'Send Account 4',
|
||
7 years ago
|
},
|
||
|
{
|
||
7 years ago
|
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
|
||
|
name: 'Address Book Account 1',
|
||
5 years ago
|
chainId: '3',
|
||
7 years ago
|
},
|
||
|
]
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getTokenBalance()', function () {
|
||
|
it('should', function () {
|
||
7 years ago
|
assert.equal(
|
||
|
getTokenBalance(mockState),
|
||
|
3434
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
5 years ago
|
describe('getUnapprovedTxs()', function () {
|
||
|
it('should return the unapproved txs', function () {
|
||
7 years ago
|
assert.deepEqual(
|
||
|
getUnapprovedTxs(mockState),
|
||
|
{
|
||
7 years ago
|
4768706228115573: {
|
||
|
id: 4768706228115573,
|
||
|
time: 1487363153561,
|
||
|
status: 'unapproved',
|
||
|
gasMultiplier: 1,
|
||
|
metamaskNetworkId: '3',
|
||
|
txParams: {
|
||
|
from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||
|
to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
|
||
|
value: '0xde0b6b3a7640000',
|
||
|
metamaskId: 4768706228115573,
|
||
|
metamaskNetworkId: '3',
|
||
|
gas: '0x5209',
|
||
7 years ago
|
},
|
||
7 years ago
|
txFee: '17e0186e60800',
|
||
|
txValue: 'de0b6b3a7640000',
|
||
|
maxCost: 'de234b52e4a0800',
|
||
|
gasPrice: '4a817c800',
|
||
7 years ago
|
},
|
||
|
}
|
||
|
)
|
||
|
})
|
||
|
})
|
||
5 years ago
|
|
||
|
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,
|
||
|
token: true, // this can be whatever
|
||
|
})
|
||
|
), 'edit')
|
||
|
})
|
||
|
|
||
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSelectedToken is truthy', function () {
|
||
|
assert.equal(
|
||
|
getTitleKey(
|
||
|
getMetamaskSendMockState({
|
||
|
to: true,
|
||
|
editingTransactionId: false,
|
||
|
token: true,
|
||
|
})
|
||
|
), 'sendTokens')
|
||
|
})
|
||
|
|
||
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSelectedToken is falsy', function () {
|
||
|
assert.equal(
|
||
|
getTitleKey(
|
||
|
getMetamaskSendMockState({
|
||
|
to: true,
|
||
|
editingTransactionId: false,
|
||
|
token: false,
|
||
|
})
|
||
|
), '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 ],
|
||
|
})
|
||
|
), true)
|
||
|
})
|
||
|
|
||
|
it('should return false if all of the values of the object returned by getSendErrors are falsy', function () {
|
||
|
assert.equal(isSendFormInError(
|
||
|
getSendMockState({
|
||
|
errors: [],
|
||
|
})
|
||
|
), false)
|
||
|
assert.equal(isSendFormInError(
|
||
|
getSendMockState({
|
||
|
errors: [ false ],
|
||
|
})
|
||
|
), false)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
7 years ago
|
})
|