2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import proxyquire from 'proxyquire';
|
|
|
|
import nock from 'nock';
|
|
|
|
import { cloneDeep } from 'lodash';
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2021-03-16 22:00:08 +01:00
|
|
|
import waitUntilCalled from '../../../test/lib/wait-until-called';
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
import {
|
2021-03-19 22:54:30 +01:00
|
|
|
CHAIN_ID_TO_TYPE_MAP,
|
|
|
|
GOERLI_CHAIN_ID,
|
|
|
|
KOVAN_CHAIN_ID,
|
2020-10-31 01:58:12 +01:00
|
|
|
MAINNET_CHAIN_ID,
|
2021-03-19 22:54:30 +01:00
|
|
|
RINKEBY_CHAIN_ID,
|
2020-10-31 01:58:12 +01:00
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
ROPSTEN_NETWORK_ID,
|
2021-03-19 22:54:30 +01:00
|
|
|
ROPSTEN,
|
2021-03-16 22:00:08 +01:00
|
|
|
} from '../../../shared/constants/network';
|
2020-11-07 08:38:12 +01:00
|
|
|
import {
|
2021-03-10 21:16:44 +01:00
|
|
|
TRANSACTION_TYPES,
|
2020-11-07 08:38:12 +01:00
|
|
|
TRANSACTION_STATUSES,
|
2021-03-16 22:00:08 +01:00
|
|
|
} from '../../../shared/constants/transaction';
|
2020-08-19 18:27:05 +02:00
|
|
|
|
2021-03-16 22:00:08 +01:00
|
|
|
const IncomingTransactionsController = proxyquire('./incoming-transactions', {
|
2021-03-18 19:23:46 +01:00
|
|
|
'../../../shared/modules/random-id': { default: () => 54321 },
|
2021-03-16 22:00:08 +01:00
|
|
|
}).default;
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const FAKE_CHAIN_ID = '0x1338';
|
|
|
|
const MOCK_SELECTED_ADDRESS = '0x0101';
|
|
|
|
const SET_STATE_TIMEOUT = 10;
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const EXISTING_INCOMING_TX = { id: 777, hash: '0x123456' };
|
|
|
|
const PREPOPULATED_INCOMING_TXS_BY_HASH = {
|
|
|
|
[EXISTING_INCOMING_TX.hash]: EXISTING_INCOMING_TX,
|
|
|
|
};
|
|
|
|
const PREPOPULATED_BLOCKS_BY_NETWORK = {
|
|
|
|
[GOERLI_CHAIN_ID]: 1,
|
|
|
|
[KOVAN_CHAIN_ID]: 2,
|
|
|
|
[MAINNET_CHAIN_ID]: 3,
|
|
|
|
[RINKEBY_CHAIN_ID]: 5,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 4,
|
|
|
|
};
|
|
|
|
const EMPTY_BLOCKS_BY_NETWORK = {
|
|
|
|
[GOERLI_CHAIN_ID]: null,
|
|
|
|
[KOVAN_CHAIN_ID]: null,
|
|
|
|
[MAINNET_CHAIN_ID]: null,
|
|
|
|
[RINKEBY_CHAIN_ID]: null,
|
|
|
|
[ROPSTEN_CHAIN_ID]: null,
|
|
|
|
};
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function getEmptyInitState() {
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
return {
|
2019-08-16 20:54:10 +02:00
|
|
|
incomingTransactions: {},
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTxLastFetchedBlockByChainId: EMPTY_BLOCKS_BY_NETWORK,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
}
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function getNonEmptyInitState() {
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
return {
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTransactions: PREPOPULATED_INCOMING_TXS_BY_HASH,
|
|
|
|
incomingTxLastFetchedBlockByChainId: PREPOPULATED_BLOCKS_BY_NETWORK,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
}
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
function getMockNetworkControllerMethods(chainId = FAKE_CHAIN_ID) {
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
return {
|
2020-10-31 01:58:12 +01:00
|
|
|
getCurrentChainId: () => chainId,
|
2021-03-19 22:54:30 +01:00
|
|
|
onNetworkDidChange: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
}
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function getMockPreferencesController({
|
|
|
|
showIncomingTransactions = true,
|
|
|
|
} = {}) {
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
return {
|
|
|
|
getSelectedAddress: sinon.stub().returns(MOCK_SELECTED_ADDRESS),
|
2019-08-16 20:54:10 +02:00
|
|
|
store: {
|
2019-08-21 20:42:14 +02:00
|
|
|
getState: sinon.stub().returns({
|
|
|
|
featureFlags: {
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
showIncomingTransactions,
|
2019-08-21 20:42:14 +02:00
|
|
|
},
|
|
|
|
}),
|
2019-08-16 20:54:10 +02:00
|
|
|
subscribe: sinon.spy(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function getMockBlockTracker() {
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
return {
|
|
|
|
addListener: sinon.stub().callsArgWithAsync(1, '0xa'),
|
|
|
|
removeListener: sinon.spy(),
|
|
|
|
testProperty: 'fakeBlockTracker',
|
|
|
|
getCurrentBlock: () => '0xa',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
}
|
|
|
|
|
2020-10-30 15:17:36 +01:00
|
|
|
/**
|
2021-03-19 22:54:30 +01:00
|
|
|
* @typedef {import(
|
|
|
|
* '../../../../app/scripts/controllers/incoming-transactions'
|
|
|
|
* ).EtherscanTransaction} EtherscanTransaction
|
2020-10-30 15:17:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a transaction object matching the expected format returned
|
|
|
|
* by the Etherscan API
|
|
|
|
*
|
|
|
|
* @param {string} [toAddress] - The hex-prefixed address of the recipient
|
|
|
|
* @param {number} [blockNumber] - The block number for the transaction
|
|
|
|
* @returns {EtherscanTransaction}
|
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
const getFakeEtherscanTransaction = (
|
|
|
|
toAddress = MOCK_SELECTED_ADDRESS,
|
|
|
|
blockNumber = 10,
|
|
|
|
) => {
|
2020-10-30 15:17:36 +01:00
|
|
|
return {
|
|
|
|
blockNumber: blockNumber.toString(),
|
|
|
|
from: '0xfake',
|
|
|
|
gas: '0',
|
|
|
|
gasPrice: '0',
|
|
|
|
hash: '0xfake',
|
|
|
|
isError: '0',
|
|
|
|
nonce: '100',
|
|
|
|
timeStamp: '16000000000000',
|
|
|
|
to: toAddress,
|
|
|
|
value: '0',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
function nockEtherscanApiForAllChains(mockResponse) {
|
|
|
|
for (const chainId of [
|
|
|
|
GOERLI_CHAIN_ID,
|
|
|
|
KOVAN_CHAIN_ID,
|
|
|
|
MAINNET_CHAIN_ID,
|
|
|
|
RINKEBY_CHAIN_ID,
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
'undefined',
|
|
|
|
]) {
|
|
|
|
nock(
|
|
|
|
`https://api${
|
|
|
|
chainId === MAINNET_CHAIN_ID ? '' : `-${CHAIN_ID_TO_TYPE_MAP[chainId]}`
|
|
|
|
}.etherscan.io`,
|
|
|
|
)
|
|
|
|
.get(/api.+/u)
|
|
|
|
.reply(200, JSON.stringify(mockResponse));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Replace shared mocks in incoming transaction controller tests (#9754)
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.
We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.
In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.
The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.
Instead we should never share mocks in the first place, which has other
benefits anyway.
This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
2020-10-29 16:16:04 +01:00
|
|
|
describe('IncomingTransactionsController', function () {
|
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
nock.cleanAll();
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('constructor', function () {
|
|
|
|
it('should set up correct store, listeners and properties in the constructor', function () {
|
2021-03-19 22:54:30 +01:00
|
|
|
const mockedNetworkMethods = getMockNetworkControllerMethods();
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...mockedNetworkMethods,
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: {},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
sinon.spy(incomingTransactionsController, '_update');
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
incomingTransactionsController.store.getState(),
|
|
|
|
getEmptyInitState(),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert(mockedNetworkMethods.onNetworkDidChange.calledOnce);
|
|
|
|
const networkControllerListenerCallback = mockedNetworkMethods.onNetworkDidChange.getCall(
|
2020-11-03 00:41:28 +01:00
|
|
|
0,
|
2021-03-19 22:54:30 +01:00
|
|
|
).args[0];
|
|
|
|
assert.strictEqual(incomingTransactionsController._update.callCount, 0);
|
2021-02-04 19:15:23 +01:00
|
|
|
networkControllerListenerCallback('testNetworkType');
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.strictEqual(incomingTransactionsController._update.callCount, 1);
|
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
incomingTransactionsController._update.getCall(0).args[0],
|
2021-03-19 22:54:30 +01:00
|
|
|
'0x0101',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionsController._update.resetHistory();
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should set the store to a provided initial state', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
incomingTransactionsController.store.getState(),
|
|
|
|
getNonEmptyInitState(),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-10-30 15:17:36 +01:00
|
|
|
describe('update events', function () {
|
|
|
|
it('should set up a listener for the latest block', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: {},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-20 20:52:00 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionsController.start();
|
2019-08-20 20:52:00 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(
|
|
|
|
incomingTransactionsController.blockTracker.addListener.calledOnce,
|
|
|
|
);
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
incomingTransactionsController.blockTracker.addListener.getCall(0)
|
|
|
|
.args[0],
|
|
|
|
'latest',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
it('should update upon latest block when started and on supported network', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const startBlock = getNonEmptyInitState()
|
2021-03-19 22:54:30 +01:00
|
|
|
.incomingTxLastFetchedBlockByChainId[ROPSTEN_CHAIN_ID];
|
2020-10-30 15:17:36 +01:00
|
|
|
nock('https://api-ropsten.etherscan.io')
|
2020-11-03 00:41:28 +01:00
|
|
|
.get(
|
|
|
|
`/api?module=account&action=txlist&address=${MOCK_SELECTED_ADDRESS}&tag=latest&page=1&startBlock=${startBlock}`,
|
|
|
|
)
|
2020-10-30 15:17:36 +01:00
|
|
|
.reply(
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionsController.start();
|
|
|
|
await updateStateCalled();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const actualState = incomingTransactionsController.store.getState();
|
|
|
|
const generatedTxId = actualState?.incomingTransactions?.['0xfake']?.id;
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const actualStateWithoutGenerated = cloneDeep(actualState);
|
|
|
|
delete actualStateWithoutGenerated?.incomingTransactions?.['0xfake']?.id;
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
typeof generatedTxId === 'number' && generatedTxId > 0,
|
|
|
|
'Generated transaction ID should be a positive number',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
actualStateWithoutGenerated,
|
|
|
|
{
|
|
|
|
incomingTransactions: {
|
|
|
|
...getNonEmptyInitState().incomingTransactions,
|
|
|
|
'0xfake': {
|
|
|
|
blockNumber: '10',
|
|
|
|
hash: '0xfake',
|
2021-03-01 16:15:42 +01:00
|
|
|
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
|
|
|
chainId: ROPSTEN_CHAIN_ID,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-10-30 15:17:36 +01:00
|
|
|
time: 16000000000000000,
|
2021-03-10 21:16:44 +01:00
|
|
|
type: TRANSACTION_TYPES.INCOMING,
|
2020-10-30 15:17:36 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0xfake',
|
|
|
|
gas: '0x0',
|
|
|
|
gasPrice: '0x0',
|
|
|
|
nonce: '0x64',
|
|
|
|
to: '0x0101',
|
|
|
|
value: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...getNonEmptyInitState().incomingTxLastFetchedBlockByChainId,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 11,
|
2020-10-30 15:17:36 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'State should have been updated after first block was received',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-10-31 01:58:12 +01:00
|
|
|
it('should not update upon latest block when started and not on supported network', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-31 01:58:12 +01:00
|
|
|
// reply with a valid request for any supported network, so that this test has every opportunity to fail
|
2021-03-19 22:54:30 +01:00
|
|
|
nockEtherscanApiForAllChains({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
});
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'putState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateCalled = waitUntilCalled(
|
|
|
|
putStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionsController.start();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-10-31 01:58:12 +01:00
|
|
|
try {
|
|
|
|
await Promise.race([
|
2020-12-04 18:17:57 +01:00
|
|
|
updateStateCalled(),
|
|
|
|
putStateCalled(),
|
2020-10-31 01:58:12 +01:00
|
|
|
new Promise((_, reject) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
setTimeout(() => reject(new Error('TIMEOUT')), SET_STATE_TIMEOUT);
|
2020-10-31 01:58:12 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
assert.fail('Update state should not have been called');
|
2020-10-31 01:58:12 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(error.message === 'TIMEOUT', 'TIMEOUT error should be thrown');
|
2020-10-31 01:58:12 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
it('should not update upon latest block when started and incoming transactions disabled', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController({
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
}),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
// reply with a valid request for any supported network, so that this test has every opportunity to fail
|
2021-03-19 22:54:30 +01:00
|
|
|
nockEtherscanApiForAllChains({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'putState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateCalled = waitUntilCalled(
|
|
|
|
putStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionsController.start();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await Promise.race([
|
2020-12-04 18:17:57 +01:00
|
|
|
updateStateCalled(),
|
|
|
|
putStateCalled(),
|
2020-10-30 15:17:36 +01:00
|
|
|
new Promise((_, reject) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
setTimeout(() => reject(new Error('TIMEOUT')), SET_STATE_TIMEOUT);
|
2020-10-30 15:17:36 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
assert.fail('Update state should not have been called');
|
2020-10-30 15:17:36 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(error.message === 'TIMEOUT', 'TIMEOUT error should be thrown');
|
2020-10-30 15:17:36 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
it('should not update upon latest block when not started', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
// reply with a valid request for any supported network, so that this test has every opportunity to fail
|
2021-03-19 22:54:30 +01:00
|
|
|
nockEtherscanApiForAllChains({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'putState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateCalled = waitUntilCalled(
|
|
|
|
putStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await Promise.race([
|
2020-12-04 18:17:57 +01:00
|
|
|
updateStateCalled(),
|
|
|
|
putStateCalled(),
|
2020-10-30 15:17:36 +01:00
|
|
|
new Promise((_, reject) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
setTimeout(() => reject(new Error('TIMEOUT')), SET_STATE_TIMEOUT);
|
2020-10-30 15:17:36 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
assert.fail('Update state should not have been called');
|
2020-10-30 15:17:36 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(error.message === 'TIMEOUT', 'TIMEOUT error should be thrown');
|
2020-10-30 15:17:36 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
it('should not update upon latest block when stopped', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
// reply with a valid request for any supported network, so that this test has every opportunity to fail
|
2021-03-19 22:54:30 +01:00
|
|
|
nockEtherscanApiForAllChains({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'putState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateCalled = waitUntilCalled(
|
|
|
|
putStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionsController.stop();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await Promise.race([
|
2020-12-04 18:17:57 +01:00
|
|
|
updateStateCalled(),
|
|
|
|
putStateCalled(),
|
2020-10-30 15:17:36 +01:00
|
|
|
new Promise((_, reject) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
setTimeout(() => reject(new Error('TIMEOUT')), SET_STATE_TIMEOUT);
|
2020-10-30 15:17:36 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
assert.fail('Update state should not have been called');
|
2020-10-30 15:17:36 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(error.message === 'TIMEOUT', 'TIMEOUT error should be thrown');
|
2020-10-30 15:17:36 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
it('should update when the selected address changes and on supported network', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const NEW_MOCK_SELECTED_ADDRESS = `${MOCK_SELECTED_ADDRESS}9`;
|
2020-11-03 00:41:28 +01:00
|
|
|
const startBlock = getNonEmptyInitState()
|
2021-03-19 22:54:30 +01:00
|
|
|
.incomingTxLastFetchedBlockByChainId[ROPSTEN_CHAIN_ID];
|
2020-10-30 15:17:36 +01:00
|
|
|
nock('https://api-ropsten.etherscan.io')
|
2020-11-03 00:41:28 +01:00
|
|
|
.get(
|
|
|
|
`/api?module=account&action=txlist&address=${NEW_MOCK_SELECTED_ADDRESS}&tag=latest&page=1&startBlock=${startBlock}`,
|
|
|
|
)
|
2020-10-30 15:17:36 +01:00
|
|
|
.reply(
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction(NEW_MOCK_SELECTED_ADDRESS)],
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const subscription = incomingTransactionsController.preferencesController.store.subscribe.getCall(
|
|
|
|
1,
|
2021-02-04 19:15:23 +01:00
|
|
|
).args[0];
|
2020-10-30 15:17:36 +01:00
|
|
|
// The incoming transactions controller will always skip the first event
|
|
|
|
// We need to call subscription twice to test the event handling
|
|
|
|
// TODO: stop skipping the first event
|
2021-02-04 19:15:23 +01:00
|
|
|
await subscription({ selectedAddress: MOCK_SELECTED_ADDRESS });
|
|
|
|
await subscription({ selectedAddress: NEW_MOCK_SELECTED_ADDRESS });
|
|
|
|
await updateStateCalled();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const actualState = incomingTransactionsController.store.getState();
|
|
|
|
const generatedTxId = actualState?.incomingTransactions?.['0xfake']?.id;
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const actualStateWithoutGenerated = cloneDeep(actualState);
|
|
|
|
delete actualStateWithoutGenerated?.incomingTransactions?.['0xfake']?.id;
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
typeof generatedTxId === 'number' && generatedTxId > 0,
|
|
|
|
'Generated transaction ID should be a positive number',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
actualStateWithoutGenerated,
|
|
|
|
{
|
|
|
|
incomingTransactions: {
|
|
|
|
...getNonEmptyInitState().incomingTransactions,
|
|
|
|
'0xfake': {
|
|
|
|
blockNumber: '10',
|
|
|
|
hash: '0xfake',
|
2021-03-01 16:15:42 +01:00
|
|
|
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
|
|
|
chainId: ROPSTEN_CHAIN_ID,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-10-30 15:17:36 +01:00
|
|
|
time: 16000000000000000,
|
2021-03-10 21:16:44 +01:00
|
|
|
type: TRANSACTION_TYPES.INCOMING,
|
2020-10-30 15:17:36 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0xfake',
|
|
|
|
gas: '0x0',
|
|
|
|
gasPrice: '0x0',
|
|
|
|
nonce: '0x64',
|
|
|
|
to: '0x01019',
|
|
|
|
value: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...getNonEmptyInitState().incomingTxLastFetchedBlockByChainId,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 11,
|
2020-10-30 15:17:36 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'State should have been updated after first block was received',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-10-31 01:58:12 +01:00
|
|
|
it('should not update when the selected address changes and not on supported network', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: { ...getMockBlockTracker() },
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const NEW_MOCK_SELECTED_ADDRESS = `${MOCK_SELECTED_ADDRESS}9`;
|
2020-10-30 15:17:36 +01:00
|
|
|
// reply with a valid request for any supported network, so that this test has every opportunity to fail
|
2021-03-19 22:54:30 +01:00
|
|
|
nockEtherscanApiForAllChains({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction(NEW_MOCK_SELECTED_ADDRESS)],
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'putState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateCalled = waitUntilCalled(
|
|
|
|
putStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const subscription = incomingTransactionsController.preferencesController.store.subscribe.getCall(
|
|
|
|
1,
|
2021-02-04 19:15:23 +01:00
|
|
|
).args[0];
|
2020-10-30 15:17:36 +01:00
|
|
|
// The incoming transactions controller will always skip the first event
|
|
|
|
// We need to call subscription twice to test the event handling
|
|
|
|
// TODO: stop skipping the first event
|
2021-02-04 19:15:23 +01:00
|
|
|
await subscription({ selectedAddress: MOCK_SELECTED_ADDRESS });
|
|
|
|
await subscription({ selectedAddress: NEW_MOCK_SELECTED_ADDRESS });
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-10-31 01:58:12 +01:00
|
|
|
try {
|
|
|
|
await Promise.race([
|
2020-12-04 18:17:57 +01:00
|
|
|
updateStateCalled(),
|
|
|
|
putStateCalled(),
|
2020-10-31 01:58:12 +01:00
|
|
|
new Promise((_, reject) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
setTimeout(() => reject(new Error('TIMEOUT')), SET_STATE_TIMEOUT);
|
2020-10-31 01:58:12 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
assert.fail('Update state should not have been called');
|
2020-10-31 01:58:12 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(error.message === 'TIMEOUT', 'TIMEOUT error should be thrown');
|
2020-10-31 01:58:12 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
|
|
|
it('should update when switching to a supported network', async function () {
|
2021-03-19 22:54:30 +01:00
|
|
|
const mockedNetworkMethods = getMockNetworkControllerMethods(
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...mockedNetworkMethods,
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const startBlock = getNonEmptyInitState()
|
2021-03-19 22:54:30 +01:00
|
|
|
.incomingTxLastFetchedBlockByChainId[ROPSTEN_CHAIN_ID];
|
2020-10-30 15:17:36 +01:00
|
|
|
nock('https://api-ropsten.etherscan.io')
|
2020-11-03 00:41:28 +01:00
|
|
|
.get(
|
|
|
|
`/api?module=account&action=txlist&address=${MOCK_SELECTED_ADDRESS}&tag=latest&page=1&startBlock=${startBlock}`,
|
|
|
|
)
|
2020-10-30 15:17:36 +01:00
|
|
|
.reply(
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const subscription = mockedNetworkMethods.onNetworkDidChange.getCall(0)
|
|
|
|
.args[0];
|
|
|
|
await subscription(ROPSTEN_CHAIN_ID);
|
2021-02-04 19:15:23 +01:00
|
|
|
await updateStateCalled();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const actualState = incomingTransactionsController.store.getState();
|
|
|
|
const generatedTxId = actualState?.incomingTransactions?.['0xfake']?.id;
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const actualStateWithoutGenerated = cloneDeep(actualState);
|
|
|
|
delete actualStateWithoutGenerated?.incomingTransactions?.['0xfake']?.id;
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
typeof generatedTxId === 'number' && generatedTxId > 0,
|
|
|
|
'Generated transaction ID should be a positive number',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
actualStateWithoutGenerated,
|
|
|
|
{
|
|
|
|
incomingTransactions: {
|
|
|
|
...getNonEmptyInitState().incomingTransactions,
|
|
|
|
'0xfake': {
|
|
|
|
blockNumber: '10',
|
|
|
|
hash: '0xfake',
|
2021-03-01 16:15:42 +01:00
|
|
|
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
|
|
|
chainId: ROPSTEN_CHAIN_ID,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-10-30 15:17:36 +01:00
|
|
|
time: 16000000000000000,
|
2021-03-10 21:16:44 +01:00
|
|
|
type: TRANSACTION_TYPES.INCOMING,
|
2020-10-30 15:17:36 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0xfake',
|
|
|
|
gas: '0x0',
|
|
|
|
gasPrice: '0x0',
|
|
|
|
nonce: '0x64',
|
|
|
|
to: '0x0101',
|
|
|
|
value: '0x0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...getNonEmptyInitState().incomingTxLastFetchedBlockByChainId,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 11,
|
2020-10-30 15:17:36 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'State should have been updated after first block was received',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-10-31 01:58:12 +01:00
|
|
|
it('should not update when switching to an unsupported network', async function () {
|
2021-03-19 22:54:30 +01:00
|
|
|
const mockedNetworkMethods = getMockNetworkControllerMethods(
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...mockedNetworkMethods,
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
// reply with a valid request for any supported network, so that this test has every opportunity to fail
|
2021-03-19 22:54:30 +01:00
|
|
|
nockEtherscanApiForAllChains({
|
|
|
|
status: '1',
|
|
|
|
result: [getFakeEtherscanTransaction()],
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'updateState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const updateStateCalled = waitUntilCalled(
|
|
|
|
updateStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateStub = sinon.stub(
|
|
|
|
incomingTransactionsController.store,
|
|
|
|
'putState',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const putStateCalled = waitUntilCalled(
|
|
|
|
putStateStub,
|
|
|
|
incomingTransactionsController.store,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const subscription = mockedNetworkMethods.onNetworkDidChange.getCall(0)
|
|
|
|
.args[0];
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTransactionsController.getCurrentChainId = () => FAKE_CHAIN_ID;
|
2021-02-04 19:15:23 +01:00
|
|
|
await subscription();
|
2020-10-30 15:17:36 +01:00
|
|
|
|
2020-10-31 01:58:12 +01:00
|
|
|
try {
|
|
|
|
await Promise.race([
|
2020-12-04 18:17:57 +01:00
|
|
|
updateStateCalled(),
|
|
|
|
putStateCalled(),
|
2020-10-31 01:58:12 +01:00
|
|
|
new Promise((_, reject) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
setTimeout(() => reject(new Error('TIMEOUT')), SET_STATE_TIMEOUT);
|
2020-10-31 01:58:12 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
assert.fail('Update state should not have been called');
|
2020-10-31 01:58:12 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(error.message === 'TIMEOUT', 'TIMEOUT error should be thrown');
|
2020-10-31 01:58:12 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-08-20 20:52:00 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
describe('_update', function () {
|
|
|
|
describe('when state is empty (initialized)', function () {
|
|
|
|
it('should use provided block number and update the latest block seen', async function () {
|
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getEmptyInitState(),
|
|
|
|
getCurrentChainId: () => ROPSTEN_CHAIN_ID,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
sinon.spy(incomingTransactionsController.store, 'updateState');
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTransactionsController._getNewIncomingTransactions = sinon
|
|
|
|
.stub()
|
|
|
|
.returns([]);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
await incomingTransactionsController._update('fakeAddress', 999);
|
|
|
|
assert(
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions.calledOnce,
|
|
|
|
);
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions.getCall(0)
|
|
|
|
.args,
|
|
|
|
['fakeAddress', 999, ROPSTEN_CHAIN_ID],
|
|
|
|
);
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController.store.updateState.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...EMPTY_BLOCKS_BY_NETWORK,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 1000,
|
|
|
|
},
|
|
|
|
incomingTransactions: {},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should update the last fetched block for network to highest block seen in incoming txs', async function () {
|
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getEmptyInitState(),
|
|
|
|
getCurrentChainId: () => ROPSTEN_CHAIN_ID,
|
|
|
|
},
|
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const NEW_TRANSACTION_ONE = {
|
|
|
|
id: 555,
|
|
|
|
hash: '0xfff',
|
|
|
|
blockNumber: 444,
|
|
|
|
};
|
|
|
|
const NEW_TRANSACTION_TWO = {
|
|
|
|
id: 556,
|
|
|
|
hash: '0xffa',
|
|
|
|
blockNumber: 443,
|
|
|
|
};
|
|
|
|
|
|
|
|
sinon.spy(incomingTransactionsController.store, 'updateState');
|
|
|
|
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions = sinon
|
|
|
|
.stub()
|
|
|
|
.returns([NEW_TRANSACTION_ONE, NEW_TRANSACTION_TWO]);
|
|
|
|
await incomingTransactionsController._update('fakeAddress', 10);
|
|
|
|
|
|
|
|
assert(incomingTransactionsController.store.updateState.calledOnce);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions.getCall(0)
|
|
|
|
.args,
|
|
|
|
['fakeAddress', 10, ROPSTEN_CHAIN_ID],
|
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController.store.updateState.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...EMPTY_BLOCKS_BY_NETWORK,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 445,
|
|
|
|
},
|
|
|
|
incomingTransactions: {
|
|
|
|
[NEW_TRANSACTION_ONE.hash]: NEW_TRANSACTION_ONE,
|
|
|
|
[NEW_TRANSACTION_TWO.hash]: NEW_TRANSACTION_TWO,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-03-19 22:54:30 +01:00
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
describe('when state is populated with prior data for network', function () {
|
|
|
|
it('should use the last fetched block for the current network and increment by 1 in state', async function () {
|
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
getCurrentChainId: () => ROPSTEN_CHAIN_ID,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
sinon.spy(incomingTransactionsController.store, 'updateState');
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions = sinon
|
|
|
|
.stub()
|
|
|
|
.returns([]);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
await incomingTransactionsController._update('fakeAddress', 999);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert(
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions.calledOnce,
|
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions.getCall(0)
|
|
|
|
.args,
|
|
|
|
['fakeAddress', 4, ROPSTEN_CHAIN_ID],
|
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController.store.updateState.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...PREPOPULATED_BLOCKS_BY_NETWORK,
|
|
|
|
[ROPSTEN_CHAIN_ID]:
|
|
|
|
PREPOPULATED_BLOCKS_BY_NETWORK[ROPSTEN_CHAIN_ID] + 1,
|
|
|
|
},
|
|
|
|
incomingTransactions: PREPOPULATED_INCOMING_TXS_BY_HASH,
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should update the last fetched block for network to highest block seen in incoming txs', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
2021-03-19 22:54:30 +01:00
|
|
|
getCurrentChainId: () => ROPSTEN_CHAIN_ID,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const NEW_TRANSACTION_ONE = {
|
|
|
|
id: 555,
|
|
|
|
hash: '0xfff',
|
|
|
|
blockNumber: 444,
|
|
|
|
};
|
|
|
|
const NEW_TRANSACTION_TWO = {
|
|
|
|
id: 556,
|
|
|
|
hash: '0xffa',
|
|
|
|
blockNumber: 443,
|
|
|
|
};
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.spy(incomingTransactionsController.store, 'updateState');
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTransactionsController._getNewIncomingTransactions = sinon
|
|
|
|
.stub()
|
|
|
|
.returns([NEW_TRANSACTION_ONE, NEW_TRANSACTION_TWO]);
|
|
|
|
await incomingTransactionsController._update('fakeAddress', 10);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(incomingTransactionsController.store.updateState.calledOnce);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
incomingTransactionsController._getNewIncomingTransactions.getCall(0)
|
|
|
|
.args,
|
|
|
|
['fakeAddress', 4, ROPSTEN_CHAIN_ID],
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
incomingTransactionsController.store.updateState.getCall(0).args[0],
|
|
|
|
{
|
2021-03-19 22:54:30 +01:00
|
|
|
incomingTxLastFetchedBlockByChainId: {
|
|
|
|
...PREPOPULATED_BLOCKS_BY_NETWORK,
|
|
|
|
[ROPSTEN_CHAIN_ID]: 445,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
|
|
|
incomingTransactions: {
|
2021-03-19 22:54:30 +01:00
|
|
|
...PREPOPULATED_INCOMING_TXS_BY_HASH,
|
|
|
|
[NEW_TRANSACTION_ONE.hash]: NEW_TRANSACTION_ONE,
|
|
|
|
[NEW_TRANSACTION_TWO.hash]: NEW_TRANSACTION_TWO,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2019-08-16 20:54:10 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
describe('_getNewIncomingTransactions', function () {
|
|
|
|
const ADDRESS_TO_FETCH_FOR = '0xfakeaddress';
|
|
|
|
const FETCHED_TX = getFakeEtherscanTransaction(ADDRESS_TO_FETCH_FOR);
|
2020-11-03 00:41:28 +01:00
|
|
|
const mockFetch = sinon.stub().returns(
|
|
|
|
Promise.resolve({
|
2021-03-19 22:54:30 +01:00
|
|
|
json: () => Promise.resolve({ status: '1', result: [FETCHED_TX] }),
|
2020-11-03 00:41:28 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
let tempFetch;
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
tempFetch = window.fetch;
|
|
|
|
window.fetch = mockFetch;
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
window.fetch = tempFetch;
|
|
|
|
mockFetch.resetHistory();
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should call fetch with the expected url when passed an address, block number and supported chainId', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
await incomingTransactionsController._getNewIncomingTransactions(
|
|
|
|
ADDRESS_TO_FETCH_FOR,
|
2020-11-03 00:41:28 +01:00
|
|
|
'789',
|
|
|
|
ROPSTEN_CHAIN_ID,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(mockFetch.calledOnce);
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
mockFetch.getCall(0).args[0],
|
|
|
|
`https://api-${ROPSTEN}.etherscan.io/api?module=account&action=txlist&address=0xfakeaddress&tag=latest&page=1&startBlock=789`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should call fetch with the expected url when passed an address, block number and MAINNET chainId', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(MAINNET_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
await incomingTransactionsController._getNewIncomingTransactions(
|
|
|
|
ADDRESS_TO_FETCH_FOR,
|
2020-11-03 00:41:28 +01:00
|
|
|
'789',
|
|
|
|
MAINNET_CHAIN_ID,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(mockFetch.calledOnce);
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
mockFetch.getCall(0).args[0],
|
|
|
|
`https://api.etherscan.io/api?module=account&action=txlist&address=0xfakeaddress&tag=latest&page=1&startBlock=789`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should call fetch with the expected url when passed an address and supported chainId, but a falsy block number', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
await incomingTransactionsController._getNewIncomingTransactions(
|
|
|
|
ADDRESS_TO_FETCH_FOR,
|
2020-11-03 00:41:28 +01:00
|
|
|
null,
|
|
|
|
ROPSTEN_CHAIN_ID,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(mockFetch.calledOnce);
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
mockFetch.getCall(0).args[0],
|
|
|
|
`https://api-${ROPSTEN}.etherscan.io/api?module=account&action=txlist&address=0xfakeaddress&tag=latest&page=1`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should return an array of normalized transactions', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const result = await incomingTransactionsController._getNewIncomingTransactions(
|
|
|
|
ADDRESS_TO_FETCH_FOR,
|
2020-11-03 00:41:28 +01:00
|
|
|
'789',
|
|
|
|
ROPSTEN_CHAIN_ID,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(mockFetch.calledOnce);
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(result, [
|
|
|
|
incomingTransactionsController._normalizeTxFromEtherscan(
|
|
|
|
FETCHED_TX,
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
),
|
|
|
|
]);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should return empty tx array if status is 0', async function () {
|
|
|
|
const mockFetchStatusZero = sinon.stub().returns(
|
|
|
|
Promise.resolve({
|
|
|
|
json: () => Promise.resolve({ status: '0', result: [FETCHED_TX] }),
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-03-19 22:54:30 +01:00
|
|
|
const tempFetchStatusZero = window.fetch;
|
|
|
|
window.fetch = mockFetchStatusZero;
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const result = await incomingTransactionsController._getNewIncomingTransactions(
|
|
|
|
ADDRESS_TO_FETCH_FOR,
|
|
|
|
'789',
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
);
|
|
|
|
assert.deepStrictEqual(result, []);
|
|
|
|
window.fetch = tempFetchStatusZero;
|
|
|
|
mockFetchStatusZero.reset();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
it('should return empty tx array if result array is empty', async function () {
|
|
|
|
const mockFetchEmptyResult = sinon.stub().returns(
|
|
|
|
Promise.resolve({
|
|
|
|
json: () => Promise.resolve({ status: '1', result: [] }),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
const tempFetchEmptyResult = window.fetch;
|
|
|
|
window.fetch = mockFetchEmptyResult;
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
const result = await incomingTransactionsController._getNewIncomingTransactions(
|
|
|
|
ADDRESS_TO_FETCH_FOR,
|
|
|
|
'789',
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
);
|
|
|
|
assert.deepStrictEqual(result, []);
|
|
|
|
window.fetch = tempFetchEmptyResult;
|
|
|
|
mockFetchEmptyResult.reset();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('_normalizeTxFromEtherscan', function () {
|
|
|
|
it('should return the expected data when the tx is in error', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const result = incomingTransactionsController._normalizeTxFromEtherscan(
|
|
|
|
{
|
|
|
|
timeStamp: '4444',
|
|
|
|
isError: '1',
|
|
|
|
blockNumber: 333,
|
|
|
|
from: '0xa',
|
|
|
|
gas: '11',
|
|
|
|
gasPrice: '12',
|
|
|
|
nonce: '13',
|
|
|
|
to: '0xe',
|
|
|
|
value: '15',
|
|
|
|
hash: '0xg',
|
|
|
|
},
|
|
|
|
ROPSTEN_CHAIN_ID,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(result, {
|
2019-08-16 20:54:10 +02:00
|
|
|
blockNumber: 333,
|
|
|
|
id: 54321,
|
2020-10-31 01:58:12 +01:00
|
|
|
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId: ROPSTEN_CHAIN_ID,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.FAILED,
|
2019-08-16 20:54:10 +02:00
|
|
|
time: 4444000,
|
|
|
|
txParams: {
|
|
|
|
from: '0xa',
|
|
|
|
gas: '0xb',
|
|
|
|
gasPrice: '0xc',
|
|
|
|
nonce: '0xd',
|
|
|
|
to: '0xe',
|
|
|
|
value: '0xf',
|
|
|
|
},
|
|
|
|
hash: '0xg',
|
2021-03-10 21:16:44 +01:00
|
|
|
type: TRANSACTION_TYPES.INCOMING,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the expected data when the tx is not in error', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const incomingTransactionsController = new IncomingTransactionsController(
|
|
|
|
{
|
|
|
|
blockTracker: getMockBlockTracker(),
|
2021-03-19 22:54:30 +01:00
|
|
|
...getMockNetworkControllerMethods(ROPSTEN_CHAIN_ID),
|
2020-11-03 00:41:28 +01:00
|
|
|
preferencesController: getMockPreferencesController(),
|
|
|
|
initState: getNonEmptyInitState(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const result = incomingTransactionsController._normalizeTxFromEtherscan(
|
|
|
|
{
|
|
|
|
timeStamp: '4444',
|
|
|
|
isError: '0',
|
|
|
|
blockNumber: 333,
|
|
|
|
from: '0xa',
|
|
|
|
gas: '11',
|
|
|
|
gasPrice: '12',
|
|
|
|
nonce: '13',
|
|
|
|
to: '0xe',
|
|
|
|
value: '15',
|
|
|
|
hash: '0xg',
|
|
|
|
},
|
|
|
|
ROPSTEN_CHAIN_ID,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-08-16 20:54:10 +02:00
|
|
|
|
2021-03-19 22:54:30 +01:00
|
|
|
assert.deepStrictEqual(result, {
|
2019-08-16 20:54:10 +02:00
|
|
|
blockNumber: 333,
|
|
|
|
id: 54321,
|
2020-10-31 01:58:12 +01:00
|
|
|
metamaskNetworkId: ROPSTEN_NETWORK_ID,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId: ROPSTEN_CHAIN_ID,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2019-08-16 20:54:10 +02:00
|
|
|
time: 4444000,
|
|
|
|
txParams: {
|
|
|
|
from: '0xa',
|
|
|
|
gas: '0xb',
|
|
|
|
gasPrice: '0xc',
|
|
|
|
nonce: '0xd',
|
|
|
|
to: '0xe',
|
|
|
|
value: '0xf',
|
|
|
|
},
|
|
|
|
hash: '0xg',
|
2021-03-10 21:16:44 +01:00
|
|
|
type: TRANSACTION_TYPES.INCOMING,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|