From 22cd5fe297fbc52ec8fb965e16bc8efd5262ca68 Mon Sep 17 00:00:00 2001 From: Charly Chevalier Date: Mon, 25 Nov 2024 10:30:22 +0100 Subject: [PATCH] test(keyring-snap-bridge): fix missing scopes + use new *Scopes constants --- .../src/KeyringSnapControllerClient.test.ts | 1 + .../src/SnapKeyring.test.ts | 40 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/keyring-snap-bridge/src/KeyringSnapControllerClient.test.ts b/packages/keyring-snap-bridge/src/KeyringSnapControllerClient.test.ts index 9c16fc94..a9d73773 100644 --- a/packages/keyring-snap-bridge/src/KeyringSnapControllerClient.test.ts +++ b/packages/keyring-snap-bridge/src/KeyringSnapControllerClient.test.ts @@ -13,6 +13,7 @@ describe('KeyringSnapControllerClient', () => { address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', options: {}, methods: [], + scopes: ['eip155'], type: 'eip155:eoa', }, ]; diff --git a/packages/keyring-snap-bridge/src/SnapKeyring.test.ts b/packages/keyring-snap-bridge/src/SnapKeyring.test.ts index 57fb9daa..8c88147c 100644 --- a/packages/keyring-snap-bridge/src/SnapKeyring.test.ts +++ b/packages/keyring-snap-bridge/src/SnapKeyring.test.ts @@ -8,6 +8,7 @@ import type { KeyringExecutionContext, } from '@metamask/keyring-api'; import { + EthScopes, BtcAccountType, BtcMethod, EthAccountType, @@ -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 '.'; @@ -79,6 +80,7 @@ describe('SnapKeyring', () => { address: '0xC728514Df8A7F9271f4B7a4dd2Aa6d2D723d3eE3'.toLowerCase(), options: {}, methods: ETH_EOA_METHODS, + scopes: [EthScopes.Namespace], type: EthAccountType.Eoa, }; const ethEoaAccount2 = { @@ -86,6 +88,7 @@ describe('SnapKeyring', () => { address: '0x34b13912eAc00152bE0Cb409A301Ab8E55739e63'.toLowerCase(), options: {}, methods: ETH_EOA_METHODS, + scopes: [EthScopes.Namespace], type: EthAccountType.Eoa, }; const ethEoaAccount3 = { @@ -93,6 +96,7 @@ describe('SnapKeyring', () => { address: '0xab1G3q98V7C67T9103g30C0417610237A137d763'.toLowerCase(), options: {}, methods: ETH_EOA_METHODS, + scopes: [EthScopes.Namespace], type: EthAccountType.Eoa, }; const ethErc4337Account = { @@ -100,6 +104,7 @@ describe('SnapKeyring', () => { address: '0x2f15b30952aebe0ed5fdbfe5bf16fb9ecdb31d9a'.toLowerCase(), options: {}, methods: ETH_4337_METHODS, + scopes: [EthScopes.Namespace], type: EthAccountType.Erc4337, }; const btcP2wpkhAccount = { @@ -107,6 +112,7 @@ describe('SnapKeyring', () => { address: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh', options: {}, methods: [...Object.values(BtcMethod)], + scopes: ['bip122:000000000019d6689c085ae165831e93'], type: BtcAccountType.P2wpkh, }; const solDataAccount = { @@ -114,6 +120,7 @@ describe('SnapKeyring', () => { address: '3d4v35MRK57xM2Nte3E3rTQU1zyXGVrkXJ6FuEjVoKzM', options: {}, methods: [...Object.values(SolMethod)], + scopes: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'], type: SolAccountType.DataAccount, }; @@ -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', @@ -190,6 +198,7 @@ describe('SnapKeyring', () => { options: {}, methods: [...Object.values(SolMethod)], type: SolAccountType.DataAccount, + scopes: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'], address: '4k3s6XreQwU9Jht6FzZt8c5yDGrNo8tZ9pGE6S5YjowM', }; await keyring.handleKeyringSnapMessage(snapId, { @@ -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, @@ -947,7 +956,7 @@ describe('SnapKeyring', () => { }, }; - const expectedScope = 'eip155:1'; + const expectedScope = EthScopes.Mainnet; const expectedSignature = '0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c'; @@ -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', @@ -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', @@ -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', @@ -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', @@ -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',