2021-02-04 19:15:23 +01:00
|
|
|
import { strict as assert } from 'assert';
|
|
|
|
import EventEmitter from 'events';
|
2021-04-16 17:05:13 +02:00
|
|
|
import { toBuffer } from 'ethereumjs-util';
|
2021-06-16 22:40:17 +02:00
|
|
|
import { TransactionFactory } from '@ethereumjs/tx';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { ObservableStore } from '@metamask/obs-store';
|
|
|
|
import sinon from 'sinon';
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
createTestProviderTools,
|
|
|
|
getTestAccounts,
|
2021-03-16 22:00:08 +01:00
|
|
|
} from '../../../../test/stub/provider';
|
2022-01-31 18:27:46 +01:00
|
|
|
import mockEstimates from '../../../../test/data/mock-estimates.json';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } from '../../../../shared/constants/metametrics';
|
2020-11-03 23:57:51 +01:00
|
|
|
import {
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionStatus,
|
|
|
|
TransactionType,
|
|
|
|
TransactionEnvelopeType,
|
|
|
|
TransactionMetaMetricsEvent,
|
|
|
|
AssetType,
|
|
|
|
TokenStandard,
|
2021-03-16 22:00:08 +01:00
|
|
|
} from '../../../../shared/constants/transaction';
|
2021-10-28 01:55:02 +02:00
|
|
|
|
2021-06-10 21:27:03 +02:00
|
|
|
import { SECOND } from '../../../../shared/constants/time';
|
2021-11-06 01:59:23 +01:00
|
|
|
import {
|
2023-01-27 19:28:03 +01:00
|
|
|
GasEstimateTypes,
|
|
|
|
GasRecommendations,
|
2021-11-06 01:59:23 +01:00
|
|
|
} from '../../../../shared/constants/gas';
|
2021-03-16 22:00:08 +01:00
|
|
|
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
|
2022-04-26 19:07:39 +02:00
|
|
|
import { ORIGIN_METAMASK } from '../../../../shared/constants/app';
|
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
|
|
|
import { NetworkStatus } from '../../../../shared/constants/network';
|
2022-09-16 21:05:21 +02:00
|
|
|
import { TRANSACTION_ENVELOPE_TYPE_NAMES } from '../../../../shared/lib/transactions-controller-utils';
|
2022-01-20 17:26:39 +01:00
|
|
|
import TransactionController from '.';
|
2017-08-15 04:15:09 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const noop = () => true;
|
2022-09-29 05:26:01 +02:00
|
|
|
const currentNetworkId = '5';
|
|
|
|
const currentChainId = '0x5';
|
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
|
|
|
const currentNetworkStatus = NetworkStatus.Available;
|
2021-06-16 22:40:17 +02:00
|
|
|
const providerConfig = {
|
2022-09-29 05:26:01 +02:00
|
|
|
type: 'goerli',
|
2021-06-16 22:40:17 +02:00
|
|
|
};
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = 'DUMMY_ACTION_ID';
|
2021-03-30 16:54:05 +02:00
|
|
|
const VALID_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
|
const VALID_ADDRESS_TWO = '0x0000000000000000000000000000000000000001';
|
|
|
|
|
2017-08-02 17:34:45 +02:00
|
|
|
describe('Transaction Controller', function () {
|
2022-12-13 20:13:12 +01:00
|
|
|
let txController,
|
|
|
|
provider,
|
|
|
|
providerResultStub,
|
|
|
|
fromAccount,
|
|
|
|
fragmentExists,
|
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
|
|
|
networkStatusStore,
|
|
|
|
getCurrentChainId;
|
2016-12-14 21:56:53 +01:00
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
beforeEach(function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = false;
|
2018-01-18 06:43:34 +01:00
|
|
|
providerResultStub = {
|
|
|
|
// 1 gwei
|
|
|
|
eth_gasPrice: '0x0de0b6b3a7640000',
|
|
|
|
// by default, all accounts are external accounts (not contracts)
|
|
|
|
eth_getCode: '0x',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2022-01-20 17:56:52 +01:00
|
|
|
provider = createTestProviderTools({
|
|
|
|
scaffold: providerResultStub,
|
|
|
|
networkId: currentNetworkId,
|
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
|
|
|
chainId: parseInt(currentChainId, 16),
|
2022-01-20 17:56:52 +01:00
|
|
|
}).provider;
|
2021-06-16 22:40:17 +02:00
|
|
|
|
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
|
|
|
networkStatusStore = new ObservableStore(currentNetworkStatus);
|
2022-12-13 20:13:12 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
fromAccount = getTestAccounts()[0];
|
|
|
|
const blockTrackerStub = new EventEmitter();
|
|
|
|
blockTrackerStub.getCurrentBlock = noop;
|
|
|
|
blockTrackerStub.getLatestBlock = noop;
|
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
|
|
|
|
|
|
|
getCurrentChainId = sinon.stub().callsFake(() => currentChainId);
|
|
|
|
|
2017-05-16 19:27:41 +02:00
|
|
|
txController = new TransactionController({
|
2017-08-09 00:30:22 +02:00
|
|
|
provider,
|
2020-11-03 00:41:28 +01:00
|
|
|
getGasPrice() {
|
2021-02-04 19:15:23 +01:00
|
|
|
return '0xee6b2800';
|
2019-11-20 01:03:20 +01:00
|
|
|
},
|
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
|
|
|
getNetworkId: () => currentNetworkId,
|
|
|
|
getNetworkStatus: () => networkStatusStore.getState(),
|
|
|
|
onNetworkStateChange: (listener) =>
|
|
|
|
networkStatusStore.subscribe(listener),
|
2021-07-31 02:45:18 +02:00
|
|
|
getCurrentNetworkEIP1559Compatibility: () => Promise.resolve(false),
|
|
|
|
getCurrentAccountEIP1559Compatibility: () => false,
|
2016-12-16 19:33:36 +01:00
|
|
|
txHistoryLimit: 10,
|
2018-05-28 23:29:31 +02:00
|
|
|
blockTracker: blockTrackerStub,
|
2020-11-03 00:41:28 +01:00
|
|
|
signTransaction: (ethTx) =>
|
|
|
|
new Promise((resolve) => {
|
2021-06-16 22:40:17 +02:00
|
|
|
resolve(ethTx.sign(fromAccount.key));
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
2021-06-16 22:40:17 +02:00
|
|
|
getProviderConfig: () => providerConfig,
|
2020-08-14 13:47:02 +02:00
|
|
|
getPermittedAccounts: () => undefined,
|
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
|
|
|
getCurrentChainId,
|
2020-10-08 18:41:23 +02:00
|
|
|
getParticipateInMetrics: () => false,
|
2021-06-21 21:02:43 +02:00
|
|
|
trackMetaMetricsEvent: () => undefined,
|
2022-01-20 17:26:39 +01:00
|
|
|
createEventFragment: () => undefined,
|
|
|
|
updateEventFragment: () => undefined,
|
|
|
|
finalizeEventFragment: () => undefined,
|
|
|
|
getEventFragmentById: () =>
|
|
|
|
fragmentExists === false ? undefined : { id: 0 },
|
2021-07-31 02:45:18 +02:00
|
|
|
getEIP1559GasFeeEstimates: () => undefined,
|
2022-02-23 16:15:41 +01:00
|
|
|
getAccountType: () => 'MetaMask',
|
|
|
|
getDeviceModel: () => 'N/A',
|
2023-01-23 15:32:01 +01:00
|
|
|
securityProviderRequest: () => undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
txController.nonceTracker.getNonceLock = () =>
|
2021-02-04 19:15:23 +01:00
|
|
|
Promise.resolve({ nextNonce: 0, releaseLock: noop });
|
|
|
|
});
|
2017-07-26 20:56:52 +02:00
|
|
|
|
2017-09-08 23:24:40 +02:00
|
|
|
describe('#getState', function () {
|
2020-04-20 17:01:00 +02:00
|
|
|
it('should return a state object with the right keys and data types', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const exposedState = txController.getState();
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
'unapprovedTxs' in exposedState,
|
|
|
|
'state should have the key unapprovedTxs',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
'currentNetworkTxList' in exposedState,
|
|
|
|
'state should have the key currentNetworkTxList',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
typeof exposedState?.unapprovedTxs === 'object',
|
|
|
|
'should be an object',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
Array.isArray(exposedState.currentNetworkTxList),
|
|
|
|
'should be an array',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-09-08 23:24:40 +02:00
|
|
|
|
|
|
|
describe('#getUnapprovedTxCount', function () {
|
|
|
|
it('should return the number of unapproved txs', function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
const unapprovedTxCount = txController.getUnapprovedTxCount();
|
|
|
|
assert.equal(unapprovedTxCount, 3, 'should be 3');
|
|
|
|
});
|
|
|
|
});
|
2017-09-08 23:24:40 +02:00
|
|
|
|
2017-09-13 23:07:22 +02:00
|
|
|
describe('#getPendingTxCount', function () {
|
|
|
|
it('should return the number of pending txs', function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
const pendingTxCount = txController.getPendingTxCount();
|
|
|
|
assert.equal(pendingTxCount, 3, 'should be 3');
|
|
|
|
});
|
|
|
|
});
|
2017-09-13 23:07:22 +02:00
|
|
|
|
2017-09-23 01:15:18 +02:00
|
|
|
describe('#getConfirmedTransactions', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the number of confirmed txs', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const address = '0xc684832530fcbddae4b4230a47e991ddcec2831d';
|
2017-09-23 01:15:18 +02:00
|
|
|
const txParams = {
|
2020-11-03 00:41:28 +01:00
|
|
|
from: address,
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 0,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.confirmed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.confirmed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.confirmed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.rejected,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.approved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 6,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.signed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 7,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 8,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.failed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
txController.nonceTracker.getConfirmedTransactions(address).length,
|
|
|
|
3,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
2017-08-03 00:58:05 +02:00
|
|
|
describe('#newUnapprovedTransaction', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let stub, txMeta, txParams;
|
2017-08-03 00:58:05 +02:00
|
|
|
beforeEach(function () {
|
|
|
|
txParams = {
|
2020-11-03 00:41:28 +01:00
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-08-03 00:58:05 +02:00
|
|
|
txMeta = {
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2017-08-03 00:58:05 +02:00
|
|
|
id: 1,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
2018-11-16 19:34:08 +01:00
|
|
|
history: [{}],
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([txMeta]);
|
2020-11-03 00:41:28 +01:00
|
|
|
stub = sinon
|
|
|
|
.stub(txController, 'addUnapprovedTransaction')
|
|
|
|
.callsFake(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txController.emit('newUnapprovedTx', txMeta);
|
2021-03-30 16:54:05 +02:00
|
|
|
return Promise.resolve(
|
|
|
|
txController.txStateManager.addTransaction(txMeta),
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2017-08-03 00:58:05 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([]);
|
2021-02-04 19:15:23 +01:00
|
|
|
stub.restore();
|
|
|
|
});
|
2017-08-03 00:58:05 +02:00
|
|
|
|
2020-04-20 17:01:00 +02:00
|
|
|
it('should resolve when finished and status is submitted and resolve with the hash', async function () {
|
2017-11-06 13:35:51 +01:00
|
|
|
txController.once('newUnapprovedTx', (txMetaFromEmit) => {
|
2017-08-03 00:58:05 +02:00
|
|
|
setTimeout(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txController.setTxHash(txMetaFromEmit.id, '0x0');
|
|
|
|
txController.txStateManager.setTxStatusSubmitted(txMetaFromEmit.id);
|
|
|
|
});
|
|
|
|
});
|
2017-08-03 00:58:05 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const hash = await txController.newUnapprovedTransaction(txParams);
|
|
|
|
assert.ok(hash, 'newUnapprovedTransaction needs to return the hash');
|
|
|
|
});
|
2017-08-03 00:58:05 +02:00
|
|
|
|
2020-04-20 17:01:00 +02:00
|
|
|
it('should reject when finished and status is rejected', async function () {
|
2017-11-06 13:35:51 +01:00
|
|
|
txController.once('newUnapprovedTx', (txMetaFromEmit) => {
|
2017-08-03 00:58:05 +02:00
|
|
|
setTimeout(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txController.txStateManager.setTxStatusRejected(txMetaFromEmit.id);
|
|
|
|
});
|
|
|
|
});
|
2017-08-03 00:58:05 +02:00
|
|
|
|
2020-04-20 17:01:00 +02:00
|
|
|
await assert.rejects(
|
|
|
|
() => txController.newUnapprovedTransaction(txParams),
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
message: 'MetaMask Tx Signature: User denied transaction signature.',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-08-03 00:58:05 +02:00
|
|
|
|
2017-07-26 20:56:52 +02:00
|
|
|
describe('#addUnapprovedTransaction', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const selectedAddress = '0x1678a085c290ebd122dc42cba69373b5953b831d';
|
|
|
|
const recipientAddress = '0xc42edfcc21ed14dda456aa0756c153f7985d8813';
|
2018-10-10 20:41:17 +02:00
|
|
|
|
2022-09-06 11:08:32 +02:00
|
|
|
let getSelectedAddress, getPermittedAccounts, getDefaultGasFees;
|
2018-10-10 20:41:17 +02:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
getSelectedAddress = sinon
|
|
|
|
.stub(txController, 'getSelectedAddress')
|
2021-02-04 19:15:23 +01:00
|
|
|
.returns(selectedAddress);
|
2022-09-06 11:08:32 +02:00
|
|
|
getDefaultGasFees = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.returns({});
|
2020-11-03 00:41:28 +01:00
|
|
|
getPermittedAccounts = sinon
|
|
|
|
.stub(txController, 'getPermittedAccounts')
|
2021-02-04 19:15:23 +01:00
|
|
|
.returns([selectedAddress]);
|
|
|
|
});
|
2018-10-10 20:41:17 +02:00
|
|
|
|
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
getSelectedAddress.restore();
|
|
|
|
getPermittedAccounts.restore();
|
2022-09-06 11:08:32 +02:00
|
|
|
getDefaultGasFees.restore();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-01-14 23:01:37 +01:00
|
|
|
|
2020-04-20 17:01:00 +02:00
|
|
|
it('should add an unapproved transaction and return a valid txMeta', async function () {
|
2023-01-23 15:32:01 +01:00
|
|
|
const txMeta = await txController.addUnapprovedTransaction(undefined, {
|
2020-11-03 00:41:28 +01:00
|
|
|
from: selectedAddress,
|
2020-12-04 03:15:59 +01:00
|
|
|
to: recipientAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.ok('id' in txMeta, 'should have a id');
|
|
|
|
assert.ok('time' in txMeta, 'should have a time stamp');
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
'metamaskNetworkId' in txMeta,
|
|
|
|
'should have a metamaskNetworkId',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok('txParams' in txMeta, 'should have a txParams');
|
|
|
|
assert.ok('history' in txMeta, 'should have a history');
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
txMeta.txParams.value,
|
|
|
|
'0x0',
|
|
|
|
'should have added 0x0 as the value',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-04-20 17:01:00 +02:00
|
|
|
|
2021-03-30 16:54:05 +02:00
|
|
|
const memTxMeta = txController.txStateManager.getTransaction(txMeta.id);
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepEqual(txMeta, memTxMeta);
|
|
|
|
});
|
2018-01-14 23:01:37 +01:00
|
|
|
|
2022-09-06 11:08:32 +02:00
|
|
|
it('should add only 1 unapproved transaction when called twice with same actionId', async function () {
|
|
|
|
await txController.addUnapprovedTransaction(
|
2023-01-23 15:32:01 +01:00
|
|
|
undefined,
|
2022-09-06 11:08:32 +02:00
|
|
|
{
|
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
'12345',
|
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.addUnapprovedTransaction(
|
2023-01-23 15:32:01 +01:00
|
|
|
undefined,
|
2022-09-06 11:08:32 +02:00
|
|
|
{
|
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
'12345',
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1, transactionCount2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add multiple transactions when called with different actionId', async function () {
|
|
|
|
await txController.addUnapprovedTransaction(
|
2023-01-23 15:32:01 +01:00
|
|
|
undefined,
|
2022-09-06 11:08:32 +02:00
|
|
|
{
|
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
'12345',
|
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.addUnapprovedTransaction(
|
2023-01-23 15:32:01 +01:00
|
|
|
undefined,
|
2022-09-06 11:08:32 +02:00
|
|
|
{
|
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
'00000',
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1 + 1, transactionCount2);
|
|
|
|
});
|
|
|
|
|
2018-01-14 23:01:37 +01:00
|
|
|
it('should emit newUnapprovedTx event and pass txMeta as the first argument', function (done) {
|
2021-02-04 19:15:23 +01:00
|
|
|
providerResultStub.eth_gasPrice = '4a817c800';
|
2018-01-14 23:01:37 +01:00
|
|
|
txController.once('newUnapprovedTx', (txMetaFromEmit) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(txMetaFromEmit, 'txMeta is falsy');
|
|
|
|
done();
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
txController
|
2023-01-23 15:32:01 +01:00
|
|
|
.addUnapprovedTransaction(undefined, {
|
2020-12-04 03:15:59 +01:00
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
2018-01-14 23:01:37 +01:00
|
|
|
|
2020-04-20 17:01:00 +02:00
|
|
|
it("should fail if the from address isn't the selected address", async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
await assert.rejects(() =>
|
|
|
|
txController.addUnapprovedTransaction({
|
|
|
|
from: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2',
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-10-10 20:41:17 +02:00
|
|
|
|
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
|
|
|
it('should fail if the network status is not "available"', async function () {
|
|
|
|
networkStatusStore.putState(NetworkStatus.Unknown);
|
2020-04-20 17:01:00 +02:00
|
|
|
await assert.rejects(
|
2020-11-03 00:41:28 +01:00
|
|
|
() =>
|
2023-01-23 15:32:01 +01:00
|
|
|
txController.addUnapprovedTransaction(undefined, {
|
2020-11-03 00:41:28 +01:00
|
|
|
from: selectedAddress,
|
|
|
|
to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2',
|
|
|
|
}),
|
2020-04-20 17:01:00 +02:00
|
|
|
{ message: 'MetaMask is having trouble connecting to the network' },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2016-12-14 21:56:53 +01:00
|
|
|
|
2022-09-09 13:50:31 +02:00
|
|
|
describe('#createCancelTransaction', function () {
|
|
|
|
const selectedAddress = '0x1678a085c290ebd122dc42cba69373b5953b831d';
|
|
|
|
const recipientAddress = '0xc42edfcc21ed14dda456aa0756c153f7985d8813';
|
|
|
|
|
|
|
|
let getSelectedAddress,
|
|
|
|
getPermittedAccounts,
|
|
|
|
getDefaultGasFees,
|
|
|
|
getDefaultGasLimit;
|
|
|
|
beforeEach(function () {
|
|
|
|
const hash =
|
|
|
|
'0x2a5523c6fa98b47b7d9b6c8320179785150b42a16bcff36b398c5062b65657e8';
|
|
|
|
providerResultStub.eth_sendRawTransaction = hash;
|
|
|
|
|
|
|
|
getSelectedAddress = sinon
|
|
|
|
.stub(txController, 'getSelectedAddress')
|
|
|
|
.returns(selectedAddress);
|
|
|
|
getDefaultGasFees = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.returns({});
|
|
|
|
getDefaultGasLimit = sinon
|
|
|
|
.stub(txController, '_getDefaultGasLimit')
|
|
|
|
.returns({});
|
|
|
|
getPermittedAccounts = sinon
|
|
|
|
.stub(txController, 'getPermittedAccounts')
|
|
|
|
.returns([selectedAddress]);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
getSelectedAddress.restore();
|
|
|
|
getPermittedAccounts.restore();
|
|
|
|
getDefaultGasFees.restore();
|
|
|
|
getDefaultGasLimit.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add an cancel transaction and return a valid txMeta', async function () {
|
2023-01-23 15:32:01 +01:00
|
|
|
const txMeta = await txController.addUnapprovedTransaction(undefined, {
|
2022-09-09 13:50:31 +02:00
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
});
|
|
|
|
await txController.approveTransaction(txMeta.id);
|
|
|
|
const cancelTxMeta = await txController.createCancelTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(cancelTxMeta.type, TransactionType.cancel);
|
2022-09-09 13:50:31 +02:00
|
|
|
const memTxMeta = txController.txStateManager.getTransaction(
|
|
|
|
cancelTxMeta.id,
|
|
|
|
);
|
|
|
|
assert.deepEqual(cancelTxMeta, memTxMeta);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add only 1 cancel transaction when called twice with same actionId', async function () {
|
2023-01-23 15:32:01 +01:00
|
|
|
const txMeta = await txController.addUnapprovedTransaction(undefined, {
|
2022-09-09 13:50:31 +02:00
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
});
|
|
|
|
await txController.approveTransaction(txMeta.id);
|
|
|
|
await txController.createCancelTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.createCancelTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1, transactionCount2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add multiple transactions when called with different actionId', async function () {
|
2023-01-23 15:32:01 +01:00
|
|
|
const txMeta = await txController.addUnapprovedTransaction(undefined, {
|
2022-09-09 13:50:31 +02:00
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
});
|
|
|
|
await txController.approveTransaction(txMeta.id);
|
|
|
|
await txController.createCancelTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
2022-09-16 19:04:14 +02:00
|
|
|
{ actionId: 12345 },
|
2022-09-09 13:50:31 +02:00
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.createCancelTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 11111 },
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1 + 1, transactionCount2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-13 21:38:07 +02:00
|
|
|
describe('#addTxGasDefaults', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should add the tx defaults if their are none', async function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2017-09-23 01:15:18 +02:00
|
|
|
const txMeta = {
|
2020-05-01 17:25:45 +02:00
|
|
|
id: 1,
|
2018-05-25 07:41:09 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
2017-08-02 17:34:45 +02:00
|
|
|
},
|
2018-11-16 19:34:08 +01:00
|
|
|
history: [{}],
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
providerResultStub.eth_gasPrice = '4a817c800';
|
|
|
|
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
|
|
|
|
providerResultStub.eth_estimateGas = '5209';
|
2018-05-25 07:41:09 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
txMetaWithDefaults.txParams.gasPrice,
|
|
|
|
'should have added the gas price',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
txMetaWithDefaults.txParams.gas,
|
|
|
|
'should have added the gas field',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2021-07-31 02:45:18 +02:00
|
|
|
|
|
|
|
it('should add EIP1559 tx defaults', async function () {
|
|
|
|
const TEST_MAX_FEE_PER_GAS = '0x12a05f200';
|
|
|
|
const TEST_MAX_PRIORITY_FEE_PER_GAS = '0x77359400';
|
|
|
|
|
|
|
|
const stub1 = sinon
|
|
|
|
.stub(txController, 'getEIP1559Compatibility')
|
|
|
|
.returns(true);
|
|
|
|
|
|
|
|
const stub2 = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.callsFake(() => ({
|
|
|
|
maxFeePerGas: TEST_MAX_FEE_PER_GAS,
|
|
|
|
maxPriorityFeePerGas: TEST_MAX_PRIORITY_FEE_PER_GAS,
|
|
|
|
}));
|
|
|
|
|
|
|
|
txController.txStateManager._addTransactionsToState([
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-07-31 02:45:18 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
};
|
|
|
|
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
|
|
|
|
providerResultStub.eth_estimateGas = '5209';
|
|
|
|
|
|
|
|
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxFeePerGas,
|
|
|
|
TEST_MAX_FEE_PER_GAS,
|
|
|
|
'should have added the correct max fee per gas',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxPriorityFeePerGas,
|
|
|
|
TEST_MAX_PRIORITY_FEE_PER_GAS,
|
|
|
|
'should have added the correct max priority fee per gas',
|
|
|
|
);
|
|
|
|
stub1.restore();
|
|
|
|
stub2.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add gasPrice as maxFeePerGas and maxPriorityFeePerGas if there are no sources of other fee data available', async function () {
|
|
|
|
const TEST_GASPRICE = '0x12a05f200';
|
|
|
|
|
|
|
|
const stub1 = sinon
|
|
|
|
.stub(txController, 'getEIP1559Compatibility')
|
|
|
|
.returns(true);
|
|
|
|
|
|
|
|
const stub2 = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.callsFake(() => ({ gasPrice: TEST_GASPRICE }));
|
|
|
|
|
|
|
|
txController.txStateManager._addTransactionsToState([
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-07-31 02:45:18 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
};
|
|
|
|
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
|
|
|
|
providerResultStub.eth_estimateGas = '5209';
|
|
|
|
|
|
|
|
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxFeePerGas,
|
|
|
|
TEST_GASPRICE,
|
|
|
|
'should have added the correct max fee per gas',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxPriorityFeePerGas,
|
|
|
|
TEST_GASPRICE,
|
|
|
|
'should have added the correct max priority fee per gas',
|
|
|
|
);
|
|
|
|
stub1.restore();
|
|
|
|
stub2.restore();
|
|
|
|
});
|
|
|
|
|
2021-10-06 20:29:57 +02:00
|
|
|
it('should not add maxFeePerGas and maxPriorityFeePerGas to type-0 transactions', async function () {
|
|
|
|
const TEST_GASPRICE = '0x12a05f200';
|
|
|
|
|
|
|
|
const stub1 = sinon
|
|
|
|
.stub(txController, 'getEIP1559Compatibility')
|
|
|
|
.returns(true);
|
|
|
|
|
|
|
|
const stub2 = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.callsFake(() => ({ gasPrice: TEST_GASPRICE }));
|
|
|
|
|
|
|
|
txController.txStateManager._addTransactionsToState([
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-10-06 20:29:57 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.legacy,
|
2021-10-06 20:29:57 +02:00
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.legacy,
|
2021-10-06 20:29:57 +02:00
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
};
|
|
|
|
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
|
|
|
|
providerResultStub.eth_estimateGas = '5209';
|
|
|
|
|
|
|
|
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxFeePerGas,
|
|
|
|
undefined,
|
|
|
|
'should not have maxFeePerGas',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxPriorityFeePerGas,
|
|
|
|
undefined,
|
|
|
|
'should not have max priority fee per gas',
|
|
|
|
);
|
|
|
|
stub1.restore();
|
|
|
|
stub2.restore();
|
|
|
|
});
|
|
|
|
|
2021-07-31 02:45:18 +02:00
|
|
|
it('should not add gasPrice if the fee data is available from the dapp', async function () {
|
|
|
|
const TEST_GASPRICE = '0x12a05f200';
|
|
|
|
const TEST_MAX_FEE_PER_GAS = '0x12a05f200';
|
|
|
|
const TEST_MAX_PRIORITY_FEE_PER_GAS = '0x77359400';
|
|
|
|
|
|
|
|
const stub1 = sinon
|
|
|
|
.stub(txController, 'getEIP1559Compatibility')
|
|
|
|
.returns(true);
|
|
|
|
|
|
|
|
const stub2 = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.callsFake(() => ({ gasPrice: TEST_GASPRICE }));
|
|
|
|
|
|
|
|
txController.txStateManager._addTransactionsToState([
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-07-31 02:45:18 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
maxFeePerGas: TEST_MAX_FEE_PER_GAS,
|
|
|
|
maxPriorityFeePerGas: TEST_MAX_PRIORITY_FEE_PER_GAS,
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
};
|
|
|
|
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
|
|
|
|
providerResultStub.eth_estimateGas = '5209';
|
|
|
|
|
|
|
|
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxFeePerGas,
|
|
|
|
TEST_MAX_FEE_PER_GAS,
|
|
|
|
'should have added the correct max fee per gas',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
txMetaWithDefaults.txParams.maxPriorityFeePerGas,
|
|
|
|
TEST_MAX_PRIORITY_FEE_PER_GAS,
|
|
|
|
'should have added the correct max priority fee per gas',
|
|
|
|
);
|
|
|
|
stub1.restore();
|
|
|
|
stub2.restore();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_getDefaultGasFees', function () {
|
|
|
|
let getGasFeeStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
getGasFeeStub = sinon.stub(txController, '_getEIP1559GasFeeEstimates');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
getGasFeeStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the correct fee data when the gas estimate type is FEE_MARKET', async function () {
|
|
|
|
const EXPECTED_MAX_FEE_PER_GAS = '12a05f200';
|
|
|
|
const EXPECTED_MAX_PRIORITY_FEE_PER_GAS = '77359400';
|
|
|
|
|
|
|
|
getGasFeeStub.callsFake(() => ({
|
|
|
|
gasFeeEstimates: {
|
|
|
|
medium: {
|
|
|
|
suggestedMaxPriorityFeePerGas: '2',
|
|
|
|
suggestedMaxFeePerGas: '5',
|
|
|
|
},
|
|
|
|
},
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.feeMarket,
|
2021-07-31 02:45:18 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
const defaultGasFees = await txController._getDefaultGasFees(
|
|
|
|
{ txParams: {} },
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(defaultGasFees, {
|
|
|
|
maxPriorityFeePerGas: EXPECTED_MAX_PRIORITY_FEE_PER_GAS,
|
|
|
|
maxFeePerGas: EXPECTED_MAX_FEE_PER_GAS,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the correct fee data when the gas estimate type is LEGACY', async function () {
|
|
|
|
const EXPECTED_GAS_PRICE = '77359400';
|
|
|
|
|
|
|
|
getGasFeeStub.callsFake(() => ({
|
|
|
|
gasFeeEstimates: { medium: '2' },
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-31 02:45:18 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
const defaultGasFees = await txController._getDefaultGasFees(
|
|
|
|
{ txParams: {} },
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(defaultGasFees, {
|
|
|
|
gasPrice: EXPECTED_GAS_PRICE,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the correct fee data when the gas estimate type is ETH_GASPRICE', async function () {
|
|
|
|
const EXPECTED_GAS_PRICE = '77359400';
|
|
|
|
|
|
|
|
getGasFeeStub.callsFake(() => ({
|
|
|
|
gasFeeEstimates: { gasPrice: '2' },
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.ethGasPrice,
|
2021-07-31 02:45:18 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
const defaultGasFees = await txController._getDefaultGasFees(
|
|
|
|
{ txParams: {} },
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(defaultGasFees, {
|
|
|
|
gasPrice: EXPECTED_GAS_PRICE,
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2017-08-02 17:34:45 +02:00
|
|
|
|
2021-03-30 16:54:05 +02:00
|
|
|
describe('#addTransaction', function () {
|
2021-06-24 21:00:54 +02:00
|
|
|
let trackTransactionMetricsEventSpy;
|
2021-06-21 21:02:43 +02:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2021-06-24 21:00:54 +02:00
|
|
|
trackTransactionMetricsEventSpy = sinon.spy(
|
2021-06-21 21:02:43 +02:00
|
|
|
txController,
|
2021-06-24 21:00:54 +02:00
|
|
|
'_trackTransactionMetricsEvent',
|
2021-06-21 21:02:43 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2021-06-24 21:00:54 +02:00
|
|
|
trackTransactionMetricsEventSpy.restore();
|
2021-06-21 21:02:43 +02:00
|
|
|
});
|
|
|
|
|
2017-08-11 23:19:35 +02:00
|
|
|
it('should emit updates', function (done) {
|
2017-05-16 22:22:03 +02:00
|
|
|
const txMeta = {
|
|
|
|
id: '1',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2017-05-16 22:22:03 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-05-16 22:22:03 +02:00
|
|
|
|
2021-02-09 00:22:30 +01:00
|
|
|
const eventNames = [
|
|
|
|
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
|
|
|
|
'1:unapproved',
|
|
|
|
];
|
2021-02-04 19:15:23 +01:00
|
|
|
const listeners = [];
|
2017-08-11 23:19:35 +02:00
|
|
|
eventNames.forEach((eventName) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
listeners.push(
|
|
|
|
new Promise((resolve) => {
|
|
|
|
txController.once(eventName, (arg) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(arg);
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2017-08-11 23:19:35 +02:00
|
|
|
Promise.all(listeners)
|
2019-07-31 22:17:11 +02:00
|
|
|
.then((returnValues) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
returnValues.pop(),
|
|
|
|
txMeta,
|
|
|
|
'last event 1:unapproved should return txMeta',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
done();
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.addTransaction(txMeta);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-06-21 21:02:43 +02:00
|
|
|
|
2021-06-24 21:00:54 +02:00
|
|
|
it('should call _trackTransactionMetricsEvent with the correct params', function () {
|
2021-06-21 21:02:43 +02:00
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-06-21 21:02:43 +02:00
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2021-11-10 20:50:43 +01:00
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
2022-04-26 19:07:39 +02:00
|
|
|
origin: ORIGIN_METAMASK,
|
2021-06-21 21:02:43 +02:00
|
|
|
chainId: currentChainId,
|
2021-06-24 21:00:54 +02:00
|
|
|
time: 1624408066355,
|
2021-06-21 21:02:43 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
};
|
|
|
|
|
|
|
|
txController.addTransaction(txMeta);
|
|
|
|
|
2021-06-24 21:00:54 +02:00
|
|
|
assert.equal(trackTransactionMetricsEventSpy.callCount, 1);
|
2021-06-21 21:02:43 +02:00
|
|
|
assert.deepEqual(
|
2021-06-24 21:00:54 +02:00
|
|
|
trackTransactionMetricsEventSpy.getCall(0).args[0],
|
|
|
|
txMeta,
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
trackTransactionMetricsEventSpy.getCall(0).args[1],
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.added,
|
2021-06-21 21:02:43 +02:00
|
|
|
);
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-12-14 21:56:53 +01:00
|
|
|
|
2017-05-17 03:16:18 +02:00
|
|
|
describe('#approveTransaction', function () {
|
2020-04-20 17:01:00 +02:00
|
|
|
it('does not overwrite set values', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const originalValue = '0x01';
|
2020-02-11 17:51:13 +01:00
|
|
|
const txMeta = {
|
2017-05-17 03:16:18 +02:00
|
|
|
id: '1',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2017-05-17 03:16:18 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
2021-03-30 16:54:05 +02:00
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
2017-05-17 03:16:18 +02:00
|
|
|
nonce: originalValue,
|
|
|
|
gas: originalValue,
|
|
|
|
gasPrice: originalValue,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-03-09 20:08:06 +01:00
|
|
|
// eslint-disable-next-line @babel/no-invalid-this
|
2021-06-10 21:27:03 +02:00
|
|
|
this.timeout(SECOND * 15);
|
2021-02-04 19:15:23 +01:00
|
|
|
const wrongValue = '0x05';
|
2017-05-17 03:16:18 +02:00
|
|
|
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.addTransaction(txMeta);
|
2021-02-04 19:15:23 +01:00
|
|
|
providerResultStub.eth_gasPrice = wrongValue;
|
|
|
|
providerResultStub.eth_estimateGas = '0x5209';
|
2017-05-17 03:16:18 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const signStub = sinon
|
|
|
|
.stub(txController, 'signTransaction')
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake(() => Promise.resolve());
|
2017-05-17 03:16:18 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const pubStub = sinon
|
|
|
|
.stub(txController, 'publishTransaction')
|
|
|
|
.callsFake(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
txController.setTxHash('1', originalValue);
|
|
|
|
txController.txStateManager.setTxStatusSubmitted('1');
|
|
|
|
});
|
2017-05-17 03:16:18 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await txController.approveTransaction(txMeta.id);
|
2021-03-30 16:54:05 +02:00
|
|
|
const result = txController.txStateManager.getTransaction(txMeta.id);
|
2021-02-04 19:15:23 +01:00
|
|
|
const params = result.txParams;
|
2017-05-17 03:16:18 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(params.gas, originalValue, 'gas unmodified');
|
|
|
|
assert.equal(params.gasPrice, originalValue, 'gas price unmodified');
|
|
|
|
assert.equal(result.hash, originalValue);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
result.status,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
'should have reached the submitted status.',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
signStub.restore();
|
|
|
|
pubStub.restore();
|
|
|
|
});
|
|
|
|
});
|
2017-05-17 03:16:18 +02:00
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
describe('#sign replay-protected tx', function () {
|
2020-04-20 17:01:00 +02:00
|
|
|
it('prepares a tx with the chainId set', async function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.addTransaction(
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: '1',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
noop,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const rawTx = await txController.signTransaction('1');
|
2021-06-16 22:40:17 +02:00
|
|
|
const ethTx = TransactionFactory.fromSerializedData(toBuffer(rawTx));
|
2022-09-29 05:26:01 +02:00
|
|
|
assert.equal(ethTx.common.chainIdBN().toNumber(), 5);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
2017-09-26 04:47:03 +02:00
|
|
|
describe('#updateAndApproveTransaction', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should update and approve transactions', async function () {
|
|
|
|
const txMeta = {
|
2017-09-26 04:47:03 +02:00
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2017-09-26 04:47:03 +02:00
|
|
|
txParams: {
|
2018-04-28 02:12:52 +02:00
|
|
|
from: fromAccount.address,
|
2017-09-26 04:47:03 +02:00
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager.addTransaction(txMeta);
|
2021-02-04 19:15:23 +01:00
|
|
|
const approvalPromise = txController.updateAndApproveTransaction(txMeta);
|
2021-03-30 16:54:05 +02:00
|
|
|
const tx = txController.txStateManager.getTransaction(1);
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(tx.status, TransactionStatus.approved);
|
2021-02-04 19:15:23 +01:00
|
|
|
await approvalPromise;
|
|
|
|
});
|
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
2017-09-26 04:47:03 +02:00
|
|
|
describe('#getChainId', function () {
|
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
|
|
|
it('returns the chain ID of the network when it is available', function () {
|
|
|
|
networkStatusStore.putState(NetworkStatus.Available);
|
|
|
|
assert.equal(txController.getChainId(), 5);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns 0 when the network is not available', function () {
|
|
|
|
networkStatusStore.putState('asdflsfadf');
|
|
|
|
assert.equal(txController.getChainId(), 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns 0 when the chain ID cannot be parsed as a hex string', function () {
|
|
|
|
networkStatusStore.putState(NetworkStatus.Available);
|
|
|
|
getCurrentChainId.returns('$fdsjfldf');
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(txController.getChainId(), 0);
|
|
|
|
});
|
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
|
|
|
describe('#cancelTransaction', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should emit a status change to rejected', function (done) {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 0,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.rejected,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.approved,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.signed,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.confirmed,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 6,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.failed,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2017-09-23 01:15:18 +02:00
|
|
|
|
2018-06-26 01:16:51 +02:00
|
|
|
txController.once('tx:status-update', (txId, status) => {
|
|
|
|
try {
|
2020-11-07 08:38:12 +01:00
|
|
|
assert.equal(
|
|
|
|
status,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionStatus.rejected,
|
2020-11-07 08:38:12 +01:00
|
|
|
'status should be rejected',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(txId, 0, 'id should e 0');
|
|
|
|
done();
|
2019-11-20 01:03:20 +01:00
|
|
|
} catch (e) {
|
2021-02-04 19:15:23 +01:00
|
|
|
done(e);
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-06-26 01:16:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
txController.cancelTransaction(0);
|
|
|
|
});
|
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('#createSpeedUpTransaction', function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
let addTransactionSpy;
|
2021-02-04 19:15:23 +01:00
|
|
|
let approveTransactionSpy;
|
|
|
|
let txParams;
|
|
|
|
let expectedTxParams;
|
2022-09-13 14:43:38 +02:00
|
|
|
const selectedAddress = '0x1678a085c290ebd122dc42cba69373b5953b831d';
|
|
|
|
const recipientAddress = '0xc42edfcc21ed14dda456aa0756c153f7985d8813';
|
|
|
|
|
|
|
|
let getSelectedAddress,
|
|
|
|
getPermittedAccounts,
|
|
|
|
getDefaultGasFees,
|
|
|
|
getDefaultGasLimit;
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
addTransactionSpy = sinon.spy(txController, 'addTransaction');
|
2021-02-04 19:15:23 +01:00
|
|
|
approveTransactionSpy = sinon.spy(txController, 'approveTransaction');
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2022-09-13 14:43:38 +02:00
|
|
|
const hash =
|
|
|
|
'0x2a5523c6fa98b47b7d9b6c8320179785150b42a16bcff36b398c5062b65657e8';
|
|
|
|
providerResultStub.eth_sendRawTransaction = hash;
|
|
|
|
|
|
|
|
getSelectedAddress = sinon
|
|
|
|
.stub(txController, 'getSelectedAddress')
|
|
|
|
.returns(selectedAddress);
|
|
|
|
getDefaultGasFees = sinon
|
|
|
|
.stub(txController, '_getDefaultGasFees')
|
|
|
|
.returns({});
|
|
|
|
getDefaultGasLimit = sinon
|
|
|
|
.stub(txController, '_getDefaultGasLimit')
|
|
|
|
.returns({});
|
|
|
|
getPermittedAccounts = sinon
|
|
|
|
.stub(txController, 'getPermittedAccounts')
|
|
|
|
.returns([selectedAddress]);
|
|
|
|
|
2018-10-26 06:42:59 +02:00
|
|
|
txParams = {
|
|
|
|
nonce: '0x00',
|
|
|
|
from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
|
|
|
to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
|
|
|
gas: '0x5209',
|
|
|
|
gasPrice: '0xa',
|
2023-01-27 19:28:03 +01:00
|
|
|
estimateSuggested: GasRecommendations.medium,
|
|
|
|
estimateUsed: GasRecommendations.high,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams,
|
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
expectedTxParams = { ...txParams, gasPrice: '0xb' };
|
|
|
|
});
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
addTransactionSpy.restore();
|
2021-02-04 19:15:23 +01:00
|
|
|
approveTransactionSpy.restore();
|
2022-09-13 14:43:38 +02:00
|
|
|
getSelectedAddress.restore();
|
|
|
|
getPermittedAccounts.restore();
|
|
|
|
getDefaultGasFees.restore();
|
|
|
|
getDefaultGasLimit.restore();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-03-30 16:54:05 +02:00
|
|
|
it('should call this.addTransaction and this.approveTransaction with the expected args', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
await txController.createSpeedUpTransaction(1);
|
2021-03-30 16:54:05 +02:00
|
|
|
assert.equal(addTransactionSpy.callCount, 1);
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-03-30 16:54:05 +02:00
|
|
|
const addTransactionArgs = addTransactionSpy.getCall(0).args[0];
|
|
|
|
assert.deepEqual(addTransactionArgs.txParams, expectedTxParams);
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-07-08 20:48:23 +02:00
|
|
|
const { previousGasParams, type } = addTransactionArgs;
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(
|
2021-07-08 20:48:23 +02:00
|
|
|
{ gasPrice: previousGasParams.gasPrice, type },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
2021-07-08 20:48:23 +02:00
|
|
|
gasPrice: '0xa',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.retry,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call this.approveTransaction with the id of the returned tx', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = await txController.createSpeedUpTransaction(1);
|
|
|
|
assert.equal(approveTransactionSpy.callCount, 1);
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const approveTransactionArg = approveTransactionSpy.getCall(0).args[0];
|
|
|
|
assert.equal(result.id, approveTransactionArg);
|
|
|
|
});
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the expected txMeta', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = await txController.createSpeedUpTransaction(1);
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.deepEqual(result.txParams, expectedTxParams);
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-07-08 20:48:23 +02:00
|
|
|
const { previousGasParams, type } = result;
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.deepEqual(
|
2021-07-08 20:48:23 +02:00
|
|
|
{ gasPrice: previousGasParams.gasPrice, type },
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
2021-07-08 20:48:23 +02:00
|
|
|
gasPrice: '0xa',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.retry,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2022-09-13 14:43:38 +02:00
|
|
|
|
|
|
|
it('should add only 1 speedup transaction when called twice with same actionId', async function () {
|
2023-01-23 15:32:01 +01:00
|
|
|
const txMeta = await txController.addUnapprovedTransaction(undefined, {
|
2022-09-13 14:43:38 +02:00
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
});
|
|
|
|
await txController.approveTransaction(txMeta.id);
|
|
|
|
await txController.createSpeedUpTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.createSpeedUpTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1, transactionCount2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add multiple transactions when called with different actionId', async function () {
|
2023-01-23 15:32:01 +01:00
|
|
|
const txMeta = await txController.addUnapprovedTransaction(undefined, {
|
2022-09-13 14:43:38 +02:00
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
});
|
|
|
|
await txController.approveTransaction(txMeta.id);
|
|
|
|
await txController.createSpeedUpTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.createSpeedUpTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 11111 },
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1 + 1, transactionCount2);
|
|
|
|
});
|
2023-01-23 15:32:01 +01:00
|
|
|
|
|
|
|
it('should add multiple transactions when called with different actionId and txMethodType defined', async function () {
|
|
|
|
const txMeta = await txController.addUnapprovedTransaction(
|
|
|
|
'eth_sendTransaction',
|
|
|
|
{
|
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
await txController.approveTransaction(txMeta.id);
|
|
|
|
await txController.createSpeedUpTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 12345 },
|
|
|
|
);
|
|
|
|
const transactionCount1 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
await txController.createSpeedUpTransaction(
|
|
|
|
txMeta.id,
|
|
|
|
{},
|
|
|
|
{ actionId: 11111 },
|
|
|
|
);
|
|
|
|
const transactionCount2 =
|
|
|
|
txController.txStateManager.getTransactions().length;
|
|
|
|
assert.equal(transactionCount1 + 1, transactionCount2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call securityProviderRequest and have flagAsDangerous inside txMeta', async function () {
|
|
|
|
const txMeta = await txController.addUnapprovedTransaction(
|
|
|
|
'eth_sendTransaction',
|
|
|
|
{
|
|
|
|
from: selectedAddress,
|
|
|
|
to: recipientAddress,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
'securityProviderResponse' in txMeta,
|
|
|
|
'should have a securityProviderResponse',
|
|
|
|
);
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-26 06:42:59 +02:00
|
|
|
|
2021-07-12 22:26:53 +02:00
|
|
|
describe('#signTransaction', function () {
|
|
|
|
let fromTxDataSpy;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
fromTxDataSpy = sinon.spy(TransactionFactory, 'fromTxData');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
fromTxDataSpy.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets txParams.type to 0x0 (non-EIP-1559)', async function () {
|
|
|
|
txController.txStateManager._addTransactionsToState([
|
|
|
|
{
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-07-12 22:26:53 +02:00
|
|
|
id: 1,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
txParams: {
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
await txController.signTransaction('1');
|
|
|
|
assert.equal(fromTxDataSpy.getCall(0).args[0].type, '0x0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets txParams.type to 0x2 (EIP-1559)', async function () {
|
2021-07-31 02:45:18 +02:00
|
|
|
const eip1559CompatibilityStub = sinon
|
|
|
|
.stub(txController, 'getEIP1559Compatibility')
|
|
|
|
.returns(true);
|
2021-07-12 22:26:53 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
|
|
|
{
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-07-12 22:26:53 +02:00
|
|
|
id: 2,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
|
|
|
txParams: {
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
maxFeePerGas: '0x77359400',
|
|
|
|
maxPriorityFeePerGas: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
await txController.signTransaction('2');
|
|
|
|
assert.equal(fromTxDataSpy.getCall(0).args[0].type, '0x2');
|
2021-07-31 02:45:18 +02:00
|
|
|
eip1559CompatibilityStub.restore();
|
2021-07-12 22:26:53 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-23 01:15:18 +02:00
|
|
|
describe('#publishTransaction', function () {
|
2021-06-24 21:00:54 +02:00
|
|
|
let hash, txMeta, trackTransactionMetricsEventSpy;
|
|
|
|
|
2017-09-23 01:15:18 +02:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
hash =
|
2021-02-04 19:15:23 +01:00
|
|
|
'0x2a5523c6fa98b47b7d9b6c8320179785150b42a16bcff36b398c5062b65657e8';
|
2017-09-23 01:15:18 +02:00
|
|
|
txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
2021-06-24 21:00:54 +02:00
|
|
|
gas: '0x7b0d',
|
2021-03-30 16:54:05 +02:00
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2017-09-23 01:15:18 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
providerResultStub.eth_sendRawTransaction = hash;
|
2021-06-24 21:00:54 +02:00
|
|
|
trackTransactionMetricsEventSpy = sinon.spy(
|
|
|
|
txController,
|
|
|
|
'_trackTransactionMetricsEvent',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
trackTransactionMetricsEventSpy.restore();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2017-09-26 04:47:03 +02:00
|
|
|
|
2017-09-23 01:15:18 +02:00
|
|
|
it('should publish a tx, updates the rawTx when provided a one', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const rawTx =
|
2021-02-04 19:15:23 +01:00
|
|
|
'0x477b2e6553c917af0db0388ae3da62965ff1a184558f61b749d1266b2e6d024c';
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager.addTransaction(txMeta);
|
2021-02-04 19:15:23 +01:00
|
|
|
await txController.publishTransaction(txMeta.id, rawTx);
|
2021-03-30 16:54:05 +02:00
|
|
|
const publishedTx = txController.txStateManager.getTransaction(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(publishedTx.hash, hash);
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(publishedTx.status, TransactionStatus.submitted);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-10-30 22:40:33 +01:00
|
|
|
|
|
|
|
it('should ignore the error "Transaction Failed: known transaction" and be as usual', async function () {
|
2020-08-19 18:27:05 +02:00
|
|
|
providerResultStub.eth_sendRawTransaction = async (_, __, ___, end) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
end('Transaction Failed: known transaction');
|
|
|
|
};
|
2020-11-03 00:41:28 +01:00
|
|
|
const rawTx =
|
2021-02-04 19:15:23 +01:00
|
|
|
'0xf86204831e848082520894f231d46dd78806e1dd93442cf33c7671f853874880802ca05f973e540f2d3c2f06d3725a626b75247593cb36477187ae07ecfe0a4db3cf57a00259b52ee8c58baaa385fb05c3f96116e58de89bcc165cb3bfdfc708672fed8a';
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager.addTransaction(txMeta);
|
2021-02-04 19:15:23 +01:00
|
|
|
await txController.publishTransaction(txMeta.id, rawTx);
|
2021-03-30 16:54:05 +02:00
|
|
|
const publishedTx = txController.txStateManager.getTransaction(1);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
publishedTx.hash,
|
|
|
|
'0x2cc5a25744486f7383edebbf32003e5a66e18135799593d6b5cdd2bb43674f09',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(publishedTx.status, TransactionStatus.submitted);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-06-24 21:00:54 +02:00
|
|
|
|
|
|
|
it('should call _trackTransactionMetricsEvent with the correct params', async function () {
|
|
|
|
const rawTx =
|
|
|
|
'0x477b2e6553c917af0db0388ae3da62965ff1a184558f61b749d1266b2e6d024c';
|
|
|
|
txController.txStateManager.addTransaction(txMeta);
|
|
|
|
await txController.publishTransaction(txMeta.id, rawTx);
|
|
|
|
assert.equal(trackTransactionMetricsEventSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
trackTransactionMetricsEventSpy.getCall(0).args[0],
|
|
|
|
txMeta,
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
trackTransactionMetricsEventSpy.getCall(0).args[1],
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.submitted,
|
2021-06-24 21:00:54 +02:00
|
|
|
);
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
2018-03-13 22:30:59 +01:00
|
|
|
describe('#_markNonceDuplicatesDropped', function () {
|
|
|
|
it('should mark all nonce duplicates as dropped without marking the confirmed transaction as dropped', function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.confirmed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 6,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 7,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
history: [{}],
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS_TWO,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
nonce: '0x01',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
txController._markNonceDuplicatesDropped(1);
|
2021-03-30 16:54:05 +02:00
|
|
|
const confirmedTx = txController.txStateManager.getTransaction(1);
|
|
|
|
const droppedTxs = txController.txStateManager.getTransactions({
|
|
|
|
searchCriteria: {
|
|
|
|
nonce: '0x01',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.dropped,
|
2021-03-30 16:54:05 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
confirmedTx.status,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionStatus.confirmed,
|
2020-11-03 00:41:28 +01:00
|
|
|
'the confirmedTx should remain confirmed',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(droppedTxs.length, 6, 'their should be 6 dropped txs');
|
|
|
|
});
|
|
|
|
});
|
2017-09-23 01:15:18 +02:00
|
|
|
|
|
|
|
describe('#getPendingTransactions', function () {
|
2020-04-20 17:01:00 +02:00
|
|
|
it('should show only submitted and approved transactions as pending transaction', function () {
|
2021-03-30 16:54:05 +02:00
|
|
|
txController.txStateManager._addTransactionsToState([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.rejected,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.approved,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.signed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.submitted,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 6,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.confirmed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 7,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.failed,
|
2020-11-03 00:41:28 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
2021-03-30 16:54:05 +02:00
|
|
|
txParams: {
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2020-02-11 17:51:13 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
txController.pendingTxTracker.getPendingTransactions().length,
|
|
|
|
2,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const states = txController.pendingTxTracker
|
|
|
|
.getPendingTransactions()
|
2021-02-04 19:15:23 +01:00
|
|
|
.map((tx) => tx.status);
|
2020-11-07 08:38:12 +01:00
|
|
|
assert.ok(
|
2023-01-18 15:47:29 +01:00
|
|
|
states.includes(TransactionStatus.approved),
|
2020-11-07 08:38:12 +01:00
|
|
|
'includes approved',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-07 08:38:12 +01:00
|
|
|
assert.ok(
|
2023-01-18 15:47:29 +01:00
|
|
|
states.includes(TransactionStatus.submitted),
|
2020-11-07 08:38:12 +01:00
|
|
|
'includes submitted',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-06-24 21:00:54 +02:00
|
|
|
|
|
|
|
describe('#_trackTransactionMetricsEvent', function () {
|
|
|
|
let trackMetaMetricsEventSpy;
|
2022-01-20 17:26:39 +01:00
|
|
|
let createEventFragmentSpy;
|
|
|
|
let finalizeEventFragmentSpy;
|
2021-06-24 21:00:54 +02:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
trackMetaMetricsEventSpy = sinon.spy(
|
|
|
|
txController,
|
|
|
|
'_trackMetaMetricsEvent',
|
|
|
|
);
|
2022-01-20 17:26:39 +01:00
|
|
|
|
|
|
|
createEventFragmentSpy = sinon.spy(txController, 'createEventFragment');
|
|
|
|
|
|
|
|
finalizeEventFragmentSpy = sinon.spy(
|
|
|
|
txController,
|
|
|
|
'finalizeEventFragment',
|
|
|
|
);
|
2022-01-31 18:27:46 +01:00
|
|
|
|
|
|
|
sinon
|
|
|
|
.stub(txController, '_getEIP1559GasFeeEstimates')
|
|
|
|
.resolves(mockEstimates['fee-market']);
|
2021-06-24 21:00:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
trackMetaMetricsEventSpy.restore();
|
2022-01-20 17:26:39 +01:00
|
|
|
createEventFragmentSpy.restore();
|
|
|
|
finalizeEventFragmentSpy.restore();
|
2021-06-24 21:00:54 +02:00
|
|
|
});
|
|
|
|
|
2022-01-20 17:26:39 +01:00
|
|
|
describe('On transaction created by the user', function () {
|
|
|
|
let txMeta;
|
2022-09-16 19:04:14 +02:00
|
|
|
|
2022-01-20 17:26:39 +01:00
|
|
|
before(function () {
|
|
|
|
txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-01-20 17:26:39 +01:00
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2022-04-26 19:07:39 +02:00
|
|
|
origin: ORIGIN_METAMASK,
|
2022-01-20 17:26:39 +01:00
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
2022-01-31 18:27:46 +01:00
|
|
|
defaultGasEstimates: {
|
|
|
|
gas: '0x7b0d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
},
|
2023-03-23 18:01:51 +01:00
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 0,
|
|
|
|
},
|
2022-01-20 17:26:39 +01:00
|
|
|
};
|
|
|
|
});
|
2021-06-24 21:00:54 +02:00
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should create an event fragment when transaction added', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
initialEvent: 'Transaction Added',
|
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2022-01-20 17:26:39 +01:00
|
|
|
persist: true,
|
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-01-31 18:27:46 +01:00
|
|
|
eip_1559_version: '0',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2022-04-26 19:07:39 +02:00
|
|
|
referrer: ORIGIN_METAMASK,
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.USER,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
2022-01-20 17:26:39 +01:00
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
2022-01-31 18:27:46 +01:00
|
|
|
default_gas: '0.000031501',
|
|
|
|
default_gas_price: '2',
|
2022-01-20 17:26:39 +01:00
|
|
|
gas_price: '2',
|
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2022-01-20 17:26:39 +01:00
|
|
|
first_seen: 1624408066355,
|
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.added,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
|
|
|
assert.deepEqual(
|
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('Should finalize the transaction added fragment as abandoned if user rejects transaction', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = true;
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.rejected,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 0);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-added-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(finalizeEventFragmentSpy.getCall(0).args[1], {
|
|
|
|
abandoned: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('Should finalize the transaction added fragment if user approves transaction', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = true;
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.approved,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 0);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-added-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[1],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should create an event fragment when transaction is submitted', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
initialEvent: 'Transaction Submitted',
|
|
|
|
successEvent: 'Transaction Finalized',
|
|
|
|
uniqueIdentifier: 'transaction-submitted-1',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2022-01-20 17:26:39 +01:00
|
|
|
persist: true,
|
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-01-31 18:27:46 +01:00
|
|
|
eip_1559_version: '0',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2022-04-26 19:07:39 +02:00
|
|
|
referrer: ORIGIN_METAMASK,
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.USER,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
2022-01-20 17:26:39 +01:00
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
2022-01-31 18:27:46 +01:00
|
|
|
default_gas: '0.000031501',
|
|
|
|
default_gas_price: '2',
|
2022-01-20 17:26:39 +01:00
|
|
|
gas_price: '2',
|
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2022-01-20 17:26:39 +01:00
|
|
|
first_seen: 1624408066355,
|
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.submitted,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
|
|
|
assert.deepEqual(
|
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('Should finalize the transaction submitted fragment when transaction finalizes', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = true;
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.finalized,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 0);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-submitted-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[1],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
2021-06-24 21:00:54 +02:00
|
|
|
});
|
|
|
|
|
2022-01-20 17:26:39 +01:00
|
|
|
describe('On transaction suggested by dapp', function () {
|
|
|
|
let txMeta;
|
|
|
|
before(function () {
|
|
|
|
txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-01-20 17:26:39 +01:00
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2022-01-20 17:26:39 +01:00
|
|
|
origin: 'other',
|
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
2022-01-31 18:27:46 +01:00
|
|
|
defaultGasEstimates: {
|
|
|
|
gas: '0x7b0d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
},
|
2023-03-23 18:01:51 +01:00
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 0,
|
|
|
|
},
|
2022-01-20 17:26:39 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should create an event fragment when transaction added', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
initialEvent: 'Transaction Added',
|
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2022-01-20 17:26:39 +01:00
|
|
|
persist: true,
|
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-01-31 18:27:46 +01:00
|
|
|
eip_1559_version: '0',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2022-01-20 17:26:39 +01:00
|
|
|
referrer: 'other',
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
2022-01-20 17:26:39 +01:00
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
2022-01-31 18:27:46 +01:00
|
|
|
default_gas: '0.000031501',
|
|
|
|
default_gas_price: '2',
|
2022-01-20 17:26:39 +01:00
|
|
|
gas_price: '2',
|
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2022-01-20 17:26:39 +01:00
|
|
|
first_seen: 1624408066355,
|
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.added,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
|
|
|
assert.deepEqual(
|
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('Should finalize the transaction added fragment as abandoned if user rejects transaction', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = true;
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.rejected,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 0);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-added-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(finalizeEventFragmentSpy.getCall(0).args[1], {
|
|
|
|
abandoned: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('Should finalize the transaction added fragment if user approves transaction', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = true;
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.approved,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 0);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-added-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[1],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should create an event fragment when transaction is submitted', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
initialEvent: 'Transaction Submitted',
|
|
|
|
successEvent: 'Transaction Finalized',
|
|
|
|
uniqueIdentifier: 'transaction-submitted-1',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2022-01-20 17:26:39 +01:00
|
|
|
persist: true,
|
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-01-31 18:27:46 +01:00
|
|
|
eip_1559_version: '0',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2022-01-20 17:26:39 +01:00
|
|
|
referrer: 'other',
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
2022-01-20 17:26:39 +01:00
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
2022-01-31 18:27:46 +01:00
|
|
|
default_gas: '0.000031501',
|
|
|
|
default_gas_price: '2',
|
2022-01-20 17:26:39 +01:00
|
|
|
gas_price: '2',
|
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2022-01-20 17:26:39 +01:00
|
|
|
first_seen: 1624408066355,
|
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.submitted,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
|
|
|
assert.deepEqual(
|
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('Should finalize the transaction submitted fragment when transaction finalizes', async function () {
|
2022-01-20 17:26:39 +01:00
|
|
|
fragmentExists = true;
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2022-01-20 17:26:39 +01:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.finalized,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 0);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-submitted-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[1],
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should create missing fragments when events happen out of order or are missing', async function () {
|
2021-06-24 21:00:54 +02:00
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-06-24 21:00:54 +02:00
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2021-06-24 21:00:54 +02:00
|
|
|
origin: 'other',
|
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
2023-03-23 18:01:51 +01:00
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 0,
|
|
|
|
},
|
2021-06-24 21:00:54 +02:00
|
|
|
};
|
2022-01-20 17:26:39 +01:00
|
|
|
|
2021-06-24 21:00:54 +02:00
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2022-01-20 17:26:39 +01:00
|
|
|
persist: true,
|
2021-07-13 00:30:35 +02:00
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-01-31 18:27:46 +01:00
|
|
|
eip_1559_version: '0',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2021-07-13 00:30:35 +02:00
|
|
|
referrer: 'other',
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
2021-07-13 00:30:35 +02:00
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
2021-07-12 19:54:39 +02:00
|
|
|
gas_price: '2',
|
2021-06-29 23:54:42 +02:00
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2021-06-24 21:00:54 +02:00
|
|
|
first_seen: 1624408066355,
|
2021-11-10 20:50:43 +01:00
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
2021-06-24 21:00:54 +02:00
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2021-06-24 21:00:54 +02:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.approved,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2021-06-24 21:00:54 +02:00
|
|
|
);
|
2022-01-20 17:26:39 +01:00
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
2021-06-24 21:00:54 +02:00
|
|
|
assert.deepEqual(
|
2022-01-20 17:26:39 +01:00
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
2021-06-24 21:00:54 +02:00
|
|
|
expectedPayload,
|
|
|
|
);
|
2022-01-20 17:26:39 +01:00
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 1);
|
|
|
|
assert.deepEqual(
|
|
|
|
finalizeEventFragmentSpy.getCall(0).args[0],
|
|
|
|
'transaction-added-1',
|
|
|
|
);
|
|
|
|
assert.deepEqual(finalizeEventFragmentSpy.getCall(0).args[1], undefined);
|
2021-06-24 21:00:54 +02:00
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should call _trackMetaMetricsEvent with the correct payload (extra params)', async function () {
|
2021-06-24 21:00:54 +02:00
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-06-24 21:00:54 +02:00
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2021-06-24 21:00:54 +02:00
|
|
|
origin: 'other',
|
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
2023-03-23 18:01:51 +01:00
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 0,
|
|
|
|
},
|
2021-06-24 21:00:54 +02:00
|
|
|
};
|
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
initialEvent: 'Transaction Added',
|
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
|
|
|
persist: true,
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2021-07-13 00:30:35 +02:00
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2021-07-13 00:30:35 +02:00
|
|
|
referrer: 'other',
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-01-31 18:27:46 +01:00
|
|
|
eip_1559_version: '0',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
|
|
|
gas_price: '2',
|
|
|
|
gas_limit: '0x7b0d',
|
|
|
|
transaction_contract_method: undefined,
|
|
|
|
transaction_replaced: undefined,
|
|
|
|
first_seen: 1624408066355,
|
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await txController._trackTransactionMetricsEvent(
|
|
|
|
txMeta,
|
|
|
|
TransactionMetaMetricsEvent.added,
|
|
|
|
actionId,
|
|
|
|
{
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
|
|
|
assert.deepEqual(
|
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call _trackMetaMetricsEvent with the correct payload (extra params) when flagAsDangerous is malicious', async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
status: TransactionStatus.unapproved,
|
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
|
|
|
type: TransactionType.simpleSend,
|
|
|
|
origin: 'other',
|
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expectedPayload = {
|
|
|
|
actionId,
|
|
|
|
initialEvent: 'Transaction Added',
|
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
|
|
|
persist: true,
|
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
|
|
|
properties: {
|
|
|
|
network: '5',
|
|
|
|
referrer: 'other',
|
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
|
|
|
transaction_type: TransactionType.simpleSend,
|
|
|
|
chain_id: '0x5',
|
|
|
|
eip_1559_version: '0',
|
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
|
|
|
account_type: 'MetaMask',
|
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
|
|
|
device_model: 'N/A',
|
|
|
|
transaction_speed_up: false,
|
|
|
|
ui_customizations: ['flagged_as_malicious'],
|
|
|
|
},
|
|
|
|
sensitiveProperties: {
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
|
|
|
gas_price: '2',
|
|
|
|
gas_limit: '0x7b0d',
|
|
|
|
transaction_contract_method: undefined,
|
|
|
|
transaction_replaced: undefined,
|
|
|
|
first_seen: 1624408066355,
|
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await txController._trackTransactionMetricsEvent(
|
|
|
|
txMeta,
|
|
|
|
TransactionMetaMetricsEvent.added,
|
|
|
|
actionId,
|
|
|
|
{
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
|
|
|
assert.deepEqual(
|
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call _trackMetaMetricsEvent with the correct payload (extra params) when flagAsDangerous is unknown', async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
status: TransactionStatus.unapproved,
|
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
|
|
|
type: TransactionType.simpleSend,
|
|
|
|
origin: 'other',
|
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 2,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expectedPayload = {
|
|
|
|
actionId,
|
|
|
|
initialEvent: 'Transaction Added',
|
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
|
|
|
persist: true,
|
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
|
|
|
properties: {
|
|
|
|
network: '5',
|
|
|
|
referrer: 'other',
|
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
|
|
|
transaction_type: TransactionType.simpleSend,
|
|
|
|
chain_id: '0x5',
|
|
|
|
eip_1559_version: '0',
|
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
|
|
|
account_type: 'MetaMask',
|
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
|
|
|
device_model: 'N/A',
|
|
|
|
transaction_speed_up: false,
|
|
|
|
ui_customizations: ['flagged_as_safety_unknown'],
|
2021-07-13 00:30:35 +02:00
|
|
|
},
|
2021-06-24 21:00:54 +02:00
|
|
|
sensitiveProperties: {
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
2021-07-12 19:54:39 +02:00
|
|
|
gas_price: '2',
|
2021-06-29 23:54:42 +02:00
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2021-06-29 23:54:42 +02:00
|
|
|
first_seen: 1624408066355,
|
2021-11-10 20:50:43 +01:00
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.LEGACY,
|
2021-06-29 23:54:42 +02:00
|
|
|
status: 'unapproved',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2021-06-29 23:54:42 +02:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.added,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2021-06-29 23:54:42 +02:00
|
|
|
{
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
);
|
2022-01-20 17:26:39 +01:00
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
2021-06-29 23:54:42 +02:00
|
|
|
assert.deepEqual(
|
2022-01-20 17:26:39 +01:00
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
2021-06-29 23:54:42 +02:00
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
it('should call _trackMetaMetricsEvent with the correct payload (EIP-1559)', async function () {
|
2021-06-29 23:54:42 +02:00
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2021-06-29 23:54:42 +02:00
|
|
|
txParams: {
|
|
|
|
from: fromAccount.address,
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
maxFeePerGas: '0x77359400',
|
|
|
|
maxPriorityFeePerGas: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
2023-01-27 19:28:03 +01:00
|
|
|
estimateSuggested: GasRecommendations.medium,
|
|
|
|
estimateUsed: GasRecommendations.high,
|
2021-06-29 23:54:42 +02:00
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2021-06-29 23:54:42 +02:00
|
|
|
origin: 'other',
|
|
|
|
chainId: currentChainId,
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: currentNetworkId,
|
2022-01-31 18:27:46 +01:00
|
|
|
defaultGasEstimates: {
|
|
|
|
estimateType: 'medium',
|
|
|
|
maxFeePerGas: '0x77359400',
|
|
|
|
maxPriorityFeePerGas: '0x77359400',
|
|
|
|
},
|
2023-03-23 18:01:51 +01:00
|
|
|
securityProviderResponse: {
|
|
|
|
flagAsDangerous: 0,
|
|
|
|
},
|
2021-06-29 23:54:42 +02:00
|
|
|
};
|
|
|
|
const expectedPayload = {
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-01-20 17:26:39 +01:00
|
|
|
initialEvent: 'Transaction Added',
|
|
|
|
successEvent: 'Transaction Approved',
|
|
|
|
failureEvent: 'Transaction Rejected',
|
|
|
|
uniqueIdentifier: 'transaction-added-1',
|
|
|
|
persist: true,
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.TRANSACTIONS,
|
2021-07-13 00:30:35 +02:00
|
|
|
properties: {
|
2022-09-29 05:26:01 +02:00
|
|
|
chain_id: '0x5',
|
2022-12-08 19:37:06 +01:00
|
|
|
eip_1559_version: '2',
|
2022-02-01 18:53:03 +01:00
|
|
|
gas_edit_attempted: 'none',
|
|
|
|
gas_edit_type: 'none',
|
2022-09-29 05:26:01 +02:00
|
|
|
network: '5',
|
2021-07-13 00:30:35 +02:00
|
|
|
referrer: 'other',
|
2022-05-11 22:27:58 +02:00
|
|
|
source: EVENT.SOURCE.TRANSACTION.DAPP,
|
2023-01-18 15:47:29 +01:00
|
|
|
transaction_type: TransactionType.simpleSend,
|
2022-02-23 16:15:41 +01:00
|
|
|
account_type: 'MetaMask',
|
2023-01-18 15:47:29 +01:00
|
|
|
asset_type: AssetType.native,
|
|
|
|
token_standard: TokenStandard.none,
|
2022-02-23 16:15:41 +01:00
|
|
|
device_model: 'N/A',
|
2022-07-28 15:46:20 +02:00
|
|
|
transaction_speed_up: false,
|
2023-03-23 18:01:51 +01:00
|
|
|
ui_customizations: null,
|
2021-07-13 00:30:35 +02:00
|
|
|
},
|
2021-06-29 23:54:42 +02:00
|
|
|
sensitiveProperties: {
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
2021-07-12 19:54:39 +02:00
|
|
|
max_fee_per_gas: '2',
|
|
|
|
max_priority_fee_per_gas: '2',
|
2021-06-29 23:54:42 +02:00
|
|
|
gas_limit: '0x7b0d',
|
2022-07-22 19:45:04 +02:00
|
|
|
transaction_contract_method: undefined,
|
2022-08-02 17:53:09 +02:00
|
|
|
transaction_replaced: undefined,
|
2021-06-24 21:00:54 +02:00
|
|
|
first_seen: 1624408066355,
|
2021-11-10 20:50:43 +01:00
|
|
|
transaction_envelope_type: TRANSACTION_ENVELOPE_TYPE_NAMES.FEE_MARKET,
|
2021-06-24 21:00:54 +02:00
|
|
|
status: 'unapproved',
|
2023-01-27 19:28:03 +01:00
|
|
|
estimate_suggested: GasRecommendations.medium,
|
|
|
|
estimate_used: GasRecommendations.high,
|
2022-01-31 18:27:46 +01:00
|
|
|
default_estimate: 'medium',
|
|
|
|
default_max_fee_per_gas: '70',
|
|
|
|
default_max_priority_fee_per_gas: '7',
|
2021-06-24 21:00:54 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-31 18:27:46 +01:00
|
|
|
await txController._trackTransactionMetricsEvent(
|
2021-06-24 21:00:54 +02:00
|
|
|
txMeta,
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionMetaMetricsEvent.added,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2021-06-24 21:00:54 +02:00
|
|
|
{
|
|
|
|
baz: 3.0,
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
);
|
2022-01-20 17:26:39 +01:00
|
|
|
assert.equal(createEventFragmentSpy.callCount, 1);
|
|
|
|
assert.equal(finalizeEventFragmentSpy.callCount, 0);
|
2021-06-24 21:00:54 +02:00
|
|
|
assert.deepEqual(
|
2022-01-20 17:26:39 +01:00
|
|
|
createEventFragmentSpy.getCall(0).args[0],
|
2021-06-24 21:00:54 +02:00
|
|
|
expectedPayload,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-07-12 19:14:54 +02:00
|
|
|
|
|
|
|
describe('#_getTransactionCompletionTime', function () {
|
|
|
|
let nowStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
nowStub = sinon.stub(Date, 'now').returns(1625782016341);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
nowStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calculates completion time (one)', function () {
|
|
|
|
const submittedTime = 1625781997397;
|
|
|
|
const result = txController._getTransactionCompletionTime(submittedTime);
|
|
|
|
assert.equal(result, '19');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calculates completion time (two)', function () {
|
|
|
|
const submittedTime = 1625781995397;
|
|
|
|
const result = txController._getTransactionCompletionTime(submittedTime);
|
|
|
|
assert.equal(result, '21');
|
|
|
|
});
|
|
|
|
});
|
2021-07-12 19:54:39 +02:00
|
|
|
|
|
|
|
describe('#_getGasValuesInGWEI', function () {
|
|
|
|
it('converts gas values in hex GWEi to dec GWEI (EIP-1559)', function () {
|
|
|
|
const params = {
|
|
|
|
max_fee_per_gas: '0x77359400',
|
|
|
|
max_priority_fee_per_gas: '0x77359400',
|
|
|
|
};
|
|
|
|
const expectedParams = {
|
|
|
|
max_fee_per_gas: '2',
|
|
|
|
max_priority_fee_per_gas: '2',
|
|
|
|
};
|
|
|
|
const result = txController._getGasValuesInGWEI(params);
|
|
|
|
assert.deepEqual(result, expectedParams);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts gas values in hex GWEi to dec GWEI (non EIP-1559)', function () {
|
|
|
|
const params = {
|
|
|
|
gas_price: '0x37e11d600',
|
|
|
|
};
|
|
|
|
const expectedParams = {
|
|
|
|
gas_price: '15',
|
|
|
|
};
|
|
|
|
const result = txController._getGasValuesInGWEI(params);
|
|
|
|
assert.deepEqual(result, expectedParams);
|
|
|
|
});
|
2021-10-22 22:42:20 +02:00
|
|
|
|
|
|
|
it('converts gas values in hex GWEi to dec GWEI, retains estimate fields', function () {
|
|
|
|
const params = {
|
|
|
|
max_fee_per_gas: '0x77359400',
|
|
|
|
max_priority_fee_per_gas: '0x77359400',
|
2023-01-27 19:28:03 +01:00
|
|
|
estimate_suggested: GasRecommendations.medium,
|
|
|
|
estimate_used: GasRecommendations.high,
|
2021-10-22 22:42:20 +02:00
|
|
|
};
|
|
|
|
const expectedParams = {
|
|
|
|
max_fee_per_gas: '2',
|
|
|
|
max_priority_fee_per_gas: '2',
|
2023-01-27 19:28:03 +01:00
|
|
|
estimate_suggested: GasRecommendations.medium,
|
|
|
|
estimate_used: GasRecommendations.high,
|
2021-10-22 22:42:20 +02:00
|
|
|
};
|
|
|
|
const result = txController._getGasValuesInGWEI(params);
|
|
|
|
assert.deepEqual(result, expectedParams);
|
|
|
|
});
|
2021-07-12 19:54:39 +02:00
|
|
|
});
|
2022-02-24 19:26:58 +01:00
|
|
|
|
|
|
|
describe('update transaction methods', function () {
|
|
|
|
let txStateManager;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
txStateManager = txController.txStateManager;
|
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '1',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-02-24 19:26:58 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
gasLimit: '0x001',
|
|
|
|
gasPrice: '0x002',
|
|
|
|
// max fees can not be mixed with gasPrice
|
|
|
|
// maxPriorityFeePerGas: '0x003',
|
|
|
|
// maxFeePerGas: '0x004',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
},
|
|
|
|
estimateUsed: '0x005',
|
|
|
|
estimatedBaseFee: '0x006',
|
|
|
|
decEstimatedBaseFee: '6',
|
|
|
|
type: 'swap',
|
|
|
|
sourceTokenSymbol: 'ETH',
|
|
|
|
destinationTokenSymbol: 'UNI',
|
|
|
|
destinationTokenDecimals: 16,
|
|
|
|
destinationTokenAddress: VALID_ADDRESS,
|
|
|
|
swapMetaData: {},
|
|
|
|
swapTokenValue: '0x007',
|
|
|
|
userEditedGasLimit: '0x008',
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates transaction gas fees', function () {
|
|
|
|
// test update gasFees
|
|
|
|
txController.updateTransactionGasFees('1', {
|
|
|
|
gasPrice: '0x0022',
|
|
|
|
gasLimit: '0x0011',
|
|
|
|
});
|
|
|
|
let result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.txParams.gasPrice, '0x0022');
|
|
|
|
// TODO: weird behavior here...only gasPrice gets returned.
|
|
|
|
// assert.equal(result.txParams.gasLimit, '0x0011');
|
|
|
|
|
|
|
|
// test update maxPriorityFeePerGas
|
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '2',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-02-24 19:26:58 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
maxPriorityFeePerGas: '0x003',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
},
|
|
|
|
estimateUsed: '0x005',
|
|
|
|
});
|
|
|
|
txController.updateTransactionGasFees('2', {
|
|
|
|
maxPriorityFeePerGas: '0x0033',
|
|
|
|
});
|
|
|
|
result = txStateManager.getTransaction('2');
|
|
|
|
assert.equal(result.txParams.maxPriorityFeePerGas, '0x0033');
|
|
|
|
|
|
|
|
// test update maxFeePerGas
|
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '3',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-02-24 19:26:58 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
maxPriorityFeePerGas: '0x003',
|
|
|
|
maxFeePerGas: '0x004',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
},
|
|
|
|
estimateUsed: '0x005',
|
|
|
|
});
|
|
|
|
txController.updateTransactionGasFees('3', { maxFeePerGas: '0x0044' });
|
|
|
|
result = txStateManager.getTransaction('3');
|
|
|
|
assert.equal(result.txParams.maxFeePerGas, '0x0044');
|
|
|
|
|
|
|
|
// test update estimate used
|
|
|
|
txController.updateTransactionGasFees('3', { estimateUsed: '0x0055' });
|
|
|
|
result = txStateManager.getTransaction('3');
|
|
|
|
assert.equal(result.estimateUsed, '0x0055');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates estimated base fee', function () {
|
|
|
|
txController.updateTransactionEstimatedBaseFee('1', {
|
|
|
|
estimatedBaseFee: '0x0066',
|
|
|
|
decEstimatedBaseFee: '66',
|
|
|
|
});
|
|
|
|
const result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.estimatedBaseFee, '0x0066');
|
|
|
|
assert.equal(result.decEstimatedBaseFee, '66');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates swap approval transaction', function () {
|
|
|
|
txController.updateSwapApprovalTransaction('1', {
|
|
|
|
type: 'swapApproval',
|
|
|
|
sourceTokenSymbol: 'XBN',
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.type, 'swapApproval');
|
|
|
|
assert.equal(result.sourceTokenSymbol, 'XBN');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates swap transaction', function () {
|
|
|
|
txController.updateSwapTransaction('1', {
|
|
|
|
sourceTokenSymbol: 'BTCX',
|
|
|
|
destinationTokenSymbol: 'ETH',
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.sourceTokenSymbol, 'BTCX');
|
|
|
|
assert.equal(result.destinationTokenSymbol, 'ETH');
|
|
|
|
assert.equal(result.destinationTokenDecimals, 16);
|
|
|
|
assert.equal(result.destinationTokenAddress, VALID_ADDRESS);
|
|
|
|
assert.equal(result.swapTokenValue, '0x007');
|
|
|
|
|
|
|
|
txController.updateSwapTransaction('1', {
|
|
|
|
type: 'swapped',
|
|
|
|
destinationTokenDecimals: 8,
|
|
|
|
destinationTokenAddress: VALID_ADDRESS_TWO,
|
|
|
|
swapTokenValue: '0x0077',
|
|
|
|
});
|
|
|
|
assert.equal(result.sourceTokenSymbol, 'BTCX');
|
|
|
|
assert.equal(result.destinationTokenSymbol, 'ETH');
|
|
|
|
assert.equal(result.type, 'swapped');
|
|
|
|
assert.equal(result.destinationTokenDecimals, 8);
|
|
|
|
assert.equal(result.destinationTokenAddress, VALID_ADDRESS_TWO);
|
|
|
|
assert.equal(result.swapTokenValue, '0x0077');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates transaction user settings', function () {
|
|
|
|
txController.updateTransactionUserSettings('1', {
|
|
|
|
userEditedGasLimit: '0x0088',
|
|
|
|
userFeeLevel: 'high',
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.userEditedGasLimit, '0x0088');
|
|
|
|
assert.equal(result.userFeeLevel, 'high');
|
|
|
|
});
|
|
|
|
|
2022-03-30 16:13:25 +02:00
|
|
|
it('should not update and should throw error if status is not type "unapproved"', function () {
|
2022-02-24 19:26:58 +01:00
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '4',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.dropped,
|
2022-02-24 19:26:58 +01:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
maxPriorityFeePerGas: '0x007',
|
|
|
|
maxFeePerGas: '0x008',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
},
|
|
|
|
estimateUsed: '0x009',
|
|
|
|
});
|
|
|
|
|
2022-03-30 16:13:25 +02:00
|
|
|
assert.throws(
|
|
|
|
() =>
|
|
|
|
txController.updateTransactionGasFees('4', {
|
|
|
|
maxFeePerGas: '0x0088',
|
|
|
|
}),
|
|
|
|
Error,
|
|
|
|
`TransactionsController: Can only call updateTransactionGasFees on an unapproved transaction.
|
2023-01-18 15:47:29 +01:00
|
|
|
Current tx status: ${TransactionStatus.dropped}`,
|
2022-03-30 16:13:25 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
const transaction = txStateManager.getTransaction('4');
|
|
|
|
assert.equal(transaction.txParams.maxFeePerGas, '0x008');
|
2022-02-24 19:26:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not update unknown parameters in update method', function () {
|
|
|
|
txController.updateSwapTransaction('1', {
|
|
|
|
type: 'swapped',
|
|
|
|
destinationTokenDecimals: 8,
|
|
|
|
destinationTokenAddress: VALID_ADDRESS_TWO,
|
|
|
|
swapTokenValue: '0x011',
|
|
|
|
gasPrice: '0x12',
|
|
|
|
});
|
|
|
|
|
|
|
|
let result = txStateManager.getTransaction('1');
|
|
|
|
|
|
|
|
assert.equal(result.type, 'swapped');
|
|
|
|
assert.equal(result.destinationTokenDecimals, 8);
|
|
|
|
assert.equal(result.destinationTokenAddress, VALID_ADDRESS_TWO);
|
|
|
|
assert.equal(result.swapTokenValue, '0x011');
|
|
|
|
assert.equal(result.txParams.gasPrice, '0x002'); // not updated even though it's passed in to update
|
|
|
|
|
|
|
|
txController.updateTransactionGasFees('1', {
|
|
|
|
estimateUsed: '0x13',
|
|
|
|
gasPrice: '0x14',
|
|
|
|
destinationTokenAddress: VALID_ADDRESS,
|
|
|
|
});
|
|
|
|
|
|
|
|
result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.estimateUsed, '0x13');
|
|
|
|
assert.equal(result.txParams.gasPrice, '0x14');
|
|
|
|
assert.equal(result.destinationTokenAddress, VALID_ADDRESS_TWO); // not updated even though it's passed in to update
|
|
|
|
});
|
|
|
|
});
|
2022-05-27 18:31:31 +02:00
|
|
|
|
|
|
|
describe('updateEditableParams', function () {
|
|
|
|
let txStateManager;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
txStateManager = txController.txStateManager;
|
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '1',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-05-27 18:31:31 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
gas: '0x001',
|
|
|
|
gasPrice: '0x002',
|
|
|
|
// max fees can not be mixed with gasPrice
|
|
|
|
// maxPriorityFeePerGas: '0x003',
|
|
|
|
// maxFeePerGas: '0x004',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
},
|
|
|
|
estimateUsed: '0x005',
|
|
|
|
estimatedBaseFee: '0x006',
|
|
|
|
decEstimatedBaseFee: '6',
|
|
|
|
type: 'simpleSend',
|
|
|
|
userEditedGasLimit: '0x008',
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates editible params when type changes from simple send to token transfer', async function () {
|
2022-07-12 19:20:20 +02:00
|
|
|
providerResultStub.eth_getCode = '0xab';
|
2022-05-27 18:31:31 +02:00
|
|
|
// test update gasFees
|
|
|
|
await txController.updateEditableParams('1', {
|
2022-07-31 20:26:40 +02:00
|
|
|
data: '0xa9059cbb000000000000000000000000e18035bf8712672935fdb4e5e431b1a0183d2dfc0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
2022-05-27 18:31:31 +02:00
|
|
|
});
|
|
|
|
const result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(
|
|
|
|
result.txParams.data,
|
|
|
|
'0xa9059cbb000000000000000000000000e18035bf8712672935fdb4e5e431b1a0183d2dfc0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
|
|
);
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(result.type, TransactionType.tokenMethodTransfer);
|
2022-05-27 18:31:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates editible params when type changes from token transfer to simple send', async function () {
|
|
|
|
// test update gasFees
|
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '2',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-05-27 18:31:31 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
gas: '0x001',
|
|
|
|
gasPrice: '0x002',
|
|
|
|
// max fees can not be mixed with gasPrice
|
|
|
|
// maxPriorityFeePerGas: '0x003',
|
|
|
|
// maxFeePerGas: '0x004',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
2022-07-31 20:26:40 +02:00
|
|
|
data: '0xa9059cbb000000000000000000000000e18035bf8712672935fdb4e5e431b1a0183d2dfc0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
2022-05-27 18:31:31 +02:00
|
|
|
},
|
|
|
|
estimateUsed: '0x005',
|
|
|
|
estimatedBaseFee: '0x006',
|
|
|
|
decEstimatedBaseFee: '6',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.tokenMethodTransfer,
|
2022-05-27 18:31:31 +02:00
|
|
|
userEditedGasLimit: '0x008',
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
});
|
|
|
|
await txController.updateEditableParams('2', {
|
|
|
|
data: '0x',
|
|
|
|
});
|
|
|
|
const result = txStateManager.getTransaction('2');
|
|
|
|
assert.equal(result.txParams.data, '0x');
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(result.type, TransactionType.simpleSend);
|
2022-05-27 18:31:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates editible params when type changes from simpleSend to contract interaction', async function () {
|
|
|
|
// test update gasFees
|
|
|
|
txStateManager.addTransaction({
|
|
|
|
id: '3',
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2022-05-27 18:31:31 +02:00
|
|
|
metamaskNetworkId: currentNetworkId,
|
|
|
|
txParams: {
|
|
|
|
gas: '0x001',
|
|
|
|
gasPrice: '0x002',
|
|
|
|
// max fees can not be mixed with gasPrice
|
|
|
|
// maxPriorityFeePerGas: '0x003',
|
|
|
|
// maxFeePerGas: '0x004',
|
|
|
|
to: VALID_ADDRESS,
|
|
|
|
from: VALID_ADDRESS,
|
|
|
|
},
|
|
|
|
estimateUsed: '0x005',
|
|
|
|
estimatedBaseFee: '0x006',
|
|
|
|
decEstimatedBaseFee: '6',
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.tokenMethodTransfer,
|
2022-05-27 18:31:31 +02:00
|
|
|
userEditedGasLimit: '0x008',
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
});
|
|
|
|
providerResultStub.eth_getCode = '0x5';
|
|
|
|
await txController.updateEditableParams('3', {
|
|
|
|
data: '0x123',
|
|
|
|
});
|
|
|
|
const result = txStateManager.getTransaction('3');
|
|
|
|
assert.equal(result.txParams.data, '0x123');
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(result.type, TransactionType.contractInteraction);
|
2022-05-27 18:31:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates editible params when type does not change', async function () {
|
|
|
|
// test update gasFees
|
|
|
|
await txController.updateEditableParams('1', {
|
|
|
|
data: '0x123',
|
|
|
|
gas: '0xabc',
|
|
|
|
from: VALID_ADDRESS_TWO,
|
|
|
|
});
|
|
|
|
const result = txStateManager.getTransaction('1');
|
|
|
|
assert.equal(result.txParams.data, '0x123');
|
|
|
|
assert.equal(result.txParams.gas, '0xabc');
|
|
|
|
assert.equal(result.txParams.from, VALID_ADDRESS_TWO);
|
|
|
|
assert.equal(result.txParams.to, VALID_ADDRESS);
|
|
|
|
assert.equal(result.txParams.gasPrice, '0x002');
|
2023-01-18 15:47:29 +01:00
|
|
|
assert.equal(result.type, TransactionType.simpleSend);
|
2022-05-27 18:31:31 +02:00
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|