Skip to content

Commit

Permalink
test(keyring-snap-bridge): fix missing scopes + use new *Scopes const…
Browse files Browse the repository at this point in the history
…ants
  • Loading branch information
ccharly committed Nov 25, 2024
1 parent 510535a commit 22cd5fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('KeyringSnapControllerClient', () => {
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
scopes: ['eip155'],
type: 'eip155:eoa',
},
];
Expand Down
40 changes: 17 additions & 23 deletions packages/keyring-snap-bridge/src/SnapKeyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
KeyringExecutionContext,
} from '@metamask/keyring-api';
import {
EthScopes,
BtcAccountType,
BtcMethod,
EthAccountType,
Expand All @@ -18,7 +19,7 @@ import {
} from '@metamask/keyring-api';
import type { SnapController } from '@metamask/snaps-controllers';
import type { SnapId } from '@metamask/snaps-sdk';
import { KnownCaipNamespace, toCaipChainId } from '@metamask/utils';
import { toCaipChainId } from '@metamask/utils';

import type { KeyringState } from '.';
import { SnapKeyring } from '.';
Expand Down Expand Up @@ -79,41 +80,47 @@ describe('SnapKeyring', () => {
address: '0xC728514Df8A7F9271f4B7a4dd2Aa6d2D723d3eE3'.toLowerCase(),
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
};
const ethEoaAccount2 = {
id: '33c96b60-2237-488e-a7bb-233576f3d22f',
address: '0x34b13912eAc00152bE0Cb409A301Ab8E55739e63'.toLowerCase(),
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
};
const ethEoaAccount3 = {
id: 'c6697bcf-5710-4751-a1cb-340e4b50617a',
address: '0xab1G3q98V7C67T9103g30C0417610237A137d763'.toLowerCase(),
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
};
const ethErc4337Account = {
id: 'fc926fff-f515-4eb5-9952-720bbd9b9849',
address: '0x2f15b30952aebe0ed5fdbfe5bf16fb9ecdb31d9a'.toLowerCase(),
options: {},
methods: ETH_4337_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Erc4337,
};
const btcP2wpkhAccount = {
id: '11cffca0-12cc-4779-8f82-23273c062e29',
address: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
options: {},
methods: [...Object.values(BtcMethod)],
scopes: ['bip122:000000000019d6689c085ae165831e93'],
type: BtcAccountType.P2wpkh,
};
const solDataAccount = {
id: '780ee179-5ab5-449d-9c25-34e12c1ada66',
address: '3d4v35MRK57xM2Nte3E3rTQU1zyXGVrkXJ6FuEjVoKzM',
options: {},
methods: [...Object.values(SolMethod)],
scopes: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
type: SolAccountType.DataAccount,
};

Expand Down Expand Up @@ -162,6 +169,7 @@ describe('SnapKeyring', () => {
id: 'b05d918a-b37c-497a-bb28-3d15c0d56b7a',
options: {},
methods: ETH_EOA_METHODS,
scopes: [EthScopes.Namespace],
type: EthAccountType.Eoa,
// Even checksummed address will be lower-cased by the bridge.
address: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F',
Expand Down Expand Up @@ -190,6 +198,7 @@ describe('SnapKeyring', () => {
options: {},
methods: [...Object.values(SolMethod)],
type: SolAccountType.DataAccount,
scopes: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
address: '4k3s6XreQwU9Jht6FzZt8c5yDGrNo8tZ9pGE6S5YjowM',
};
await keyring.handleKeyringSnapMessage(snapId, {
Expand Down Expand Up @@ -869,7 +878,7 @@ describe('SnapKeyring', () => {
};
const tx = TransactionFactory.fromTxData(mockTx);
const expectedSignedTx = TransactionFactory.fromTxData(mockSignedTx);
const expectedScope = 'eip155:1';
const expectedScope = EthScopes.Mainnet;

mockSnapController.handleRequest.mockResolvedValue({
pending: false,
Expand Down Expand Up @@ -947,7 +956,7 @@ describe('SnapKeyring', () => {
},
};

const expectedScope = 'eip155:1';
const expectedScope = EthScopes.Mainnet;
const expectedSignature =
'0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c';

Expand Down Expand Up @@ -1145,10 +1154,7 @@ describe('SnapKeyring', () => {
method: 'keyring_submitRequest',
params: {
id: expect.any(String),
scope: toCaipChainId(
KnownCaipNamespace.Eip155,
executionContext.chainId,
),
scope: toCaipChainId(EthScopes.Namespace, executionContext.chainId),
account: ethErc4337Account.id,
request: {
method: 'eth_prepareUserOperation',
Expand Down Expand Up @@ -1201,10 +1207,7 @@ describe('SnapKeyring', () => {
method: 'keyring_submitRequest',
params: {
id: expect.any(String),
scope: toCaipChainId(
KnownCaipNamespace.Eip155,
executionContext.chainId,
),
scope: toCaipChainId(EthScopes.Namespace, executionContext.chainId),
account: ethErc4337Account.id,
request: {
method: 'eth_patchUserOperation',
Expand Down Expand Up @@ -1253,10 +1256,7 @@ describe('SnapKeyring', () => {
method: 'keyring_submitRequest',
params: {
id: expect.any(String),
scope: toCaipChainId(
KnownCaipNamespace.Eip155,
executionContext.chainId,
),
scope: toCaipChainId(EthScopes.Namespace, executionContext.chainId),
account: ethErc4337Account.id,
request: {
method: 'eth_signUserOperation',
Expand Down Expand Up @@ -1481,10 +1481,7 @@ describe('SnapKeyring', () => {
method: 'keyring_submitRequest',
params: {
id: expect.any(String),
scope: toCaipChainId(
KnownCaipNamespace.Eip155,
executionContext.chainId,
),
scope: toCaipChainId(EthScopes.Namespace, executionContext.chainId),
account: ethErc4337Account.id,
request: {
method: 'eth_prepareUserOperation',
Expand Down Expand Up @@ -1551,10 +1548,7 @@ describe('SnapKeyring', () => {
method: 'keyring_submitRequest',
params: {
id: expect.any(String),
scope: toCaipChainId(
KnownCaipNamespace.Eip155,
executionContext.chainId,
),
scope: toCaipChainId(EthScopes.Namespace, executionContext.chainId),
account: ethErc4337Account.id,
request: {
method: 'eth_patchUserOperation',
Expand Down

0 comments on commit 22cd5fe

Please sign in to comment.