Skip to content

Commit

Permalink
fix: fix tests (missing scopes)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccharly committed Jan 6, 2025
1 parent e7409ab commit fd50073
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
34 changes: 26 additions & 8 deletions packages/accounts-controller/src/AccountsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
EthAccountType,
BtcMethod,
EthMethod,
EthScopes,
BtcScopes,
} from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
import type {
Expand Down Expand Up @@ -66,6 +68,7 @@ const mockAccount: InternalAccount = {
options: {},
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
scopes: [EthScopes.Namespace],
metadata: {
name: 'Account 1',
keyring: { type: KeyringTypes.hd },
Expand All @@ -81,6 +84,7 @@ const mockAccount2: InternalAccount = {
options: {},
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
scopes: [EthScopes.Namespace],
metadata: {
name: 'Account 2',
keyring: { type: KeyringTypes.hd },
Expand All @@ -95,6 +99,7 @@ const mockAccount3: InternalAccount = {
options: {},
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
scopes: [EthScopes.Namespace],
metadata: {
name: '',
keyring: { type: KeyringTypes.snap },
Expand All @@ -114,6 +119,7 @@ const mockAccount4: InternalAccount = {
options: {},
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
scopes: [EthScopes.Namespace],
metadata: {
name: 'Custom Name',
keyring: { type: KeyringTypes.snap },
Expand Down Expand Up @@ -191,24 +197,36 @@ function createExpectedInternalAccount({
lastSelected?: number;
nameLastUpdatedAt?: number;
}): InternalAccount {
const accountTypeToMethods = {
[`${EthAccountType.Eoa}`]: [...Object.values(ETH_EOA_METHODS)],
const accountTypeToInfo: Record<
string,
{ methods: string[]; scopes: string[] }
> = {
[`${EthAccountType.Eoa}`]: {
methods: [...Object.values(ETH_EOA_METHODS)],
scopes: [EthScopes.Namespace],
},
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
[`${EthAccountType.Erc4337}`]: [...Object.values(ETH_ERC_4337_METHODS)],
[`${EthAccountType.Erc4337}`]: {
methods: [...Object.values(ETH_ERC_4337_METHODS)],
scopes: [EthScopes.Mainnet], // Assuming we are using mainnet for those Smart Accounts
},
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
[`${BtcAccountType.P2wpkh}`]: [...Object.values(BtcMethod)],
[`${BtcAccountType.P2wpkh}`]: {
methods: [...Object.values(BtcMethod)],
scopes: [BtcScopes.Mainnet],
},
};

const methods =
accountTypeToMethods[type as keyof typeof accountTypeToMethods];
const { methods, scopes } = accountTypeToInfo[type];

const account = {
const account: InternalAccount = {
id,
address,
options: {},
methods,
scopes,
type,
metadata: {
name,
Expand All @@ -217,7 +235,7 @@ function createExpectedInternalAccount({
lastSelected: lastSelected || expect.any(Number),
...(nameLastUpdatedAt && { nameLastUpdatedAt }),
},
} as InternalAccount;
};

if (snapId) {
account.metadata.snap = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ const INTERNAL_ACCOUNT_MOCK: InternalAccount = {
id: '58def058-d35f-49a1-a7ab-e2580565f6f5',
address: ACCOUNT_MOCK,
type: 'eip155:eoa',
scopes: ['eip155'],
options: {},
methods: [],
metadata: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const createMockInternalAccount = ({
options: {},
methods: [],
type: 'eip155:eoa',
scopes: ['eip155'],
metadata: {
name,
keyring: { type: 'HD Key Tree' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const CONTROLLER_ARGS_MOCK: ConstructorParameters<
type: 'eip155:eoa' as const,
options: {},
methods: [],
scopes: ['eip155'],
metadata: {
name: 'Account 1',
keyring: { type: 'HD Key Tree' },
Expand Down

0 comments on commit fd50073

Please sign in to comment.