2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
|
2020-01-30 20:34:45 +01:00
|
|
|
import {
|
|
|
|
unconfirmedTransactionsCountSelector,
|
|
|
|
sendTokenTokenAmountAndToAddressSelector,
|
|
|
|
contractExchangeRateSelector,
|
2020-05-05 16:05:16 +02:00
|
|
|
conversionRateSelector,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../confirm-transaction';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-08-22 04:29:19 +02:00
|
|
|
const getEthersArrayLikeFromObj = (obj) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const arr = [];
|
2020-08-22 04:29:19 +02:00
|
|
|
Object.keys(obj).forEach((key) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
arr.push([obj[key]]);
|
|
|
|
arr[key] = obj[key];
|
|
|
|
});
|
|
|
|
return arr;
|
|
|
|
};
|
2020-08-22 04:29:19 +02:00
|
|
|
|
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',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(unconfirmedTransactionsCountSelector(state), 4);
|
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('sendTokenTokenAmountAndToAddressSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
confirmTransaction: {
|
|
|
|
tokenData: {
|
2020-11-07 08:38:12 +01:00
|
|
|
name: TRANSACTION_CATEGORIES.TOKEN_METHOD_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',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns token address and calculated token amount', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(sendTokenTokenAmountAndToAddressSelector(state), {
|
2020-11-03 00:41:28 +01:00
|
|
|
toAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
tokenAmount: '0.01',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns contract exchange rate in metamask state based on confirm transaction txParams token recipient', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(contractExchangeRateSelector(state), '10');
|
|
|
|
});
|
|
|
|
});
|
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 },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
assert.strictEqual(conversionRateSelector(state), 556.12);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|