2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionStatus } from '../../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import * as actionConstants from '../../store/actionConstants';
|
2021-06-08 18:03:59 +02:00
|
|
|
import reduceMetamask, {
|
|
|
|
getBlockGasLimit,
|
|
|
|
getConversionRate,
|
2022-01-07 20:18:02 +01:00
|
|
|
getIsNetworkBusy,
|
2021-06-08 18:03:59 +02:00
|
|
|
getNativeCurrency,
|
|
|
|
getSendHexDataFeatureFlagState,
|
|
|
|
getSendToAccounts,
|
|
|
|
getUnapprovedTxs,
|
2021-09-30 13:57:59 +02:00
|
|
|
isNotEIP1559Network,
|
2021-06-08 18:03:59 +02:00
|
|
|
} from './metamask';
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('MetaMask Reducers', () => {
|
2021-06-08 18:03:59 +02:00
|
|
|
const mockState = {
|
|
|
|
metamask: reduceMetamask(
|
|
|
|
{
|
|
|
|
isInitialized: true,
|
|
|
|
isUnlocked: true,
|
|
|
|
featureFlags: { sendHexData: true },
|
|
|
|
identities: {
|
|
|
|
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
|
|
|
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
|
|
|
name: 'Send Account 1',
|
|
|
|
},
|
|
|
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb': {
|
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
name: 'Send Account 2',
|
|
|
|
},
|
|
|
|
'0x2f8d4a878cfa04a6e60d46362f5644deab66572d': {
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
name: 'Send Account 3',
|
|
|
|
},
|
|
|
|
'0xd85a4b6a394794842887b8284293d69163007bbb': {
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cachedBalances: {},
|
|
|
|
currentBlockGasLimit: '0x4c1878',
|
|
|
|
conversionRate: 1200.88200327,
|
|
|
|
nativeCurrency: 'ETH',
|
2023-01-27 18:17:47 +01:00
|
|
|
useCurrencyRateCheck: true,
|
NetworkController: Split `network` into `networkId` and `networkStatus` (#17556)
The `network` store of the network controller crams two types of data
into one place. It roughly tracks whether we have enough information to
make requests to the network and whether the network is capable of
receiving requests, but it also stores the ID of the network (as
obtained via `net_version`).
Generally we shouldn't be using the network ID for anything, as it has
been completely replaced by chain ID, which all custom RPC endpoints
have been required to support for over a year now. However, as the
network ID is used in various places within the extension codebase,
removing it entirely would be a non-trivial effort. So, minimally, this
commit splits `network` into two stores: `networkId` and
`networkStatus`. But it also expands the concept of network status.
Previously, the network was in one of two states: "loading" and
"not-loading". But now it can be in one of four states:
- `available`: The network is able to receive and respond to requests.
- `unavailable`: The network is not able to receive and respond to
requests for unknown reasons.
- `blocked`: The network is actively blocking requests based on the
user's geolocation. (This is specific to Infura.)
- `unknown`: We don't know whether the network can receive and respond
to requests, either because we haven't checked or we tried to check
and were unsuccessful.
This commit also changes how the network status is determined —
specifically, how many requests are used to determine that status, when
they occur, and whether they are awaited. Previously, the network
controller would make 2 to 3 requests during the course of running
`lookupNetwork`.
* First, if it was an Infura network, it would make a request for
`eth_blockNumber` to determine whether Infura was blocking requests or
not, then emit an appropriate event. This operation was not awaited.
* Then, regardless of the network, it would fetch the network ID via
`net_version`. This operation was awaited.
* Finally, regardless of the network, it would fetch the latest block
via `eth_getBlockByNumber`, then use the result to determine whether
the network supported EIP-1559. This operation was awaited.
Now:
* One fewer request is made, specifically `eth_blockNumber`, as we don't
need to make an extra request to determine whether Infura is blocking
requests; we can reuse `eth_getBlockByNumber`;
* All requests are awaited, which makes `lookupNetwork` run fully
in-band instead of partially out-of-band; and
* Both requests for `net_version` and `eth_getBlockByNumber` are
performed in parallel to make `lookupNetwork` run slightly faster.
2023-03-31 00:49:12 +02:00
|
|
|
networkId: '5',
|
|
|
|
networkStatus: 'available',
|
2021-06-08 18:03:59 +02:00
|
|
|
provider: {
|
|
|
|
type: 'testnet',
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2023-01-27 18:17:47 +01:00
|
|
|
ticker: 'TestETH',
|
2021-06-08 18:03:59 +02:00
|
|
|
},
|
|
|
|
accounts: {
|
|
|
|
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x47c9d71831c76efe',
|
|
|
|
nonce: '0x1b',
|
|
|
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
|
|
|
},
|
|
|
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb': {
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
nonce: '0xa',
|
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
},
|
|
|
|
'0x2f8d4a878cfa04a6e60d46362f5644deab66572d': {
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x30c9d71831c76efe',
|
|
|
|
nonce: '0x1c',
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
},
|
|
|
|
'0xd85a4b6a394794842887b8284293d69163007bbb': {
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addressBook: {
|
2022-09-29 05:26:01 +02:00
|
|
|
'0x5': {
|
2021-06-08 18:03:59 +02:00
|
|
|
'0x06195827297c7a80a443b6894d3bdb8824b43896': {
|
|
|
|
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
|
|
|
|
name: 'Address Book Account 1',
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-06-08 18:03:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
unapprovedTxs: {
|
|
|
|
4768706228115573: {
|
|
|
|
id: 4768706228115573,
|
|
|
|
time: 1487363153561,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-06-08 18:03:59 +02:00
|
|
|
gasMultiplier: 1,
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2021-06-08 18:03:59 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
metamaskId: 4768706228115573,
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2021-06-08 18:03:59 +02:00
|
|
|
gas: '0x5209',
|
|
|
|
},
|
|
|
|
txFee: '17e0186e60800',
|
|
|
|
txValue: 'de0b6b3a7640000',
|
|
|
|
maxCost: 'de234b52e4a0800',
|
|
|
|
gasPrice: '4a817c800',
|
|
|
|
},
|
|
|
|
},
|
2021-09-30 13:57:59 +02:00
|
|
|
networkDetails: {
|
|
|
|
EIPS: { 1559: true },
|
|
|
|
},
|
2021-06-08 18:03:59 +02:00
|
|
|
},
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
it('init state', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const initState = reduceMetamask(undefined, {});
|
2021-06-08 18:03:59 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect.anything(initState);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('locks MetaMask', () => {
|
2018-10-31 15:07:25 +01:00
|
|
|
const unlockMetaMaskState = {
|
2020-02-06 17:38:14 +01:00
|
|
|
isUnlocked: true,
|
|
|
|
selectedAddress: 'test address',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-10 10:12:46 +02:00
|
|
|
const lockMetaMask = reduceMetamask(unlockMetaMaskState, {
|
2020-04-09 02:35:37 +02:00
|
|
|
type: actionConstants.LOCK_METAMASK,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(lockMetaMask.isUnlocked).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('sets account label', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const state = reduceMetamask(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: actionConstants.SET_ACCOUNT_LABEL,
|
|
|
|
value: {
|
|
|
|
account: 'test account',
|
|
|
|
label: 'test label',
|
|
|
|
},
|
2018-10-10 10:12:46 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(state.identities).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
'test account': { name: 'test label' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('toggles account menu', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const state = reduceMetamask(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: actionConstants.TOGGLE_ACCOUNT_MENU,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(state.isAccountMenuOpen).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2023-04-13 18:54:03 +02:00
|
|
|
it('toggles network menu', () => {
|
|
|
|
const state = reduceMetamask(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: actionConstants.TOGGLE_NETWORK_MENU,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(state.isNetworkMenuOpen).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('updates value of tx by id', () => {
|
2018-10-10 10:12:46 +02:00
|
|
|
const oldState = {
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList: [
|
2020-02-06 17:38:14 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
txParams: 'foo',
|
|
|
|
},
|
|
|
|
],
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-10 10:12:46 +02:00
|
|
|
|
|
|
|
const state = reduceMetamask(oldState, {
|
2020-04-09 02:35:37 +02:00
|
|
|
type: actionConstants.UPDATE_TRANSACTION_PARAMS,
|
2018-10-10 10:12:46 +02:00
|
|
|
id: 1,
|
|
|
|
value: 'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(state.currentNetworkTxList[0].txParams).toStrictEqual('bar');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('close welcome screen', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const state = reduceMetamask(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: actionConstants.CLOSE_WELCOME_SCREEN,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(state.welcomeScreenSeen).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('sets pending tokens', () => {
|
2018-10-10 10:12:46 +02:00
|
|
|
const payload = {
|
2020-11-03 00:41:28 +01:00
|
|
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'META',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const pendingTokensState = reduceMetamask(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: actionConstants.SET_PENDING_TOKENS,
|
|
|
|
payload,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(pendingTokensState.pendingTokens).toStrictEqual(payload);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('clears pending tokens', () => {
|
2018-10-31 15:07:25 +01:00
|
|
|
const payload = {
|
2020-11-03 00:41:28 +01:00
|
|
|
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'META',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-31 15:07:25 +01:00
|
|
|
|
|
|
|
const pendingTokensState = {
|
|
|
|
pendingTokens: payload,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-31 15:07:25 +01:00
|
|
|
|
2018-10-10 10:12:46 +02:00
|
|
|
const state = reduceMetamask(pendingTokensState, {
|
2020-04-09 02:35:37 +02:00
|
|
|
type: actionConstants.CLEAR_PENDING_TOKENS,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-10 10:12:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(state.pendingTokens).toStrictEqual({});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2023-02-23 17:39:48 +01:00
|
|
|
it('disables desktop', () => {
|
|
|
|
const enabledMetaMaskState = {
|
|
|
|
desktopEnabled: true,
|
|
|
|
};
|
|
|
|
const enabledDesktopMetaMask = reduceMetamask(enabledMetaMaskState, {
|
|
|
|
type: actionConstants.FORCE_DISABLE_DESKTOP,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(enabledDesktopMetaMask.desktopEnabled).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
|
2021-06-08 18:03:59 +02:00
|
|
|
describe('metamask state selectors', () => {
|
|
|
|
describe('getBlockGasLimit', () => {
|
|
|
|
it('should return the current block gas limit', () => {
|
|
|
|
expect(getBlockGasLimit(mockState)).toStrictEqual('0x4c1878');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getConversionRate()', () => {
|
|
|
|
it('should return the eth conversion rate', () => {
|
|
|
|
expect(getConversionRate(mockState)).toStrictEqual(1200.88200327);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getNativeCurrency()', () => {
|
2023-01-27 18:17:47 +01:00
|
|
|
it('should return nativeCurrency when useCurrencyRateCheck is true', () => {
|
2021-06-08 18:03:59 +02:00
|
|
|
expect(getNativeCurrency(mockState)).toStrictEqual('ETH');
|
|
|
|
});
|
2023-01-27 18:17:47 +01:00
|
|
|
|
|
|
|
it('should return the ticker symbol of the selected network when useCurrencyRateCheck is false', () => {
|
|
|
|
expect(
|
|
|
|
getNativeCurrency({
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
useCurrencyRateCheck: false,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
).toStrictEqual('TestETH');
|
|
|
|
});
|
2021-06-08 18:03:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('getSendHexDataFeatureFlagState()', () => {
|
|
|
|
it('should return the sendHexData feature flag state', () => {
|
|
|
|
expect(getSendHexDataFeatureFlagState(mockState)).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getSendToAccounts()', () => {
|
|
|
|
it('should return an array including all the users accounts and the address book', () => {
|
|
|
|
expect(getSendToAccounts(mockState)).toStrictEqual([
|
|
|
|
{
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x47c9d71831c76efe',
|
|
|
|
nonce: '0x1b',
|
|
|
|
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
|
|
|
|
name: 'Send Account 1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
nonce: '0xa',
|
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
name: 'Send Account 2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x30c9d71831c76efe',
|
|
|
|
nonce: '0x1c',
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
name: 'Send Account 3',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
|
|
|
|
name: 'Address Book Account 1',
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-06-08 18:03:59 +02:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the unapproved txs', () => {
|
|
|
|
expect(getUnapprovedTxs(mockState)).toStrictEqual({
|
|
|
|
4768706228115573: {
|
|
|
|
id: 4768706228115573,
|
|
|
|
time: 1487363153561,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-06-08 18:03:59 +02:00
|
|
|
gasMultiplier: 1,
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2021-06-08 18:03:59 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
metamaskId: 4768706228115573,
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2021-06-08 18:03:59 +02:00
|
|
|
gas: '0x5209',
|
|
|
|
},
|
|
|
|
txFee: '17e0186e60800',
|
|
|
|
txValue: 'de0b6b3a7640000',
|
|
|
|
maxCost: 'de234b52e4a0800',
|
|
|
|
gasPrice: '4a817c800',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-09-30 13:57:59 +02:00
|
|
|
|
|
|
|
describe('isNotEIP1559Network()', () => {
|
|
|
|
it('should return true if network does not supports EIP-1559', () => {
|
|
|
|
expect(
|
|
|
|
isNotEIP1559Network({
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: { 1559: false },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if networkDetails.EIPS.1559 is not false', () => {
|
|
|
|
expect(isNotEIP1559Network(mockState)).toStrictEqual(false);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
isNotEIP1559Network({
|
|
|
|
...mockState,
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: { 1559: undefined },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2022-01-07 20:18:02 +01:00
|
|
|
|
|
|
|
describe('getIsNetworkBusy', () => {
|
|
|
|
it('should return true if state.metamask.gasFeeEstimates.networkCongestion is over the "busy" threshold', () => {
|
|
|
|
expect(
|
|
|
|
getIsNetworkBusy({
|
|
|
|
metamask: { gasFeeEstimates: { networkCongestion: 0.67 } },
|
|
|
|
}),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return true if state.metamask.gasFeeEstimates.networkCongestion is right at the "busy" threshold', () => {
|
|
|
|
expect(
|
|
|
|
getIsNetworkBusy({
|
|
|
|
metamask: { gasFeeEstimates: { networkCongestion: 0.66 } },
|
|
|
|
}),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if state.metamask.gasFeeEstimates.networkCongestion is not over the "busy" threshold', () => {
|
|
|
|
expect(
|
|
|
|
getIsNetworkBusy({
|
|
|
|
metamask: { gasFeeEstimates: { networkCongestion: 0.65 } },
|
|
|
|
}),
|
|
|
|
).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|