2021-02-04 19:15:23 +01:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import sinon from 'sinon';
|
2023-08-03 19:31:35 +02:00
|
|
|
import { NetworkStatus } from '@metamask/network-controller';
|
|
|
|
import { NetworkType } from '@metamask/controller-utils';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionStatus } from '../../../shared/constants/transaction';
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import ConfirmTransactionReducer, * as actions from './confirm-transaction.duck';
|
2018-07-10 09:18:37 +02:00
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
txData: {},
|
|
|
|
tokenData: {},
|
2021-06-24 01:50:24 +02:00
|
|
|
tokenProps: {},
|
2018-07-10 09:18:37 +02:00
|
|
|
fiatTransactionAmount: '',
|
|
|
|
fiatTransactionFee: '',
|
|
|
|
fiatTransactionTotal: '',
|
|
|
|
ethTransactionAmount: '',
|
|
|
|
ethTransactionFee: '',
|
|
|
|
ethTransactionTotal: '',
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionAmount: '',
|
|
|
|
hexTransactionFee: '',
|
|
|
|
hexTransactionTotal: '',
|
2018-07-10 09:18:37 +02:00
|
|
|
nonce: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const UPDATE_TX_DATA = 'metamask/confirm-transaction/UPDATE_TX_DATA';
|
|
|
|
const UPDATE_TOKEN_DATA = 'metamask/confirm-transaction/UPDATE_TOKEN_DATA';
|
2020-11-03 00:41:28 +01:00
|
|
|
const UPDATE_TRANSACTION_AMOUNTS =
|
2021-02-04 19:15:23 +01:00
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_AMOUNTS';
|
2020-11-03 00:41:28 +01:00
|
|
|
const UPDATE_TRANSACTION_FEES =
|
2021-02-04 19:15:23 +01:00
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_FEES';
|
2020-11-03 00:41:28 +01:00
|
|
|
const UPDATE_TRANSACTION_TOTALS =
|
2021-02-04 19:15:23 +01:00
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_TOTALS';
|
|
|
|
const UPDATE_NONCE = 'metamask/confirm-transaction/UPDATE_NONCE';
|
2020-11-03 00:41:28 +01:00
|
|
|
const CLEAR_CONFIRM_TRANSACTION =
|
2021-02-04 19:15:23 +01:00
|
|
|
'metamask/confirm-transaction/CLEAR_CONFIRM_TRANSACTION';
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Confirm Transaction Duck', () => {
|
|
|
|
describe('State changes', () => {
|
2018-07-10 09:18:37 +02:00
|
|
|
const mockState = {
|
2020-02-06 17:38:14 +01:00
|
|
|
txData: {
|
|
|
|
id: 1,
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
2020-02-06 17:38:14 +01:00
|
|
|
tokenData: {
|
|
|
|
name: 'abcToken',
|
|
|
|
},
|
|
|
|
fiatTransactionAmount: '469.26',
|
|
|
|
fiatTransactionFee: '0.01',
|
|
|
|
fiatTransactionTotal: '1.000021',
|
|
|
|
ethTransactionAmount: '1',
|
|
|
|
ethTransactionFee: '0.000021',
|
|
|
|
ethTransactionTotal: '469.27',
|
|
|
|
hexTransactionAmount: '',
|
|
|
|
hexTransactionFee: '0x1319718a5000',
|
|
|
|
hexTransactionTotal: '',
|
|
|
|
nonce: '0x0',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should initialize state', () => {
|
|
|
|
expect(ConfirmTransactionReducer(undefined, {})).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
initialState,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return state unchanged if it does not match a dispatched actions type', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: 'someOtherAction',
|
|
|
|
value: 'someValue',
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({ ...mockState });
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should set txData when receiving a UPDATE_TX_DATA action', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: UPDATE_TX_DATA,
|
|
|
|
payload: {
|
|
|
|
id: 2,
|
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
...mockState,
|
|
|
|
txData: {
|
|
|
|
...mockState.txData,
|
|
|
|
id: 2,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should set tokenData when receiving a UPDATE_TOKEN_DATA action', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: UPDATE_TOKEN_DATA,
|
|
|
|
payload: {
|
|
|
|
name: 'defToken',
|
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
...mockState,
|
|
|
|
tokenData: {
|
|
|
|
...mockState.tokenData,
|
|
|
|
name: 'defToken',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should update transaction amounts when receiving an UPDATE_TRANSACTION_AMOUNTS action', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: UPDATE_TRANSACTION_AMOUNTS,
|
|
|
|
payload: {
|
|
|
|
fiatTransactionAmount: '123.45',
|
|
|
|
ethTransactionAmount: '.5',
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionAmount: '0x1',
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
...mockState,
|
|
|
|
fiatTransactionAmount: '123.45',
|
|
|
|
ethTransactionAmount: '.5',
|
|
|
|
hexTransactionAmount: '0x1',
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should update transaction fees when receiving an UPDATE_TRANSACTION_FEES action', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: UPDATE_TRANSACTION_FEES,
|
|
|
|
payload: {
|
|
|
|
fiatTransactionFee: '123.45',
|
|
|
|
ethTransactionFee: '.5',
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionFee: '0x1',
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
...mockState,
|
|
|
|
fiatTransactionFee: '123.45',
|
|
|
|
ethTransactionFee: '.5',
|
|
|
|
hexTransactionFee: '0x1',
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should update transaction totals when receiving an UPDATE_TRANSACTION_TOTALS action', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: UPDATE_TRANSACTION_TOTALS,
|
|
|
|
payload: {
|
|
|
|
fiatTransactionTotal: '123.45',
|
|
|
|
ethTransactionTotal: '.5',
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionTotal: '0x1',
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
...mockState,
|
|
|
|
fiatTransactionTotal: '123.45',
|
|
|
|
ethTransactionTotal: '.5',
|
|
|
|
hexTransactionTotal: '0x1',
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should update nonce when receiving an UPDATE_NONCE action', () => {
|
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: UPDATE_NONCE,
|
|
|
|
payload: '0x1',
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
...mockState,
|
|
|
|
nonce: '0x1',
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should clear confirmTransaction when receiving a FETCH_DATA_END action', () => {
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
ConfirmTransactionReducer(mockState, {
|
|
|
|
type: CLEAR_CONFIRM_TRANSACTION,
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(initialState);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Single actions', function () {
|
|
|
|
it('should create an action to update txData', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const txData = { test: 123 };
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: UPDATE_TX_DATA,
|
|
|
|
payload: txData,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actions.updateTxData(txData)).toStrictEqual(expectedAction);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should create an action to update tokenData', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const tokenData = { test: 123 };
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: UPDATE_TOKEN_DATA,
|
|
|
|
payload: tokenData,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actions.updateTokenData(tokenData)).toStrictEqual(expectedAction);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should create an action to update transaction amounts', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const transactionAmounts = { test: 123 };
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: UPDATE_TRANSACTION_AMOUNTS,
|
|
|
|
payload: transactionAmounts,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2018-07-10 09:18:37 +02:00
|
|
|
actions.updateTransactionAmounts(transactionAmounts),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(expectedAction);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should create an action to update transaction fees', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const transactionFees = { test: 123 };
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: UPDATE_TRANSACTION_FEES,
|
|
|
|
payload: transactionFees,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actions.updateTransactionFees(transactionFees)).toStrictEqual(
|
2020-07-14 17:20:41 +02:00
|
|
|
expectedAction,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should create an action to update transaction totals', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const transactionTotals = { test: 123 };
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: UPDATE_TRANSACTION_TOTALS,
|
|
|
|
payload: transactionTotals,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actions.updateTransactionTotals(transactionTotals)).toStrictEqual(
|
2020-07-14 17:20:41 +02:00
|
|
|
expectedAction,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should create an action to update nonce', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nonce = '0x1';
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: UPDATE_NONCE,
|
|
|
|
payload: nonce,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actions.updateNonce(nonce)).toStrictEqual(expectedAction);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should create an action to clear confirmTransaction', () => {
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedAction = {
|
|
|
|
type: CLEAR_CONFIRM_TRANSACTION,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(actions.clearConfirmTransaction()).toStrictEqual(expectedAction);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Thunk actions', () => {
|
|
|
|
beforeEach(() => {
|
2018-08-17 23:34:14 +02:00
|
|
|
global.eth = {
|
2020-11-03 00:41:28 +01:00
|
|
|
getCode: sinon
|
|
|
|
.stub()
|
|
|
|
.callsFake((address) =>
|
2020-11-05 18:09:42 +01:00
|
|
|
Promise.resolve(address?.match(/isContract/u) ? 'not-0x' : '0x'),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
});
|
2018-08-17 23:34:14 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
global.eth.getCode.resetHistory();
|
|
|
|
});
|
2018-08-17 23:34:14 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('updates txData and updates gas values in confirmTransaction', () => {
|
2018-07-10 09:18:37 +02:00
|
|
|
const txData = {
|
|
|
|
history: [],
|
|
|
|
id: 2603411941761054,
|
|
|
|
loadingDefaults: false,
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2018-07-10 09:18:37 +02:00
|
|
|
origin: 'faucet.metamask.io',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2018-07-10 09:18:37 +02:00
|
|
|
time: 1530838113716,
|
|
|
|
txParams: {
|
|
|
|
from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
|
|
|
gas: '0x33450',
|
|
|
|
gasPrice: '0x2540be400',
|
|
|
|
to: '0x81b7e08f65bdf5648606c89998a9cc8164397647',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
|
|
|
conversionRate: 468.58,
|
|
|
|
currentCurrency: 'usd',
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-01-27 18:17:47 +01:00
|
|
|
ticker: 'ETH',
|
|
|
|
},
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
|
|
|
confirmTransaction: {
|
|
|
|
ethTransactionAmount: '1',
|
|
|
|
ethTransactionFee: '0.000021',
|
|
|
|
ethTransactionTotal: '1.000021',
|
2018-08-17 23:34:14 +02:00
|
|
|
fetchingData: false,
|
2018-07-10 09:18:37 +02:00
|
|
|
fiatTransactionAmount: '469.26',
|
|
|
|
fiatTransactionFee: '0.01',
|
|
|
|
fiatTransactionTotal: '469.27',
|
|
|
|
hexGasTotal: '0x1319718a5000',
|
|
|
|
methodData: {},
|
|
|
|
nonce: '',
|
|
|
|
tokenData: {},
|
|
|
|
tokenProps: {
|
2021-06-24 01:50:24 +02:00
|
|
|
decimals: '',
|
|
|
|
symbol: '',
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
|
|
|
txData: {
|
|
|
|
...txData,
|
|
|
|
txParams: {
|
|
|
|
...txData.txParams,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const middlewares = [thunk];
|
|
|
|
const mockStore = configureMockStore(middlewares);
|
|
|
|
const store = mockStore(mockState);
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedActions = [
|
|
|
|
'metamask/confirm-transaction/UPDATE_TX_DATA',
|
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_AMOUNTS',
|
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_FEES',
|
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_TOTALS',
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
store.dispatch(actions.updateTxDataAndCalculate(txData));
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const storeActions = store.getActions();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(storeActions).toHaveLength(expectedActions.length);
|
2020-11-03 00:41:28 +01:00
|
|
|
storeActions.forEach((action, index) =>
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(action.type).toStrictEqual(expectedActions[index]),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('updates confirmTransaction transaction', () => {
|
2018-07-10 09:18:37 +02:00
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
|
|
|
conversionRate: 468.58,
|
|
|
|
currentCurrency: 'usd',
|
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-08-03 19:31:35 +02:00
|
|
|
selectedNetworkClientId: NetworkType.goerli,
|
|
|
|
networksMetadata: {
|
|
|
|
[NetworkType.goerli]: {
|
|
|
|
EIPS: {},
|
|
|
|
status: NetworkStatus.Available,
|
|
|
|
},
|
|
|
|
},
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chainId: '0x5',
|
2021-03-01 16:15:42 +01:00
|
|
|
},
|
2023-09-04 17:48:25 +02:00
|
|
|
transactions: [
|
|
|
|
{
|
2018-07-10 09:18:37 +02:00
|
|
|
history: [],
|
|
|
|
id: 2603411941761054,
|
|
|
|
loadingDefaults: false,
|
2022-09-29 05:26:01 +02:00
|
|
|
metamaskNetworkId: '5',
|
2018-07-10 09:18:37 +02:00
|
|
|
origin: 'faucet.metamask.io',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2018-07-10 09:18:37 +02:00
|
|
|
time: 1530838113716,
|
|
|
|
txParams: {
|
|
|
|
from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
|
|
|
|
gas: '0x33450',
|
|
|
|
gasPrice: '0x2540be400',
|
|
|
|
to: '0x81b7e08f65bdf5648606c89998a9cc8164397647',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
},
|
|
|
|
},
|
2023-09-04 17:48:25 +02:00
|
|
|
],
|
2018-07-10 09:18:37 +02:00
|
|
|
},
|
|
|
|
confirmTransaction: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const middlewares = [thunk];
|
|
|
|
const mockStore = configureMockStore(middlewares);
|
|
|
|
const store = mockStore(mockState);
|
2018-07-10 09:18:37 +02:00
|
|
|
const expectedActions = [
|
|
|
|
'metamask/confirm-transaction/UPDATE_TX_DATA',
|
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_AMOUNTS',
|
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_FEES',
|
|
|
|
'metamask/confirm-transaction/UPDATE_TRANSACTION_TOTALS',
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-07-10 09:18:37 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
store.dispatch(actions.setTransactionToConfirm(2603411941761054));
|
|
|
|
const storeActions = store.getActions();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(storeActions).toHaveLength(expectedActions.length);
|
2018-08-17 23:34:14 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
storeActions.forEach((action, index) =>
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(action.type).toStrictEqual(expectedActions[index]),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|