From 49eb331136385168efc6e4e7eaa856b97766985a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20=C5=81ucka?= <5708018+PatrykLucka@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:49:15 +0100 Subject: [PATCH] test: index tests --- packages/snap/snap.manifest.json | 5 +++- packages/snap/src/index.test.tsx | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/snap/src/index.test.tsx diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index dc858dc..25274a3 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "git+https://github.com/MetaMask/snap-institutional-wallet.git" }, "source": { - "shasum": "pAM+McrqnMYKY0ctbnqvhb2POFwcXh5wdz8DnklnoXc=", + "shasum": "QSEUwSGzVO8qCl4txbapwXW4cRzmhsTcd/fUDFs0q+0=", "location": { "npm": { "filePath": "dist/bundle.js", @@ -20,6 +20,7 @@ "initialConnections": { "localhost:8000": {}, "https://localhost:8000": {}, + "https://metamask.io": {}, "https://neptune-custody-ui.dev.metamask-institutional.io": {}, "https://neptune-custody-ui.metamask-institutional.io": {}, "https://zodia.io": {}, @@ -41,6 +42,7 @@ "allowedOrigins": [ "localhost:8000", "http://localhost:8000", + "https://metamask.io", "https://neptune-custody-ui.dev.metamask-institutional.io" ] }, @@ -48,6 +50,7 @@ "allowedOrigins": [ "localhost:8000", "http://localhost:8000", + "https://metamask.io", "https://neptune-custody-ui.dev.metamask-institutional.io", "https://zodia.io", "https://sit.zodia.io", diff --git a/packages/snap/src/index.test.tsx b/packages/snap/src/index.test.tsx new file mode 100644 index 0000000..596fea4 --- /dev/null +++ b/packages/snap/src/index.test.tsx @@ -0,0 +1,41 @@ +import { expect } from '@jest/globals'; +import { installSnap } from '@metamask/snaps-jest'; + +describe('onRpcRequest', () => { + it('throws an error if the requested method does not exist', async () => { + const snap = await installSnap(); + + const response = await snap.request({ + method: 'foo', + }); + + expect((response.response as any).error).toMatchObject({ + code: -32603, + message: "Origin 'https://metamask.io' is not allowed to call 'foo'", + stack: expect.any(String), + }); + }); +}); + +describe('onKeyringRequest', () => { + it('throws an error if the requested method does not exist', async () => { + const snap = await installSnap(); + + const response = await snap.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'npm:@metamask/solana-wallet-snap', + request: { + method: 'foo', + }, + }, + }); + + expect((response.response as any).error).toMatchObject({ + code: -32603, + message: + "Origin 'https://metamask.io' is not allowed to call 'wallet_invokeSnap'", + stack: expect.any(String), + }); + }); +});