1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/selectors/confirm-transaction.test.js
ryanml 0bc1eeaf37
Deprecating the Rinkeby, Ropsten, and Kovan test networks (#15989)
* Deprecating Rinkeby, setting default debug network to Goerli

* Deprecating Ropsten and Kovan

* Conflict fix

* Remove unused localization, test fixes

* Add migration for moving used deprecated testnets to custom networks

* Fix migrator test

* Add more unit tests

* Migration updates provider type to rpc if deprecated network is selected

* Migration fully and correctly updates the provider if selected network is a deprecated testnet

* Continue to show deprecation warning on each of rinkeby, ropsten and kovan

* Add rpcUrl deprecation message to loading screen

* Removing mayBeFauceting prop

Co-authored-by: Dan Miller <danjm.com@gmail.com>
2022-09-28 20:26:01 -07:00

101 lines
2.7 KiB
JavaScript

import { CHAIN_IDS } from '../../shared/constants/network';
import { TRANSACTION_TYPES } from '../../shared/constants/transaction';
import {
unconfirmedTransactionsCountSelector,
sendTokenTokenAmountAndToAddressSelector,
contractExchangeRateSelector,
conversionRateSelector,
} from './confirm-transaction';
const getEthersArrayLikeFromObj = (obj) => {
const arr = [];
Object.keys(obj).forEach((key) => {
arr.push([obj[key]]);
arr[key] = obj[key];
});
return arr;
};
describe('Confirm Transaction Selector', () => {
describe('unconfirmedTransactionsCountSelector', () => {
const state = {
metamask: {
unapprovedTxs: {
1: {
metamaskNetworkId: '5',
},
2: {
chainId: CHAIN_IDS.MAINNET,
},
},
unapprovedMsgCount: 1,
unapprovedPersonalMsgCount: 1,
unapprovedTypedMessagesCount: 1,
network: '5',
provider: {
chainId: '0x5',
},
},
};
it('returns number of txs in unapprovedTxs state with the same network plus unapproved signing method counts', () => {
expect(unconfirmedTransactionsCountSelector(state)).toStrictEqual(4);
});
});
describe('sendTokenTokenAmountAndToAddressSelector', () => {
const state = {
confirmTransaction: {
tokenData: {
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
args: getEthersArrayLikeFromObj({
_to: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
_value: { toString: () => '1' },
}),
},
tokenProps: {
decimals: '2',
symbol: 'META',
},
},
};
it('returns token address and calculated token amount', () => {
expect(sendTokenTokenAmountAndToAddressSelector(state)).toStrictEqual({
toAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
tokenAmount: '0.01',
});
});
});
describe('contractExchangeRateSelector', () => {
const state = {
metamask: {
contractExchangeRates: {
'0xTokenAddress': '10',
},
},
confirmTransaction: {
txData: {
txParams: {
to: '0xTokenAddress',
},
},
},
};
it('returns contract exchange rate in metamask state based on confirm transaction txParams token recipient', () => {
expect(contractExchangeRateSelector(state)).toStrictEqual('10');
});
});
describe('conversionRateSelector', () => {
it('returns conversionRate from state', () => {
const state = {
metamask: { conversionRate: 556.12 },
};
expect(conversionRateSelector(state)).toStrictEqual(556.12);
});
});
});