Skip to content

Commit

Permalink
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
Browse files Browse the repository at this point in the history
…k-meta
  • Loading branch information
jiexi authored Sep 22, 2023
2 parents dc5436a + 5f368d5 commit 0b5aaf7
Show file tree
Hide file tree
Showing 70 changed files with 1,333 additions and 1,105 deletions.
105 changes: 105 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ workflows:
- prep-build-test-flask:
requires:
- prep-deps
- prep-build-test-mmi:
requires:
- prep-deps
- prep-build-storybook:
requires:
- prep-deps
Expand Down Expand Up @@ -162,6 +165,12 @@ workflows:
- test-e2e-firefox-snaps-flask:
requires:
- prep-build-test-flask
- test-e2e-chrome-mmi:
requires:
- prep-build-test-mmi
- test-e2e-chrome-rpc-mmi:
requires:
- prep-build-test-mmi
- test-e2e-chrome-mv3:
requires:
- prep-build-test-mv3
Expand Down Expand Up @@ -248,6 +257,8 @@ workflows:
- test-e2e-firefox-snaps
- test-e2e-chrome-snaps-flask
- test-e2e-firefox-snaps-flask
- test-e2e-chrome-mmi
- test-e2e-chrome-rpc-mmi
- test-storybook
- benchmark:
requires:
Expand Down Expand Up @@ -579,6 +590,27 @@ jobs:
- dist-test-flask
- builds-test-flask

prep-build-test-mmi:
executor: node-browsers-medium-plus
steps:
- run: *shallow-git-clone
- attach_workspace:
at: .
- run:
name: Build extension for testing
command: yarn build:test:mmi
- run:
name: Move test build to 'dist-test' to avoid conflict with production build
command: mv ./dist ./dist-test-mmi
- run:
name: Move test zips to 'builds-test' to avoid conflict with production build
command: mv ./builds ./builds-test-mmi
- persist_to_workspace:
root: .
paths:
- dist-test-mmi
- builds-test-mmi

prep-build-test-mv3:
executor: node-browsers-medium-plus
steps:
Expand Down Expand Up @@ -855,6 +887,42 @@ jobs:
- store_test_results:
path: test/test-results/e2e.xml

test-e2e-chrome-rpc-mmi:
executor: node-browsers
steps:
- checkout
- run:
name: Re-Install Chrome
command: ./.circleci/scripts/chrome-install.sh
- attach_workspace:
at: .
- run:
name: Move test build to dist
command: mv ./dist-test-mmi ./dist
- run:
name: Move test zips to builds
command: mv ./builds-test-mmi ./builds
- run:
name: test:e2e:chrome:rpc
command: |
if .circleci/scripts/test-run-e2e.sh
then
yarn test:e2e:chrome:rpc --retries 2 --debug --build-type=mmi
fi
no_output_timeout: 20m
- run:
name: Merge JUnit report
command: |
if [ "$(ls -A test/test-results/e2e)" ]; then
yarn test:e2e:report
fi
when: always
- store_artifacts:
path: test-artifacts
destination: test-artifacts
- store_test_results:
path: test/test-results/e2e.xml

test-e2e-firefox-snaps:
executor: node-browsers
parallelism: 4
Expand Down Expand Up @@ -1003,6 +1071,43 @@ jobs:
- store_test_results:
path: test/test-results/e2e.xml

test-e2e-chrome-mmi:
executor: node-browsers
parallelism: 4
steps:
- run: *shallow-git-clone
- run:
name: Re-Install Chrome
command: ./.circleci/scripts/chrome-install.sh
- attach_workspace:
at: .
- run:
name: Move test build to dist
command: mv ./dist-test-mmi ./dist
- run:
name: Move test zips to builds
command: mv ./builds-test-mmi ./builds
- run:
name: test:e2e:chrome:mmi
command: |
if .circleci/scripts/test-run-e2e.sh
then
yarn test:e2e:chrome:mmi --retries 2 --debug --build-type=mmi
fi
no_output_timeout: 20m
- run:
name: Merge JUnit report
command: |
if [ "$(ls -A test/test-results/e2e)" ]; then
yarn test:e2e:report
fi
when: always
- store_artifacts:
path: test-artifacts
destination: test-artifacts
- store_test_results:
path: test/test-results/e2e.xml

test-e2e-firefox:
executor: node-browsers-medium-plus
parallelism: 8
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ Single e2e tests can be run with `yarn test:e2e:single test/e2e/tests/TEST_NAME.
For example, to run the `account-details` tests using Chrome, with debug logging and with the browser set to remain open upon failure, you would use:
`yarn test:e2e:single test/e2e/tests/account-details.spec.js --browser=chrome --debug --leave-running`

#### Running specific builds types e2e test

Differnt build types have different e2e tests sets. In order to run them look in the `packaje.json` file. You will find:
```console
"test:e2e:chrome:mmi": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js --mmi",
"test:e2e:chrome:snaps": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js --snaps",
"test:e2e:chrome:mv3": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js --mv3",
```
Note: MMI runs a subset of MetaMask's e2e tests. To facilitate this, we have appended the `@no-mmi` tags to the names of those tests that are not applicable to this build type.

### Changing dependencies

Whenever you change dependencies (adding, removing, or updating, either in `package.json` or `yarn.lock`), there are various files that must be kept up-to-date.
Expand Down
3 changes: 0 additions & 3 deletions app/_locales/de/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/es/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/fr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/hi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/id/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ja/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ko/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/pt/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ru/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/tl/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/tr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/vi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/zh_CN/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,9 @@ export default class TransactionController extends EventEmitter {
const currentTransactions = this.store.getState().transactions || {};

const incomingTransactions = transactions
.filter((tx) => !this._hasTransactionHash(tx.hash, currentTransactions))
.filter((tx) =>
this._hasNoDuplicateIncoming(tx.hash, currentTransactions),
)
.reduce((result, tx) => {
result[tx.id] = tx;
return result;
Expand All @@ -2809,8 +2811,21 @@ export default class TransactionController extends EventEmitter {
this.store.updateState({ lastFetchedBlockNumbers });
}

_hasTransactionHash(hash, transactions) {
return Object.values(transactions).some((tx) => tx.hash === hash);
/**
* This function checks if there is not any transaction in the provided
* transactions object that has the same hash as the provided txHash and has a
* type of 'incoming'.
*
* @param {string} txHash - The transaction hash to compare with.
* @param {object} transactions - The transactions to check in.
* @returns {boolean} Returns false if there is a transaction that has the
* same hash as the provided txHash and has a type of 'incoming'. Otherwise,
* it returns true.
*/
_hasNoDuplicateIncoming(txHash, transactions) {
return !Object.values(transactions).some(
(tx) => tx.hash === txHash && tx.type === TransactionType.incoming,
);
}

// Approvals
Expand Down
31 changes: 27 additions & 4 deletions app/scripts/controllers/transactions/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3426,13 +3426,34 @@ describe('Transaction Controller', function () {
});
});

it('ignores new transactions if hash matches existing transaction', async function () {
const existingTransaction = TRANSACTION_META_MOCK;
const incomingTransaction1 = { ...TRANSACTION_META_MOCK, id: 2 };
const incomingTransaction2 = { ...TRANSACTION_META_MOCK, id: 3 };
it('ignores new transactions if hash matches existing incoming transaction', async function () {
const existingTransaction = {
...TRANSACTION_META_MOCK,
id: 1,
type: TransactionType.incoming,
};
const existingTransaction2 = {
...TRANSACTION_META_MOCK,
id: 2,
hash: '0xNewHash',
type: TransactionType.simpleSend,
};

const incomingTransaction1 = {
...TRANSACTION_META_MOCK,
id: 3,
type: TransactionType.incoming,
};
const incomingTransaction2 = {
...TRANSACTION_META_MOCK,
id: 4,
hash: '0xNewHash',
type: TransactionType.incoming,
};

txController.store.getState().transactions = {
[existingTransaction.id]: existingTransaction,
[existingTransaction2.id]: existingTransaction2,
};

await incomingTransactionHelperEventMock.firstCall.args[1]({
Expand All @@ -3442,6 +3463,8 @@ describe('Transaction Controller', function () {

assert.deepEqual(txController.store.getState().transactions, {
[existingTransaction.id]: existingTransaction,
[existingTransaction2.id]: existingTransaction2,
[incomingTransaction2.id]: incomingTransaction2,
});
});
});
Expand Down
Loading

0 comments on commit 0b5aaf7

Please sign in to comment.