2022-09-29 05:26:01 +02:00
|
|
|
import { CHAIN_IDS } from '../../shared/constants/network';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionType } 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-03-16 22:00:08 +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
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Confirm Transaction Selector', () => {
|
|
|
|
describe('unconfirmedTransactionsCountSelector', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedTxs: {
|
|
|
|
1: {
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
2: {
|
2022-09-14 16:55:31 +02:00
|
|
|
chainId: CHAIN_IDS.MAINNET,
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
unapprovedMsgCount: 1,
|
|
|
|
unapprovedPersonalMsgCount: 1,
|
|
|
|
unapprovedTypedMessagesCount: 1,
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2021-03-01 16:15:42 +01:00
|
|
|
provider: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-03-01 16:15:42 +01:00
|
|
|
},
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns number of txs in unapprovedTxs state with the same network plus unapproved signing method counts', () => {
|
|
|
|
expect(unconfirmedTransactionsCountSelector(state)).toStrictEqual(4);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('sendTokenTokenAmountAndToAddressSelector', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
confirmTransaction: {
|
|
|
|
tokenData: {
|
2023-01-18 15:47:29 +01:00
|
|
|
name: TransactionType.tokenMethodTransfer,
|
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: {
|
2021-06-24 01:50:24 +02:00
|
|
|
decimals: '2',
|
|
|
|
symbol: 'META',
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns token address and calculated token amount', () => {
|
|
|
|
expect(sendTokenTokenAmountAndToAddressSelector(state)).toStrictEqual({
|
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
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('contractExchangeRateSelector', () => {
|
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
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('returns contract exchange rate in metamask state based on confirm transaction txParams token recipient', () => {
|
|
|
|
expect(contractExchangeRateSelector(state)).toStrictEqual('10');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('conversionRateSelector', () => {
|
|
|
|
it('returns conversionRate from state', () => {
|
2020-05-05 16:05:16 +02:00
|
|
|
const state = {
|
|
|
|
metamask: { conversionRate: 556.12 },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(conversionRateSelector(state)).toStrictEqual(556.12);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|