Skip to content

Commit

Permalink
fix: missing scopes in test + force type in migration 105
Browse files Browse the repository at this point in the history
  • Loading branch information
ccharly committed Jan 7, 2025
1 parent 57e5b2d commit 1385544
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/scripts/controllers/alert-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe('AlertController', () => {
address: '0x1234567',
options: {},
methods: [],
scopes: ['eip155'],
type: 'eip155:eoa',
metadata: {
name: '',
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/snap-keyring/snap-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const mockAccount = {
id: '3afa663e-0600-4d93-868a-61c2e553013b',
address,
methods: [],
scopes: ['eip155'],
options: {},
};
const mockInternalAccount = {
Expand Down
9 changes: 1 addition & 8 deletions app/scripts/migrations/105.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { v4 as uuid } from 'uuid';
import { sha256FromString } from 'ethereumjs-util';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { ETH_EOA_METHODS } from '../../../shared/constants/eth-methods';
import { migrate } from './105';
import { migrate, Identity, InternalAccount } from './105';

Check failure on line 4 in app/scripts/migrations/105.test.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Module '"./105"' declares 'Identity' locally, but it is not exported.

Check failure on line 4 in app/scripts/migrations/105.test.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Module '"./105"' declares 'InternalAccount' locally, but it is not exported.

const MOCK_ADDRESS = '0x0';
const MOCK_ADDRESS_2 = '0x1';
Expand All @@ -22,12 +21,6 @@ function addressToUUID(address: string): string {
});
}

type Identity = {
name: string;
address: string;
lastSelected?: number;
};

type Identities = {
[key: string]: Identity;
};
Expand Down
24 changes: 23 additions & 1 deletion app/scripts/migrations/105.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EthAccountType } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { sha256FromString } from 'ethereumjs-util';
import { v4 as uuid } from 'uuid';
import { cloneDeep } from 'lodash';
import { Json } from '@metamask/utils';
import { ETH_EOA_METHODS } from '../../../shared/constants/eth-methods';

type VersionedData = {
Expand All @@ -16,6 +16,28 @@ type Identity = {
lastSelected?: number;
};

type InternalAccount = {
type: string;
id: string;
options: Record<string, Json>;
metadata: {
name: string;
importTime: number;
keyring: {
type: string;
};
nameLastUpdatedAt?: number;
snap?: {
name: string;
id: string;
enabled: boolean;
};
lastSelected?: number;
};
address: string;
methods: string[];
};

export const version = 105;

/**
Expand Down
7 changes: 7 additions & 0 deletions test/data/mock-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
EthAccountType,
BtcMethod,
BtcAccountType,
EthScopes,
BtcScopes,
} from '@metamask/keyring-api';
import {
ETH_EOA_METHODS,
Expand All @@ -15,6 +17,7 @@ export const MOCK_ACCOUNT_EOA: InternalAccount = {
address: '0x123',
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
metadata: {
name: 'Account 1',
Expand All @@ -29,6 +32,8 @@ export const MOCK_ACCOUNT_ERC4337: InternalAccount = {
address: '0x123',
options: {},
methods: ETH_EOA_METHODS.concat(ETH_4337_METHODS),
// Smart accounts might not be available on every EVM chains, but that's ok for mock purposes.
scopes: [EthScopes.Namespace],
type: EthAccountType.Erc4337,
metadata: {
name: 'Account 2',
Expand All @@ -43,6 +48,7 @@ export const MOCK_ACCOUNT_BIP122_P2WPKH: InternalAccount = {
address: 'bc1qwl8399fz829uqvqly9tcatgrgtwp3udnhxfq4k',
options: {},
methods: [BtcMethod.SendBitcoin],
scopes: [BtcScopes.Mainnet],
type: BtcAccountType.P2wpkh,
metadata: {
name: 'Bitcoin Account',
Expand All @@ -57,6 +63,7 @@ export const MOCK_ACCOUNT_BIP122_P2WPKH_TESTNET: InternalAccount = {
address: 'tb1q6rmsq3vlfdhjdhtkxlqtuhhlr6pmj09y6w43g8',
options: {},
methods: [BtcMethod.SendBitcoin],
scopes: [BtcScopes.Testnet],
type: BtcAccountType.P2wpkh,
metadata: {
name: 'Bitcoin Testnet Account',
Expand Down
6 changes: 6 additions & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@
"eth_signTypedData_v3",
"eth_signTypedData_v4"
],
"scopes": ["eip155"],
"type": "eip155:eoa"
},
"07c2cfec-36c9-46c4-8115-3836d3ac9047": {
Expand All @@ -468,6 +469,7 @@
"eth_signTypedData_v3",
"eth_signTypedData_v4"
],
"scopes": ["eip155"],
"type": "eip155:eoa"
},
"15e69915-2a1a-4019-93b3-916e11fd432f": {
Expand All @@ -488,6 +490,7 @@
"eth_signTypedData_v3",
"eth_signTypedData_v4"
],
"scopes": ["eip155"],
"type": "eip155:eoa"
},
"784225f4-d30b-4e77-a900-c8bbce735b88": {
Expand All @@ -508,6 +511,7 @@
"eth_signTypedData_v3",
"eth_signTypedData_v4"
],
"scopes": ["eip155"],
"type": "eip155:eoa"
},
"694225f4-d30b-4e77-a900-c8bbce735b42": {
Expand All @@ -528,6 +532,7 @@
"eth_signTypedData_v3",
"eth_signTypedData_v4"
],
"scopes": ["eip155"],
"type": "eip155:eoa"
},
"c3deeb99-ba0d-4a4e-a0aa-033fc1f79ae3": {
Expand All @@ -553,6 +558,7 @@
"eth_signTypedData_v3",
"eth_signTypedData_v4"
],
"scopes": ["eip155"],
"type": "eip155:eoa"
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import configureStore from 'redux-mock-store';
import { EthAccountType, EthMethod } from '@metamask/keyring-api';
import { EthAccountType, EthMethod, EthScopes } from '@metamask/keyring-api';
import { fireEvent, renderWithProvider } from '../../../../test/jest';
import { mockNetworkState } from '../../../../test/stub/networks';
import { CHAIN_IDS } from '../../../../shared/constants/network';
Expand Down Expand Up @@ -45,6 +45,7 @@ describe('PermissionDetailsModal', () => {
},
options: {},
methods: [...Object.values(EthMethod)],
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
},
'07c2cfec-36c9-46c4-8115-3836d3ac9047': {
Expand All @@ -61,6 +62,7 @@ describe('PermissionDetailsModal', () => {
},
options: {},
methods: [...Object.values(EthMethod)],
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
},
},
Expand Down Expand Up @@ -128,6 +130,7 @@ describe('PermissionDetailsModal', () => {
},
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
label: '',
},
Expand Down
3 changes: 2 additions & 1 deletion ui/selectors/accounts.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EthAccountType } from '@metamask/keyring-api';
import { EthAccountType, EthScopes } from '@metamask/keyring-api';
import { ETH_EOA_METHODS } from '../../shared/constants/eth-methods';
import {
MOCK_ACCOUNTS,
Expand Down Expand Up @@ -88,6 +88,7 @@ describe('Accounts Selectors', () => {
},
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
};
expect(
Expand Down

0 comments on commit 1385544

Please sign in to comment.