2023-02-01 06:54:41 +01:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
|
|
|
|
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
|
|
|
import { setBackgroundConnection } from '../../../test/jest';
|
|
|
|
import { INITIAL_SEND_STATE_FOR_EXISTING_DRAFT } from '../../../test/jest/mocks';
|
|
|
|
import { GasEstimateTypes } from '../../../shared/constants/gas';
|
2023-03-21 15:43:22 +01:00
|
|
|
import { KeyringType } from '../../../shared/constants/keyring';
|
2023-02-01 06:54:41 +01:00
|
|
|
import { CHAIN_IDS } from '../../../shared/constants/network';
|
|
|
|
import { domainInitialState } from '../../ducks/domains';
|
|
|
|
|
|
|
|
import ConfirmTransactionBase from './confirm-transaction-base.container';
|
|
|
|
|
|
|
|
const middleware = [thunk];
|
|
|
|
|
|
|
|
setBackgroundConnection({
|
|
|
|
getGasFeeTimeEstimate: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest.fn(),
|
|
|
|
promisifiedBackground: jest.fn(),
|
|
|
|
tryReverseResolveAddress: jest.fn(),
|
|
|
|
getNextNonce: jest.fn(),
|
|
|
|
});
|
|
|
|
|
|
|
|
const baseStore = {
|
2023-04-17 16:34:26 +02:00
|
|
|
send: {
|
|
|
|
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
|
|
|
|
currentTransactionUUID: null,
|
|
|
|
draftTransactions: {},
|
|
|
|
},
|
2023-02-01 06:54:41 +01:00
|
|
|
DNS: domainInitialState,
|
|
|
|
gas: {
|
|
|
|
customData: { limit: null, price: null },
|
|
|
|
},
|
|
|
|
history: { mostRecentOverviewPage: '/' },
|
|
|
|
metamask: {
|
|
|
|
unapprovedTxs: {
|
|
|
|
1: {
|
|
|
|
id: 1,
|
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
|
|
|
metamaskNetworkId: '5',
|
2023-02-01 06:54:41 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0x0',
|
|
|
|
to: '0x85c1685cfceaa5c0bdb1609fc536e9a8387dd65e',
|
|
|
|
value: '0x5af3107a4000',
|
|
|
|
gas: '0x5208',
|
|
|
|
maxFeePerGas: '0x59682f16',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
|
|
type: '0x2',
|
|
|
|
data: 'data',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
|
|
|
gasFeeEstimates: {
|
|
|
|
low: '0',
|
|
|
|
medium: '1',
|
|
|
|
fast: '2',
|
|
|
|
},
|
|
|
|
selectedAddress: '0x0',
|
|
|
|
keyrings: [
|
|
|
|
{
|
2023-03-21 15:43:22 +01:00
|
|
|
type: KeyringType.hdKeyTree,
|
2023-02-01 06:54:41 +01:00
|
|
|
accounts: ['0x0'],
|
|
|
|
},
|
|
|
|
],
|
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',
|
2023-02-01 06:54:41 +01:00
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
tokens: [],
|
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: false,
|
|
|
|
},
|
|
|
|
currentCurrency: 'USD',
|
|
|
|
provider: {
|
|
|
|
chainId: CHAIN_IDS.GOERLI,
|
|
|
|
},
|
|
|
|
nativeCurrency: 'ETH',
|
|
|
|
featureFlags: {
|
|
|
|
sendHexData: false,
|
|
|
|
},
|
|
|
|
addressBook: {
|
|
|
|
[CHAIN_IDS.GOERLI]: [],
|
|
|
|
},
|
|
|
|
cachedBalances: {
|
|
|
|
[CHAIN_IDS.GOERLI]: {},
|
|
|
|
},
|
|
|
|
accounts: {
|
|
|
|
'0x0': { balance: '0x0', address: '0x0' },
|
|
|
|
},
|
|
|
|
identities: { '0x0': { address: '0x0' } },
|
|
|
|
tokenAddress: '0x32e6c34cd57087abbd59b5a4aecc4cb495924356',
|
|
|
|
tokenList: {},
|
|
|
|
ensResolutionsByAddress: {},
|
|
|
|
snaps: {},
|
|
|
|
},
|
|
|
|
confirmTransaction: {
|
|
|
|
txData: {
|
|
|
|
id: 1,
|
|
|
|
time: 1675012496170,
|
|
|
|
status: 'unapproved',
|
|
|
|
metamaskNetworkId: '5',
|
|
|
|
originalGasEstimate: '0x5208',
|
|
|
|
userEditedGasLimit: false,
|
|
|
|
chainId: '0x5',
|
|
|
|
loadingDefaults: false,
|
|
|
|
dappSuggestedGasFees: null,
|
|
|
|
sendFlowHistory: [],
|
|
|
|
txParams: {
|
|
|
|
from: '0x0',
|
|
|
|
to: '0x85c1685cfceaa5c0bdb1609fc536e9a8387dd65e',
|
|
|
|
value: '0x5af3107a4000',
|
|
|
|
gas: '0x5208',
|
|
|
|
maxFeePerGas: '0x59682f16',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
|
|
type: '0x2',
|
|
|
|
},
|
|
|
|
origin: 'metamask',
|
|
|
|
actionId: 1675012496153.2039,
|
|
|
|
type: 'simpleSend',
|
|
|
|
history: [],
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
defaultGasEstimates: {
|
|
|
|
estimateType: 'medium',
|
|
|
|
gas: '0x5208',
|
|
|
|
maxFeePerGas: '0x59682f16',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tokenData: {},
|
|
|
|
tokenProps: {},
|
|
|
|
fiatTransactionAmount: '0.16',
|
|
|
|
fiatTransactionFee: '0',
|
|
|
|
fiatTransactionTotal: '0.16',
|
|
|
|
ethTransactionAmount: '0.0001',
|
|
|
|
ethTransactionFee: '0',
|
|
|
|
ethTransactionTotal: '0.0001',
|
|
|
|
hexTransactionAmount: '0x5af3107a4000',
|
|
|
|
hexTransactionFee: '0x0',
|
|
|
|
hexTransactionTotal: '0x5af3107a4000',
|
|
|
|
nonce: '',
|
|
|
|
},
|
|
|
|
appState: {
|
|
|
|
sendInputCurrencySwitched: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Confirm Transaction Base', () => {
|
|
|
|
it('should match snapshot', () => {
|
2023-04-26 02:13:38 +02:00
|
|
|
const store = configureMockStore(middleware)(baseStore);
|
2023-02-01 06:54:41 +01:00
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<ConfirmTransactionBase actionKey="confirm" />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
2023-04-26 02:13:38 +02:00
|
|
|
|
|
|
|
it('should contain L1 L2 fee details for optimism', () => {
|
|
|
|
baseStore.metamask.provider.chainId = CHAIN_IDS.OPTIMISM;
|
|
|
|
baseStore.confirmTransaction.txData.chainId = CHAIN_IDS.OPTIMISM;
|
|
|
|
const store = configureMockStore(middleware)(baseStore);
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<ConfirmTransactionBase actionKey="confirm" />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
expect(getByText('Layer 1 fees')).toBeInTheDocument();
|
|
|
|
expect(getByText('Layer 2 gas fee')).toBeInTheDocument();
|
|
|
|
});
|
2023-02-01 06:54:41 +01:00
|
|
|
});
|