Skip to content

Commit

Permalink
Merge branch 'develop' into migrate-test-unit-global-to-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyoboieltr committed Jul 25, 2024
2 parents 13c04d6 + 51410b2 commit 060d93c
Show file tree
Hide file tree
Showing 30 changed files with 1,046 additions and 123 deletions.
17 changes: 0 additions & 17 deletions .github/actions/setup-environment/action.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ async function main(): Promise<void> {
// We can't use "GITHUB_TOKEN" here, as its permissions are scoped to the repository where the action is running.
// "GITHUB_TOKEN" does not have access to other repositories, even when they belong to the same organization.
// As we want to get files which are not necessarily located in the same repository,
// we need to create our own "RELEASE_LABEL_TOKEN" with "repo" permissions.
// we need to create our own "PERSONAL_ACCESS_TOKEN" with "repo" permissions.
// Such a token allows to access other repositories of the MetaMask organisation.
const personalAccessToken = process.env.RELEASE_LABEL_TOKEN;
const personalAccessToken = process.env.PERSONAL_ACCESS_TOKEN;
if (!personalAccessToken) {
core.setFailed('RELEASE_LABEL_TOKEN not found');
core.setFailed('PERSONAL_ACCESS_TOKEN not found');
process.exit(1);
}

Expand Down
33 changes: 4 additions & 29 deletions .github/workflows/add-team-label.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Add team label to PR when it is opened
name: Add team label

on:
pull_request:
Expand All @@ -7,31 +7,6 @@ on:

jobs:
add-team-label:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- run: corepack enable

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # This is needed to checkout all branches

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn

- name: Install dependencies
run: yarn --immutable

- name: Add team label to PR
id: add-team-label-to-pr
env:
RELEASE_LABEL_TOKEN: ${{ secrets.RELEASE_LABEL_TOKEN }}
run: yarn run add-team-label-to-pr
uses: metamask/github-tools/.github/workflows/add-team-label.yml@main
secrets:
PERSONAL_ACCESS_TOKEN: ${{ secrets.RELEASE_LABEL_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/run-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup environment
uses: ./.github/actions/setup-environment
uses: metamask/github-tools/.github/actions/setup-environment@main

- name: test:integration:coverage
run: yarn test:integration:coverage
2 changes: 1 addition & 1 deletion .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup environment
uses: ./.github/actions/setup-environment
uses: metamask/github-tools/.github/actions/setup-environment@main

- name: test:unit:coverage
run: yarn test:unit:coverage --shard=${{ matrix.shard }}/${{ strategy.job-total }}
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/lib/accounts/BalancesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import { BalancesTracker } from './BalancesTracker';
const mockBtcAccount = createMockInternalAccount({
address: '',
name: 'Btc Account',
// @ts-expect-error - account type may be btc or eth, mock file is not typed
type: BtcAccountType.P2wpkh,
// @ts-expect-error - snap options is not typed and defaults to undefined
snapOptions: {
id: 'mock-btc-snap',
name: 'mock-btc-snap',
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/lib/accounts/BalancesTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const MOCK_TIMESTAMP = 1709983353;
const mockBtcAccount = createMockInternalAccount({
address: '',
name: 'Btc Account',
// @ts-expect-error - account type may be btc or eth, mock file is not typed
type: BtcAccountType.P2wpkh,
// @ts-expect-error - snap options is not typed and defaults to undefined
snapOptions: {
id: 'mock-btc-snap',
name: 'mock-btc-snap',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"generate-beta-commit": "node ./development/generate-beta-commit.js",
"validate-branch-name": "validate-branch-name",
"add-release-label-to-pr-and-linked-issues": "ts-node ./.github/scripts/add-release-label-to-pr-and-linked-issues.ts",
"add-team-label-to-pr": "ts-node ./.github/scripts/add-team-label-to-pr.ts",
"add-team-label": "ts-node ./.github/scripts/add-team-label.ts",
"check-pr-has-required-labels": "ts-node ./.github/scripts/check-pr-has-required-labels.ts",
"close-release-bug-report-issue": "ts-node ./.github/scripts/close-release-bug-report-issue.ts",
"check-template-and-add-labels": "ts-node ./.github/scripts/check-template-and-add-labels.ts",
Expand Down
8 changes: 8 additions & 0 deletions shared/constants/custody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum AccountType {
CUSTODY = 'custody',
}

export enum CustodyStatus {
CREATED = 'created',
ABORTED = 'aborted',
}
9 changes: 1 addition & 8 deletions test/e2e/flask/btc/btc-dapp-connection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import {
withFixtures,
Expand Down Expand Up @@ -32,15 +31,9 @@ describe('BTC Account - Dapp Connection', function (this: Suite) {
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

const account2 = await driver.waitForSelector(
await driver.assertElementNotPresent(
'[data-testid="choose-account-list-1"]',
);
assert((await account2.getText()).includes('Bitcoin Ac...'));
await account2.click();
const nextButton = await driver.waitForSelector(
'[data-testid="page-container-footer-next"]',
);
assert.equal(await nextButton.isEnabled(), false);
},
);
});
Expand Down
22 changes: 19 additions & 3 deletions test/jest/mocks.js → test/jest/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
EthMethod,
BtcMethod,
BtcAccountType,
InternalAccount,
} from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
import { v4 as uuidv4 } from 'uuid';
Expand All @@ -11,6 +12,7 @@ import {
draftTransactionInitialState,
initialState,
} from '../../ui/ducks/send';
import { MetaMaskReduxState } from '../../ui/store/store';

export const MOCK_DEFAULT_ADDRESS =
'0xd5e099c71b797516c10ed0f0d895f429c2781111';
Expand Down Expand Up @@ -131,7 +133,9 @@ export const INITIAL_SEND_STATE_FOR_EXISTING_DRAFT = {
},
};

export const getInitialSendStateWithExistingTxState = (draftTxState) => ({
// TODO: Define the type of draftTxState
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const getInitialSendStateWithExistingTxState = (draftTxState: any) => ({
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
draftTransactions: {
'test-uuid': {
Expand Down Expand Up @@ -171,11 +175,21 @@ export const getInitialSendStateWithExistingTxState = (draftTxState) => ({
});

export function createMockInternalAccount({
name = 'Account 1',
address = MOCK_DEFAULT_ADDRESS,
name,
type = EthAccountType.Eoa,
keyringType = KeyringTypes.hd,
snapOptions = undefined,
}: {
name?: string;
address?: string;
type?: string;
keyringType?: string;
snapOptions?: {
enabled: boolean;
name: string;
id: string;
};
} = {}) {
let methods;

Expand Down Expand Up @@ -221,7 +235,9 @@ export function createMockInternalAccount({
};
}

export const getSelectedInternalAccountFromMockState = (state) => {
export const getSelectedInternalAccountFromMockState = (
state: MetaMaskReduxState,
): InternalAccount => {
return state.metamask.internalAccounts.accounts[
state.metamask.internalAccounts.selectedAccount
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const mockAccount = createMockInternalAccount({
const mockNonEvmAccount = createMockInternalAccount({
name: 'Account 1',
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
// @ts-expect-error type not defined in js file
type: BtcAccountType.P2wpkh,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SECOND } from '../../../../shared/constants/time';
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
import { AccountType } from '../../../../shared/constants/custody';
import CustodyLabels from '../../institutional/custody-labels/custody-labels';
///: END:ONLY_INCLUDE_IF
import { Icon, IconName, IconSize, Text } from '../../component-library';
Expand Down Expand Up @@ -81,7 +82,7 @@ class SelectedAccount extends Component {

const showCustodyLabels =
getEnvironmentType() !== ENVIRONMENT_TYPE_POPUP &&
accountType === 'custody' &&
accountType === AccountType.CUSTODY &&
custodyLabels;

const tooltipText = this.state.copied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { TransactionStatus } from '@metamask/transaction-controller';
import Tooltip from '../../ui/tooltip';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { TransactionGroupStatus } from '../../../../shared/constants/transaction';
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
import { CustodyStatus } from '../../../../shared/constants/custody';
///: END:ONLY_INCLUDE_IF

const QUEUED_PSEUDO_STATUS = 'queued';
const SIGNING_PSUEDO_STATUS = 'signing';
Expand Down Expand Up @@ -84,7 +87,7 @@ export default function TransactionStatusLabel({
if (error) {
tooltipText = error.message;
statusText =
custodyStatus === 'aborted'
custodyStatus === CustodyStatus.ABORTED
? custodyStatusDisplayText
: t('snapResultError');
} else {
Expand Down
Loading

0 comments on commit 060d93c

Please sign in to comment.