2020-01-30 20:34:45 +01:00
|
|
|
import assert from 'assert'
|
|
|
|
import {
|
|
|
|
unconfirmedTransactionsCountSelector,
|
|
|
|
sendTokenTokenAmountAndToAddressSelector,
|
|
|
|
contractExchangeRateSelector,
|
2020-05-05 16:05:16 +02:00
|
|
|
conversionRateSelector,
|
2020-01-30 20:34:45 +01:00
|
|
|
} from '../confirm-transaction'
|
|
|
|
|
2020-08-22 04:29:19 +02:00
|
|
|
const getEthersArrayLikeFromObj = (obj) => {
|
|
|
|
const arr = []
|
|
|
|
Object.keys(obj).forEach((key) => {
|
|
|
|
arr.push([obj[key]])
|
|
|
|
arr[key] = obj[key]
|
|
|
|
})
|
|
|
|
return arr
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Confirm Transaction Selector', function () {
|
|
|
|
describe('unconfirmedTransactionsCountSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedTxs: {
|
|
|
|
1: {
|
|
|
|
metamaskNetworkId: 'test',
|
|
|
|
},
|
|
|
|
2: {
|
|
|
|
metmaskNetworkId: 'other network',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
unapprovedMsgCount: 1,
|
|
|
|
unapprovedPersonalMsgCount: 1,
|
|
|
|
unapprovedTypedMessagesCount: 1,
|
|
|
|
network: 'test',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns number of txs in unapprovedTxs state with the same network plus unapproved signing method counts', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
assert.equal(unconfirmedTransactionsCountSelector(state), 4)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('sendTokenTokenAmountAndToAddressSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
confirmTransaction: {
|
|
|
|
tokenData: {
|
|
|
|
name: 'transfer',
|
2020-08-22 04:29:19 +02:00
|
|
|
args: getEthersArrayLikeFromObj({
|
2020-11-03 00:41:28 +01:00
|
|
|
_to: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
_value: { toString: () => '1' },
|
2020-08-22 04:29:19 +02:00
|
|
|
}),
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
tokenProps: {
|
|
|
|
tokenDecimals: '2',
|
|
|
|
tokenSymbol: 'META',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns token address and calculated token amount', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(sendTokenTokenAmountAndToAddressSelector(state), {
|
|
|
|
toAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
tokenAmount: '0.01',
|
|
|
|
})
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('contractExchangeRateSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
contractExchangeRates: {
|
|
|
|
'0xTokenAddress': '10',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
confirmTransaction: {
|
|
|
|
txData: {
|
|
|
|
txParams: {
|
|
|
|
to: '0xTokenAddress',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns contract exchange rate in metamask state based on confirm transaction txParams token recipient', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
assert.equal(contractExchangeRateSelector(state), 10)
|
|
|
|
})
|
2020-05-05 16:05:16 +02:00
|
|
|
})
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-05-05 16:05:16 +02:00
|
|
|
describe('conversionRateSelector', function () {
|
|
|
|
it('returns conversionRate from state', function () {
|
|
|
|
const state = {
|
|
|
|
metamask: { conversionRate: 556.12 },
|
|
|
|
}
|
|
|
|
assert.equal(conversionRateSelector(state), 556.12)
|
|
|
|
})
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|