2020-01-30 20:34:45 +01:00
|
|
|
import assert from 'assert'
|
|
|
|
import {
|
|
|
|
unconfirmedTransactionsCountSelector,
|
|
|
|
tokenAmountAndToAddressSelector,
|
|
|
|
approveTokenAmountAndToAddressSelector,
|
|
|
|
sendTokenTokenAmountAndToAddressSelector,
|
|
|
|
contractExchangeRateSelector,
|
|
|
|
} from '../confirm-transaction'
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Confirm Transaction Selector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
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('tokenAmountAndToAddressSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
confirmTransaction: {
|
|
|
|
tokenData: {
|
|
|
|
name: 'transfer',
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: '_to',
|
|
|
|
value: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
type: 'address',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '_value',
|
|
|
|
value: '1',
|
|
|
|
type: 'uint256',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
tokenProps: {
|
|
|
|
tokenDecimals: '2',
|
|
|
|
tokenSymbol: 'META',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns calulcated token amount based on token value and token decimals and recipient address', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
assert.deepEqual(tokenAmountAndToAddressSelector(state),
|
|
|
|
{ toAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', tokenAmount: 0.01 })
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('approveTokenAmountAndToAddressSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
confirmTransaction: {
|
|
|
|
tokenData: {
|
|
|
|
name: 'approve',
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: '_spender',
|
|
|
|
value: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
type: 'address',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '_value',
|
|
|
|
value: '1',
|
|
|
|
type: 'uint256',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
tokenProps: {
|
|
|
|
tokenDecimals: '2',
|
|
|
|
tokenSymbol: 'META',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns token amount and recipient for approve token allocation spending', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
assert.deepEqual(approveTokenAmountAndToAddressSelector(state),
|
|
|
|
{ toAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', tokenAmount: 0.01 })
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
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',
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: '_to',
|
|
|
|
value: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
type: 'address',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '_value',
|
|
|
|
value: '1',
|
|
|
|
type: 'uint256',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
tokenProps: {
|
|
|
|
tokenDecimals: '2',
|
|
|
|
tokenSymbol: 'META',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns token address and calculated token amount', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
assert.deepEqual(sendTokenTokenAmountAndToAddressSelector(state),
|
|
|
|
{ toAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', tokenAmount: 0.01 })
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|