@@ -11,6 +11,7 @@ import {
1111 SOLANA_CAIP2 ,
1212 MOCK_SOLANA_ACCOUNTS ,
1313 MOCK_BTC_ACCOUNTS ,
14+ getMockWithSnapKeyring ,
1415} from '../test-utils' ;
1516import { MultichainRouter } from './MultichainRouter' ;
1617
@@ -19,24 +20,23 @@ describe('MultichainRouter', () => {
1920 it ( 'can route signing requests to account Snaps without address resolution' , async ( ) => {
2021 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
2122 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
23+ const withSnapKeyring = getMockWithSnapKeyring ( {
24+ submitRequest : jest . fn ( ) . mockResolvedValue ( {
25+ txid : '53de51e2fa75c3cfa51132865f7d430138b1cd92a8f5267ec836ec565b422969' ,
26+ } ) ,
27+ } ) ;
2228
2329 /* eslint-disable-next-line no-new */
2430 new MultichainRouter ( {
2531 messenger,
32+ withSnapKeyring,
2633 } ) ;
2734
2835 rootMessenger . registerActionHandler (
2936 'AccountsController:listMultichainAccounts' ,
3037 ( ) => MOCK_BTC_ACCOUNTS ,
3138 ) ;
3239
33- rootMessenger . registerActionHandler (
34- 'KeyringController:submitNonEvmRequest' ,
35- async ( ) => ( {
36- txid : '53de51e2fa75c3cfa51132865f7d430138b1cd92a8f5267ec836ec565b422969' ,
37- } ) ,
38- ) ;
39-
4040 rootMessenger . registerActionHandler (
4141 'SnapController:handleRequest' ,
4242 async ( { handler } ) => {
@@ -66,24 +66,23 @@ describe('MultichainRouter', () => {
6666 it ( 'can route signing requests to account Snaps using address resolution' , async ( ) => {
6767 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
6868 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
69+ const withSnapKeyring = getMockWithSnapKeyring ( {
70+ submitRequest : jest . fn ( ) . mockResolvedValue ( {
71+ signature : '0x' ,
72+ } ) ,
73+ } ) ;
6974
7075 /* eslint-disable-next-line no-new */
7176 new MultichainRouter ( {
7277 messenger,
78+ withSnapKeyring,
7379 } ) ;
7480
7581 rootMessenger . registerActionHandler (
7682 'AccountsController:listMultichainAccounts' ,
7783 ( ) => MOCK_SOLANA_ACCOUNTS ,
7884 ) ;
7985
80- rootMessenger . registerActionHandler (
81- 'KeyringController:submitNonEvmRequest' ,
82- async ( ) => ( {
83- signature : '0x' ,
84- } ) ,
85- ) ;
86-
8786 rootMessenger . registerActionHandler (
8887 'PermissionController:getPermissions' ,
8988 ( ) => MOCK_SOLANA_SNAP_PERMISSIONS ,
@@ -113,13 +112,15 @@ describe('MultichainRouter', () => {
113112 expect ( result ) . toStrictEqual ( { signature : '0x' } ) ;
114113 } ) ;
115114
116- it ( 'can route protocol requests to procotol Snaps' , async ( ) => {
115+ it ( 'can route protocol requests to protocol Snaps' , async ( ) => {
117116 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
118117 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
118+ const withSnapKeyring = getMockWithSnapKeyring ( ) ;
119119
120120 /* eslint-disable-next-line no-new */
121121 new MultichainRouter ( {
122122 messenger,
123+ withSnapKeyring,
123124 } ) ;
124125
125126 rootMessenger . registerActionHandler (
@@ -161,10 +162,12 @@ describe('MultichainRouter', () => {
161162 it ( 'throws if no suitable Snaps are found' , async ( ) => {
162163 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
163164 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
165+ const withSnapKeyring = getMockWithSnapKeyring ( ) ;
164166
165167 /* eslint-disable-next-line no-new */
166168 new MultichainRouter ( {
167169 messenger,
170+ withSnapKeyring,
168171 } ) ;
169172
170173 rootMessenger . registerActionHandler (
@@ -190,10 +193,15 @@ describe('MultichainRouter', () => {
190193 it ( 'throws if address resolution fails' , async ( ) => {
191194 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
192195 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
196+ const withSnapKeyring = getMockWithSnapKeyring ( {
197+ // Simulate the Snap returning a bogus address
198+ resolveAccountAddress : jest . fn ( ) . mockResolvedValue ( { address : 'foo' } ) ,
199+ } ) ;
193200
194201 /* eslint-disable-next-line no-new */
195202 new MultichainRouter ( {
196203 messenger,
204+ withSnapKeyring,
197205 } ) ;
198206
199207 rootMessenger . registerActionHandler (
@@ -206,17 +214,6 @@ describe('MultichainRouter', () => {
206214 ( ) => MOCK_SOLANA_SNAP_PERMISSIONS ,
207215 ) ;
208216
209- rootMessenger . registerActionHandler (
210- 'SnapController:handleRequest' ,
211- async ( { handler } ) => {
212- if ( handler === HandlerType . OnKeyringRequest ) {
213- // Simulate the Snap returning a bogus address
214- return { address : 'foo' } ;
215- }
216- throw new Error ( 'Unmocked request' ) ;
217- } ,
218- ) ;
219-
220217 await expect (
221218 messenger . call ( 'MultichainRouter:handleRequest' , {
222219 connectedAddresses : SOLANA_CONNECTED_ACCOUNTS ,
@@ -234,10 +231,18 @@ describe('MultichainRouter', () => {
234231 it ( 'throws if address resolution returns an address that isnt available' , async ( ) => {
235232 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
236233 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
234+ const withSnapKeyring = getMockWithSnapKeyring ( {
235+ // Simulate the Snap returning an unconnected address
236+ resolveAccountAddress : jest . fn ( ) . mockResolvedValue ( {
237+ address :
238+ 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKa' ,
239+ } ) ,
240+ } ) ;
237241
238242 /* eslint-disable-next-line no-new */
239243 new MultichainRouter ( {
240244 messenger,
245+ withSnapKeyring,
241246 } ) ;
242247
243248 rootMessenger . registerActionHandler (
@@ -250,20 +255,6 @@ describe('MultichainRouter', () => {
250255 ( ) => MOCK_SOLANA_SNAP_PERMISSIONS ,
251256 ) ;
252257
253- rootMessenger . registerActionHandler (
254- 'SnapController:handleRequest' ,
255- async ( { handler } ) => {
256- if ( handler === HandlerType . OnKeyringRequest ) {
257- // Simulate the Snap returning an unconnected address
258- return {
259- address :
260- 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKa' ,
261- } ;
262- }
263- throw new Error ( 'Unmocked request' ) ;
264- } ,
265- ) ;
266-
267258 await expect (
268259 messenger . call ( 'MultichainRouter:handleRequest' , {
269260 connectedAddresses : SOLANA_CONNECTED_ACCOUNTS ,
@@ -283,10 +274,12 @@ describe('MultichainRouter', () => {
283274 it ( 'returns a set of both protocol and account Snap methods' , async ( ) => {
284275 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
285276 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
277+ const withSnapKeyring = getMockWithSnapKeyring ( ) ;
286278
287279 /* eslint-disable-next-line no-new */
288280 new MultichainRouter ( {
289281 messenger,
282+ withSnapKeyring,
290283 } ) ;
291284
292285 rootMessenger . registerActionHandler ( 'SnapController:getAll' , ( ) => {
@@ -313,10 +306,12 @@ describe('MultichainRouter', () => {
313306 it ( 'handles lack of protocol Snaps' , async ( ) => {
314307 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
315308 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
309+ const withSnapKeyring = getMockWithSnapKeyring ( ) ;
316310
317311 /* eslint-disable-next-line no-new */
318312 new MultichainRouter ( {
319313 messenger,
314+ withSnapKeyring,
320315 } ) ;
321316
322317 rootMessenger . registerActionHandler ( 'SnapController:getAll' , ( ) => {
@@ -343,10 +338,12 @@ describe('MultichainRouter', () => {
343338 it ( 'handles lack of account Snaps' , async ( ) => {
344339 const rootMessenger = getRootMultichainRouterMessenger ( ) ;
345340 const messenger = getRestrictedMultichainRouterMessenger ( rootMessenger ) ;
341+ const withSnapKeyring = getMockWithSnapKeyring ( ) ;
346342
347343 /* eslint-disable-next-line no-new */
348344 new MultichainRouter ( {
349345 messenger,
346+ withSnapKeyring,
350347 } ) ;
351348
352349 rootMessenger . registerActionHandler ( 'SnapController:getAll' , ( ) => {
0 commit comments