@metamask/snaps-jest 3.1.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/README.md +2 -2
- package/dist/cjs/internals/interface.js +4 -4
- package/dist/cjs/internals/interface.js.map +1 -1
- package/dist/cjs/internals/request.js.map +1 -1
- package/dist/cjs/internals/structs.js +6 -8
- package/dist/cjs/internals/structs.js.map +1 -1
- package/dist/cjs/matchers.js.map +1 -1
- package/dist/cjs/types.js +0 -7
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/internals/interface.js +1 -1
- package/dist/esm/internals/interface.js.map +1 -1
- package/dist/esm/internals/request.js.map +1 -1
- package/dist/esm/internals/structs.js +3 -5
- package/dist/esm/internals/structs.js.map +1 -1
- package/dist/esm/internals/types.js.map +1 -1
- package/dist/esm/matchers.js.map +1 -1
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/internals/network.d.ts +1 -1
- package/dist/types/internals/request.d.ts +29 -10
- package/dist/types/internals/structs.d.ts +111 -35
- package/dist/types/internals/types.d.ts +1 -2
- package/dist/types/matchers.d.ts +1 -3
- package/dist/types/types.d.ts +1 -4
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [4.0.1]
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fix coercing of address values in `sendTransaction` function ([#1970](https://github.com/MetaMask/snaps/pull/1970))
|
|
12
|
+
|
|
13
|
+
## [4.0.0]
|
|
14
|
+
### Changed
|
|
15
|
+
- Use `@metamask/snaps-sdk` package ([#1930](https://github.com/MetaMask/snaps/pull/1930),
|
|
16
|
+
[#1950](https://github.com/MetaMask/snaps/pull/1950), [#1954](https://github.com/MetaMask/snaps/pull/1954))
|
|
17
|
+
- This package replaces the `@metamask/snaps-types` and
|
|
18
|
+
- `@metamask/snaps-ui` packages.
|
|
19
|
+
|
|
20
|
+
### Removed
|
|
21
|
+
- **BREAKING**: `DialogType`, `ManageStateOperation`, `NotificationType` are no
|
|
22
|
+
longer re-exported from `@metamask/snaps-jest` ([#1930](https://github.com/MetaMask/snaps/pull/1930))
|
|
23
|
+
- These enums can now be imported from `@metamask/snaps-sdk` instead.
|
|
24
|
+
|
|
9
25
|
## [3.1.0]
|
|
10
26
|
### Added
|
|
11
27
|
- Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
|
|
@@ -65,7 +81,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
65
81
|
- The version of the package no longer needs to match the version of all other
|
|
66
82
|
MetaMask Snaps packages.
|
|
67
83
|
|
|
68
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@
|
|
84
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@4.0.1...HEAD
|
|
85
|
+
[4.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@4.0.0...@metamask/snaps-jest@4.0.1
|
|
86
|
+
[4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@3.1.0...@metamask/snaps-jest@4.0.0
|
|
69
87
|
[3.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@3.0.0...@metamask/snaps-jest@3.1.0
|
|
70
88
|
[3.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@2.0.0...@metamask/snaps-jest@3.0.0
|
|
71
89
|
[2.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@1.0.0...@metamask/snaps-jest@2.0.0
|
package/README.md
CHANGED
|
@@ -200,7 +200,7 @@ function.
|
|
|
200
200
|
|
|
201
201
|
```js
|
|
202
202
|
import { installSnap } from '@metamask/snaps-jest';
|
|
203
|
-
import { panel, text } from '@metamask/snaps-
|
|
203
|
+
import { panel, text } from '@metamask/snaps-sdk';
|
|
204
204
|
|
|
205
205
|
describe('MySnap', () => {
|
|
206
206
|
it('should do something', async () => {
|
|
@@ -316,7 +316,7 @@ functions that can be used to interact with the user interface.
|
|
|
316
316
|
|
|
317
317
|
```js
|
|
318
318
|
import { installSnap } from '@metamask/snaps-jest';
|
|
319
|
-
import { text } from '@metamask/snaps-
|
|
319
|
+
import { text } from '@metamask/snaps-sdk';
|
|
320
320
|
import { assert } from '@metamask/utils';
|
|
321
321
|
|
|
322
322
|
describe('MySnap', () => {
|
|
@@ -16,7 +16,7 @@ _export(exports, {
|
|
|
16
16
|
return getNotifications;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
const
|
|
19
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
20
20
|
const _utils = require("@metamask/utils");
|
|
21
21
|
const _superstruct = require("superstruct");
|
|
22
22
|
const _structs = require("./structs");
|
|
@@ -35,7 +35,7 @@ async function getInterface(page, options = {}) {
|
|
|
35
35
|
message: 'Timed out waiting for snap interface to be shown.'
|
|
36
36
|
});
|
|
37
37
|
switch(type){
|
|
38
|
-
case
|
|
38
|
+
case _snapssdk.DialogType.Alert:
|
|
39
39
|
return {
|
|
40
40
|
type: 'alert',
|
|
41
41
|
content,
|
|
@@ -48,7 +48,7 @@ async function getInterface(page, options = {}) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
case
|
|
51
|
+
case _snapssdk.DialogType.Confirmation:
|
|
52
52
|
return {
|
|
53
53
|
type: 'confirmation',
|
|
54
54
|
content,
|
|
@@ -69,7 +69,7 @@ async function getInterface(page, options = {}) {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
-
case
|
|
72
|
+
case _snapssdk.DialogType.Prompt:
|
|
73
73
|
return {
|
|
74
74
|
type: 'prompt',
|
|
75
75
|
content,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["getInterface","getNotifications","page","options","timeout","create","SnapOptionsStruct","type","node","content","waitFor","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","assert","message","DialogType","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","requestId","id"],"mappings":";;;;;;;;;;;IAmBsBA,YAAY;eAAZA;;IAkGAC,gBAAgB;eAAhBA;;;0BArHK;uBACJ;6BAEA;yBAGW;yBACV;AAYjB,eAAeD,aACpBE,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,OAAO,EAAE,GAAGC,IAAAA,mBAAM,EAACF,SAASG,0BAAiB;IAErD,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMC,IAAAA,gBAAO,EAC3C;QACE,MAAMC,KAAK,MAAMT,KAAKU,QAAQ,CAAC;YAC7B,MAAMC,QAAQC,OAAOC,iBAAiB,CAACC,QAAQ;YAC/C,OAAOH,MAAMI,UAAU,CAACN,EAAE;QAC5B;QAEAO,IAAAA,aAAM,EAACP;QACP,OAAOA;IACT,GACA;QACEP;QACAe,SAAS;IACX;IAGF,OAAQZ;QACN,KAAKa,oBAAU,CAACC,KAAK;YACnB,OAAO;gBACLd,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,oBAAU,CAACK,YAAY;YAC1B,OAAO;gBACLlB,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;gBAEAE,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,oBAAU,CAACO,MAAM;YACpB,OAAO;gBACLpB,MAAM;gBACNE;gBAEAa,IAAI,OAAOM;oBACT,MAAM1B,KAAKU,QAAQ,CAAC,CAACY;wBACnBV,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB;wBACF;oBACF,GAAGI;gBACL;gBAEAF,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOvB,MAAM,CAAC,CAAC;IAC1E;AACF;AASO,eAAeN,iBAAiBC,IAAU,EAAE6B,SAAiB;IAClE,OAAO,MAAM7B,KAAKU,QAAQ,CAAC,CAACoB;QAC1B,OAAOlB,OAAOC,iBAAiB,CAACd,gBAAgB,CAAC+B;IACnD,GAAGD;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n assert,\n createModuleLogger,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type {\n CronjobOptions,\n RequestOptions,\n SnapRequest,\n SnapResponse,\n TransactionOptions,\n} from '../types';\nimport { getInterface, getNotifications } from './interface';\nimport { rootLogger } from './logger';\nimport { TransactionOptionsStruct } from './structs';\nimport { waitForResponse } from './wait-for';\n\nconst log = createModuleLogger(rootLogger, 'request');\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param args - The request arguments.\n * @returns The request ID.\n */\nasync function sendRequest(page: Page, args: SnapRpcHookArgs) {\n const document = await getDocument(page);\n const button = await queries.getByTestId(\n document,\n `navigation-${args.handler}`,\n );\n\n // Navigate to the request handler page.\n await button.click();\n\n return await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/sendRequest',\n payload,\n });\n\n return window.__SIMULATOR_API__.getRequestId();\n }, args);\n}\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param options - The request options.\n * @param options.origin - The origin of the request. Defaults to `metamask.io`.\n * @param handler - The handler to use. Defaults to `onRpcRequest`.\n * @returns The response.\n */\nexport function request(\n page: Page,\n { origin = 'metamask.io', ...options }: RequestOptions,\n handler:\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob = HandlerType.OnRpcRequest,\n) {\n const doRequest = async (): Promise<SnapResponse> => {\n const args: SnapRpcHookArgs = {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n };\n\n log('Sending request %o', args);\n\n const promise = waitForResponse(page, handler);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n const notifications = await getNotifications(page, id);\n\n return { id, response, notifications };\n };\n\n // This is a bit hacky, but it allows us to add the `getInterface` method\n // to the response promise.\n const response = doRequest() as SnapRequest;\n\n response.getInterface = async (getInterfaceOptions) => {\n return await getInterface(page, getInterfaceOptions);\n };\n\n return response;\n}\n\n/**\n * Send a transaction to the snap.\n *\n * @param page - The page to send the transaction from.\n * @param options - The transaction options.\n * @returns The response.\n */\nexport async function sendTransaction(\n page: Page,\n options: Partial<TransactionOptions>,\n) {\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(options, TransactionOptionsStruct);\n\n const args: SnapRpcHookArgs = {\n origin: '',\n handler: HandlerType.OnTransaction,\n request: {\n jsonrpc: '2.0',\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n };\n\n log('Sending transaction %o', args);\n\n const promise = waitForResponse(page, HandlerType.OnTransaction);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n if (hasProperty(response, 'error')) {\n return { id, response, notifications: [] };\n }\n\n assert(isPlainObject(response.result));\n assert(hasProperty(response.result, 'content'));\n\n return {\n id,\n response,\n notifications: [],\n content: response.result.content as Component,\n };\n}\n\n/**\n * Run a cronjob.\n *\n * @param page - The page to run the cronjob from.\n * @param options - The request options.\n * @returns The response.\n */\nexport function runCronjob(page: Page, options: CronjobOptions) {\n return request(page, options, HandlerType.OnCronjob);\n}\n"],"names":["request","sendTransaction","runCronjob","log","createModuleLogger","rootLogger","sendRequest","page","args","document","getDocument","button","queries","getByTestId","handler","click","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","getRequestId","origin","options","HandlerType","OnRpcRequest","doRequest","jsonrpc","id","promise","waitForResponse","response","notifications","getNotifications","getInterface","getInterfaceOptions","transactionOrigin","chainId","transaction","create","TransactionOptionsStruct","OnTransaction","method","params","hasProperty","assert","isPlainObject","result","content","OnCronjob"],"mappings":";;;;;;;;;;;IA+DgBA,OAAO;eAAPA;;IAiDMC,eAAe;eAAfA;;IAsDNC,UAAU;eAAVA;;;4BApKY;uBAMrB;oCAC8B;6BAEd;2BASwB;wBACpB;yBACc;yBACT;A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ACzBC,OAAO,EACP,GAAGC,aACJ,GAAGC,IAAAA,mBAAM,EAAChB,SAASiB,iCAAwB;IAE5C,MAAMjC,OAAwB;QAC5Be,QAAQ;QACRT,SAASW,uBAAW,CAACiB,aAAa;QAClC1C,SAAS;YACP4B,SAAS;YACTe,QAAQ;YACRC,QAAQ;gBACNN;gBACAC;gBACAF;YACF;QACF;IACF;IAEAlC,IAAI,0BAA0BK;IAE9B,MAAMsB,UAAUC,IAAAA,wBAAe,EAACxB,MAAMkB,uBAAW,CAACiB,aAAa;IAC/D,MAAMb,KAAK,MAAMvB,YAAYC,MAAMC;IACnC,MAAMwB,WAAW,MAAMF;IAEvB3B,IAAI,wBAAwB6B;IAE5B,IAAIa,IAAAA,kBAAW,EAACb,UAAU,UAAU;QAClC,OAAO;YAAEH;YAAIG;YAAUC,eAAe,EAAE;QAAC;IAC3C;IAEAa,IAAAA,aAAM,EAACC,IAAAA,oBAAa,EAACf,SAASgB,MAAM;IACpCF,IAAAA,aAAM,EAACD,IAAAA,kBAAW,EAACb,SAASgB,MAAM,EAAE;IAEpC,OAAO;QACLnB;QACAG;QACAC,eAAe,EAAE;QACjBgB,SAASjB,SAASgB,MAAM,CAACC,OAAO;IAClC;AACF;AASO,SAAS/C,WAAWK,IAAU,EAAEiB,OAAuB;IAC5D,OAAOxB,QAAQO,MAAMiB,SAASC,uBAAW,CAACyB,SAAS;AACrD"}
|
|
@@ -22,9 +22,7 @@ _export(exports, {
|
|
|
22
22
|
return SnapResponseStruct;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
const
|
|
26
|
-
const _snapsui = require("@metamask/snaps-ui");
|
|
27
|
-
const _snapsutils = require("@metamask/snaps-utils");
|
|
25
|
+
const _snapssdk = require("@metamask/snaps-sdk");
|
|
28
26
|
const _utils = require("@metamask/utils");
|
|
29
27
|
const _crypto = require("crypto");
|
|
30
28
|
const _superstruct = require("superstruct");
|
|
@@ -48,7 +46,7 @@ const TransactionOptionsStruct = (0, _superstruct.object)({
|
|
|
48
46
|
*/ // TODO: Move this coercer to `@metamask/utils`.
|
|
49
47
|
from: (0, _superstruct.coerce)(_utils.StrictHexStruct, (0, _superstruct.optional)(BytesLikeStruct), (value)=>{
|
|
50
48
|
if (value) {
|
|
51
|
-
return (0, _utils.valueToBytes)(value);
|
|
49
|
+
return (0, _utils.bytesToHex)((0, _utils.valueToBytes)(value));
|
|
52
50
|
}
|
|
53
51
|
return (0, _utils.bytesToHex)((0, _crypto.randomBytes)(20));
|
|
54
52
|
}),
|
|
@@ -58,7 +56,7 @@ const TransactionOptionsStruct = (0, _superstruct.object)({
|
|
|
58
56
|
*/ // TODO: Move this coercer to `@metamask/utils`.
|
|
59
57
|
to: (0, _superstruct.coerce)(_utils.StrictHexStruct, (0, _superstruct.optional)(BytesLikeStruct), (value)=>{
|
|
60
58
|
if (value) {
|
|
61
|
-
return (0, _utils.valueToBytes)(value);
|
|
59
|
+
return (0, _utils.bytesToHex)((0, _utils.valueToBytes)(value));
|
|
62
60
|
}
|
|
63
61
|
return (0, _utils.bytesToHex)((0, _crypto.randomBytes)(20));
|
|
64
62
|
}),
|
|
@@ -99,7 +97,7 @@ const SnapOptionsStruct = (0, _superstruct.object)({
|
|
|
99
97
|
*/ timeout: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.number)()), 1000)
|
|
100
98
|
});
|
|
101
99
|
const InterfaceStruct = (0, _superstruct.type)({
|
|
102
|
-
content: (0, _superstruct.optional)(
|
|
100
|
+
content: (0, _superstruct.optional)(_snapssdk.ComponentStruct)
|
|
103
101
|
});
|
|
104
102
|
const SnapResponseStruct = (0, _superstruct.assign)(InterfaceStruct, (0, _superstruct.object)({
|
|
105
103
|
id: (0, _superstruct.string)(),
|
|
@@ -115,8 +113,8 @@ const SnapResponseStruct = (0, _superstruct.assign)(InterfaceStruct, (0, _supers
|
|
|
115
113
|
id: (0, _superstruct.string)(),
|
|
116
114
|
message: (0, _superstruct.string)(),
|
|
117
115
|
type: (0, _superstruct.union)([
|
|
118
|
-
(0,
|
|
119
|
-
(0,
|
|
116
|
+
(0, _snapssdk.enumValue)(_snapssdk.NotificationType.InApp),
|
|
117
|
+
(0, _snapssdk.enumValue)(_snapssdk.NotificationType.Native)
|
|
120
118
|
])
|
|
121
119
|
}))
|
|
122
120
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import {\n NotificationType,\n ComponentStruct,\n enumValue,\n} from '@metamask/snaps-sdk';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["TransactionOptionsStruct","SnapOptionsStruct","InterfaceStruct","SnapResponseStruct","BytesLikeStruct","union","bigint","number","string","instance","Uint8Array","object","chainId","defaulted","origin","from","coerce","StrictHexStruct","optional","value","bytesToHex","valueToBytes","randomBytes","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","literal","timeout","type","content","ComponentStruct","assign","id","response","result","JsonStruct","error","notifications","array","message","enumValue","NotificationType","InApp","Native"],"mappings":";;;;;;;;;;;IAoCaA,wBAAwB;eAAxBA;;IA0GAC,iBAAiB;eAAjBA;;IAQAC,eAAe;eAAfA;;IAIAC,kBAAkB;eAAlBA;;;0BAtJN;uBAMA;wBACqB;6BAerB;AAEP,oDAAoD;AACpD,MAAMC,kBAAkBC,IAAAA,kBAAK,EAAC;IAC5BC,IAAAA,mBAAM;IACNC,IAAAA,mBAAM;IACNC,IAAAA,mBAAM;IACNC,IAAAA,qBAAQ,EAACC;CACV;AAEM,MAAMV,2BAA2BW,IAAAA,mBAAM,EAAC;IAC7C;;GAEC,GACDC,SAASC,IAAAA,sBAAS,EAACL,IAAAA,mBAAM,KAAI;IAE7B;;GAEC,GACDM,QAAQD,IAAAA,sBAAS,EAACL,IAAAA,mBAAM,KAAI;IAE5B;;;GAGC,GACD,gDAAgD;IAChDO,MAAMC,IAAAA,mBAAM,EAACC,sBAAe,EAAEC,IAAAA,qBAAQ,EAACd,kBAAkB,CAACe;QACxD,IAAIA,OAAO;YACT,OAAOC,IAAAA,iBAAU,EAACC,IAAAA,mBAAY,EAACF;QACjC;QAEA,OAAOC,IAAAA,iBAAU,EAACE,IAAAA,mBAAW,EAAC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AA,oBAAO,EAAC;KAAM,GAAGzB,iBAAiB,CAACe,QAChEC,IAAAA,iBAAU,EAACC,IAAAA,mBAAY,EAACF,UAE1B;AAEJ;AAEO,MAAMlB,oBAAoBU,IAAAA,mBAAM,EAAC;IACtC;;;GAGC,GACDmB,SAASjB,IAAAA,sBAAS,EAACK,IAAAA,qBAAQ,EAACX,IAAAA,mBAAM,MAAK;AACzC;AAEO,MAAML,kBAAkB6B,IAAAA,iBAAI,EAAC;IAClCC,SAASd,IAAAA,qBAAQ,EAACe,yBAAe;AACnC;AAEO,MAAM9B,qBAAqB+B,IAAAA,mBAAM,EACtChC,iBACAS,IAAAA,mBAAM,EAAC;IACLwB,IAAI3B,IAAAA,mBAAM;IAEV4B,UAAU/B,IAAAA,kBAAK,EAAC;QACdM,IAAAA,mBAAM,EAAC;YACL0B,QAAQC,iBAAU;QACpB;QACA3B,IAAAA,mBAAM,EAAC;YACL4B,OAAOD,iBAAU;QACnB;KACD;IAEDE,eAAeC,IAAAA,kBAAK,EAClB9B,IAAAA,mBAAM,EAAC;QACLwB,IAAI3B,IAAAA,mBAAM;QACVkC,SAASlC,IAAAA,mBAAM;QACfuB,MAAM1B,IAAAA,kBAAK,EAAC;YACVsC,IAAAA,mBAAS,EAACC,0BAAgB,CAACC,KAAK;YAChCF,IAAAA,mBAAS,EAACC,0BAAgB,CAACE,MAAM;SAClC;IACH;AAEJ"}
|
package/dist/cjs/matchers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { Component } from '@metamask/snaps-ui';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["toRespondWith","toRespondWithError","toSendNotification","toRender","assertActualIsSnapResponse","actual","matcherName","options","is","SnapResponseStruct","Error","matcherErrorMessage","matcherHint","undefined","RECEIVED_COLOR","printWithType","printReceived","assertHasInterface","InterfaceStruct","content","expected","response","hasProperty","message","utils","printExpected","error","pass","equals","result","type","notifications","some","notification","difference","diff","expect","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;;;;;;;;;;;;IAgF5DA,aAAa;eAAbA;;IA8BAC,kBAAkB;eAAlBA;;IAuCAC,kBAAkB;eAAlBA;;IA2BAC,QAAQ;eAARA;;;yBA7KU;uBAKK;kCASrB;6BACY;2BAEiC;AAGpD;;;;;;CAMC,GACD,SAASC,2BAC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pD,CAAC,UAAU,EAAE,IAAI,CAACN,KAAK,CAACR,aAAa,CAACe,eAAe,CAAC;IAE5D,OAAO;QAAER;QAASI;IAAK;AACzB;AAEO,MAAMxB,WAAmD,SAC9DE,MAAM,EACNe,QAAQ;IAERH,mBAAmBZ,QAAQ;IAE3B,MAAM,EAAEc,OAAO,EAAE,GAAGd;IACpB,MAAMsB,OAAO,IAAI,CAACC,MAAM,CAACT,SAASC;IAElC,MAAMc,aAAaC,IAAAA,sBAAI,EAACf,UAAUD;IAElC,MAAMI,UAAUI,OACZ,IACE,CAAC,EAAE,IAAI,CAACH,KAAK,CAACZ,WAAW,CAAC,wBAAwB,IAAI,CAAC,GACvD,CAAC,UAAU,EAAE,IAAI,CAACY,KAAK,CAACC,aAAa,CAACL,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACI,KAAK,CAACR,aAAa,CAACG,SAAS,CAAC,GAChD,CAAC,EAAEe,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC,GAC3D,IACE,CAAC,EAAE,IAAI,CAACV,KAAK,CAACZ,WAAW,CAAC,oBAAoB,IAAI,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACY,KAAK,CAACC,aAAa,CAACL,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACI,KAAK,CAACR,aAAa,CAACG,SAAS,CAAC,GAChD,CAAC,EAAEe,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEX;QAASI;IAAK;AACzB;AAEAS,eAAM,CAACC,MAAM,CAAC;IACZrC;IACAC;IACAC;IACAC;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["toRespondWith","toRespondWithError","toSendNotification","toRender","assertActualIsSnapResponse","actual","matcherName","options","is","SnapResponseStruct","Error","matcherErrorMessage","matcherHint","undefined","RECEIVED_COLOR","printWithType","printReceived","assertHasInterface","InterfaceStruct","content","expected","response","hasProperty","message","utils","printExpected","error","pass","equals","result","type","notifications","some","notification","difference","diff","expect","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;;;;;;;;;;;;IAkF5DA,aAAa;eAAbA;;IA8BAC,kBAAkB;eAAlBA;;IAuCAC,kBAAkB;eAA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exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "NotificationType", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _snapsrpcmethods.NotificationType;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
|
|
12
5
|
|
|
13
6
|
//# sourceMappingURL=types.js.map
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["DialogType","assert","create","SnapOptionsStruct","waitFor","getInterface","page","options","timeout","type","node","content","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","message","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","getNotifications","requestId","id"],"mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AACjD,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,MAAM,QAAQ,cAAc;AAGrC,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,OAAO,QAAQ,aAAa;AAErC;;;;;;;;;CASC,GACD,OAAO,eAAeC,aACpBC,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,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F;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOpB,MAAM,CAAC,CAAC;IAC1E;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeqB,iBAAiBxB,IAAU,EAAEyB,SAAiB;IAClE,OAAO,MAAMzB,KAAKO,QAAQ,CAAC,CAACmB;QAC1B,OAAOjB,OAAOC,iBAAiB,CAACc,gBAAgB,CAACE;IACnD,GAAGD;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/request.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n assert,\n createModuleLogger,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type {\n CronjobOptions,\n RequestOptions,\n SnapRequest,\n SnapResponse,\n TransactionOptions,\n} from '../types';\nimport { getInterface, getNotifications } from './interface';\nimport { rootLogger } from './logger';\nimport { TransactionOptionsStruct } from './structs';\nimport { waitForResponse } from './wait-for';\n\nconst log = createModuleLogger(rootLogger, 'request');\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param args - The request arguments.\n * @returns The request ID.\n */\nasync function sendRequest(page: Page, args: SnapRpcHookArgs) {\n const document = await getDocument(page);\n const button = await queries.getByTestId(\n document,\n `navigation-${args.handler}`,\n );\n\n // Navigate to the request handler page.\n await button.click();\n\n return await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/sendRequest',\n payload,\n });\n\n return window.__SIMULATOR_API__.getRequestId();\n }, args);\n}\n\n/**\n * Send a request to the snap.\n *\n * @param page - The page to send the request from.\n * @param options - The request options.\n * @param options.origin - The origin of the request. Defaults to `metamask.io`.\n * @param handler - The handler to use. Defaults to `onRpcRequest`.\n * @returns The response.\n */\nexport function request(\n page: Page,\n { origin = 'metamask.io', ...options }: RequestOptions,\n handler:\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob = HandlerType.OnRpcRequest,\n) {\n const doRequest = async (): Promise<SnapResponse> => {\n const args: SnapRpcHookArgs = {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n };\n\n log('Sending request %o', args);\n\n const promise = waitForResponse(page, handler);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n const notifications = await getNotifications(page, id);\n\n return { id, response, notifications };\n };\n\n // This is a bit hacky, but it allows us to add the `getInterface` method\n // to the response promise.\n const response = doRequest() as SnapRequest;\n\n response.getInterface = async (getInterfaceOptions) => {\n return await getInterface(page, getInterfaceOptions);\n };\n\n return response;\n}\n\n/**\n * Send a transaction to the snap.\n *\n * @param page - The page to send the transaction from.\n * @param options - The transaction options.\n * @returns The response.\n */\nexport async function sendTransaction(\n page: Page,\n options: Partial<TransactionOptions>,\n) {\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(options, TransactionOptionsStruct);\n\n const args: SnapRpcHookArgs = {\n origin: '',\n handler: HandlerType.OnTransaction,\n request: {\n jsonrpc: '2.0',\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n };\n\n log('Sending transaction %o', args);\n\n const promise = waitForResponse(page, HandlerType.OnTransaction);\n const id = await sendRequest(page, args);\n const response = await promise;\n\n log('Received response %o', response);\n\n if (hasProperty(response, 'error')) {\n return { id, response, notifications: [] };\n }\n\n assert(isPlainObject(response.result));\n assert(hasProperty(response.result, 'content'));\n\n return {\n id,\n response,\n notifications: [],\n content: response.result.content as Component,\n };\n}\n\n/**\n * Run a cronjob.\n *\n * @param page - The page to run the cronjob from.\n * @param options - The request options.\n * @returns The response.\n */\nexport function runCronjob(page: Page, options: CronjobOptions) {\n return request(page, options, HandlerType.OnCronjob);\n}\n"],"names":["HandlerType","assert","createModuleLogger","hasProperty","isPlainObject","getDocument","queries","create","getInterface","getNotifications","rootLogger","TransactionOptionsStruct","waitForResponse","log","sendRequest","page","args","document","button","getByTestId","handler","click","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","getRequestId","request","origin","options","OnRpcRequest","doRequest","jsonrpc","id","promise","response","notifications","getInterfaceOptions","sendTransaction","transactionOrigin","chainId","transaction","OnTransaction","method","params","result","content","runCronjob","OnCronjob"],"mappings":"AAEA,SAASA,WAAW,QAAQ,wBAAwB;AACpD,SACEC,MAAM,EACNC,kBAAkB,EAClBC,WAAW,EACXC,aAAa,QACR,kBAAkB;AACzB,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAuB;AAE5D,SAASC,MAAM,QAAQ,cAAc;AASrC,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,cAAc;AAC7D,SAASC,UAAU,QAAQ,WAAW;AACtC,SAASC,wBAAwB,QAAQ,YAAY;AACrD,SAASC,eAAe,QAAQ,aAAa;AAE7C,MAAMC,MAAMX,mBAAmBQ,YAAY;AAE3C;;;;;;CAMC,GACD,eAAeI,YAAYC,IAAU,EAAEC,IAAqB;IAC1D,MAAMC,WAAW,MAAMZ,YAAYU;IACnC,MAAMG,SAAS,MAAMZ,QAAQa,WAAW,CACtCF,UACA,CAAC,WAAW,EAAED,KAAKI,OAAO,CAAC,CAAC;IAG9B,wCAAwC;IACxC,MAAMF,OAAOG,KAAK;IAElB,OAAO,MAAMN,KAAKO,QAAQ,CAAC,CAACC;QAC1BC,OAAOC,iBAAiB,CAACC,QAAQ,CAAC;YAChCC,MAAM;YACNJ;QACF;QAEA,OAAOC,OAAOC,iBAAiB,CAACG,YAAY;IAC9C,GAAGZ;AACL;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASa,QACdd,IAAU,EACV,EAAEe,SAAS,aAAa,EAAE,GAAGC,SAAyB,EACtDX,UAE4BpB,YA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E;QACAC,eAAe,EAAE;QACjBU,SAASX,SAASU,MAAM,CAACC,OAAO;IAClC;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,WAAWlC,IAAU,EAAEgB,OAAuB;IAC5D,OAAOF,QAAQd,MAAMgB,SAAS/B,YAAYkD,SAAS;AACrD"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NotificationType } from '@metamask/snaps-
|
|
2
|
-
import { ComponentStruct } from '@metamask/snaps-ui';
|
|
3
|
-
import { enumValue } from '@metamask/snaps-utils';
|
|
1
|
+
import { NotificationType, ComponentStruct, enumValue } from '@metamask/snaps-sdk';
|
|
4
2
|
import { bytesToHex, JsonStruct, StrictHexStruct, valueToBytes } from '@metamask/utils';
|
|
5
3
|
import { randomBytes } from 'crypto';
|
|
6
4
|
import { array, assign, bigint, coerce, defaulted, instance, literal, number, object, optional, string, type, union } from 'superstruct';
|
|
@@ -24,7 +22,7 @@ export const TransactionOptionsStruct = object({
|
|
|
24
22
|
*/ // TODO: Move this coercer to `@metamask/utils`.
|
|
25
23
|
from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value)=>{
|
|
26
24
|
if (value) {
|
|
27
|
-
return valueToBytes(value);
|
|
25
|
+
return bytesToHex(valueToBytes(value));
|
|
28
26
|
}
|
|
29
27
|
return bytesToHex(randomBytes(20));
|
|
30
28
|
}),
|
|
@@ -34,7 +32,7 @@ export const TransactionOptionsStruct = object({
|
|
|
34
32
|
*/ // TODO: Move this coercer to `@metamask/utils`.
|
|
35
33
|
to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value)=>{
|
|
36
34
|
if (value) {
|
|
37
|
-
return valueToBytes(value);
|
|
35
|
+
return bytesToHex(valueToBytes(value));
|
|
38
36
|
}
|
|
39
37
|
return bytesToHex(randomBytes(20));
|
|
40
38
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import {\n NotificationType,\n ComponentStruct,\n enumValue,\n} from '@metamask/snaps-sdk';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["NotificationType","ComponentStruct","enumValue","bytesToHex","JsonStruct","StrictHexStruct","valueToBytes","randomBytes","array","assign","bigint","coerce","defaulted","instance","literal","number","object","optional","string","type","union","BytesLikeStruct","Uint8Array","TransactionOptionsStruct","chainId","origin","from","value","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","SnapOptionsStruct","timeout","InterfaceStruct","content","SnapResponseStruct","id","response","result","error","notifications","message","InApp","Native"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,eAAe,EACfC,SAAS,QACJ,sBAAsB;AAC7B,SACEC,UAAU,EACVC,UAAU,EACVC,eAAe,EACfC,YAAY,QACP,kBAAkB;AACzB,SAASC,WAAW,QAAQ,SAAS;AACrC,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,QAAQ,EACRC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,KAAK,QACA,cAAc;AAErB,oDAAoD;AACpD,MAAMC,kBAAkBD,MAAM;IAC5BV;IACAK;IACAG;IACAL,SAASS;CACV;AAED,OAAO,MAAMC,2BAA2BP,OAAO;IAC7C;;GAEC,GACDQ,SAASZ,UAAUM,UAAU;IAE7B;;GAEC,GACDO,QAAQb,UAAUM,UAAU;IAE5B;;;GAGC,GACD,gDAAgD;IAChDQ,MAAMf,OAAON,iBAAiBY,SAASI,kBAAkB,CAACM;QACxD,IAAIA,OAAO;YACT,OAAOxB,WAAWG,aAAaqB;QACjC;QAEA,OAAOxB,WAAWI,YAAY;IAChC;IAEA;;;GAGC,GACD,gDAAgD;IAChDqB,IAAIjB,OAAON,iBAAiBY,SAASI,kBAAkB,CAACM;QACtD,IAAIA,OAAO;YACT,OAAOxB,WAAWG,aAAaqB;QACjC;QAEA,OAAOxB,WAAWI,YAAY;IAChC;IAEA;;;GAGC,GACDoB,OAAOf,UACLD,OAAON,iBAAiBgB,iBAAiB,CAACM,QACxCxB,WAAWG,aAAaqB,UAE1B;IAGF;;;GAGC,GACDE,UAAUjB,UACRD,OAAON,iBAAiBgB,iBAAiB,CAACM,QACxCxB,WAAWG,aAAaqB,UAE1BrB,aAAa;IAGf;;;;GAIC,GACDwB,cAAclB,UACZD,OAAON,iBAAiBgB,iBAAiB,CAACM,QACxCxB,WAAWG,aAAaqB,UAE1BrB,aAAa;IAGf;;;;GAIC,GACDyB,sBAAsBnB,UACpBD,OAAON,iBAAiBgB,iBAAiB,CAACM,QACxCxB,WAAWG,aAAaqB,UAE1BrB,aAAa;IAGf;;;GAGC,GACD0B,OAAOpB,UACLD,OAAON,iBAAiBgB,iBAAiB,CAACM,QACxCxB,WAAWG,aAAaqB,UAE1BrB,aAAa;IAGf;;;GAGC,GACD2B,MAAMrB,UACJD,OAAOS,MAAM;QAACf;QAAiBS,QAAQ;KAAM,GAAGO,iBAAiB,CAACM,QAChExB,WAAWG,aAAaqB,UAE1B;AAEJ,GAAG;AAEH,OAAO,MAAMO,oBAAoBlB,OAAO;IACtC;;;GAGC,GACDmB,SAASvB,UAAUK,SAASF,WAAW;AACzC,GAAG;AAEH,OAAO,MAAMqB,kBAAkBjB,KAAK;IAClCkB,SAASpB,SAAShB;AACpB,GAAG;AAEH,OAAO,MAAMqC,qBAAqB7B,OAChC2B,iBACApB,OAAO;IACLuB,IAAIrB;IAEJsB,UAAUpB,MAAM;QACdJ,OAAO;YACLyB,QAAQrC;QACV;QACAY,OAAO;YACL0B,OAAOtC;QACT;KACD;IAEDuC,eAAenC,MACbQ,OAAO;QACLuB,IAAIrB;QACJ0B,SAAS1B;QACTC,MAAMC,MAAM;YACVlB,UAAUF,iBAAiB6C,KAAK;YAChC3C,UAAUF,iBAAiB8C,MAAM;SAClC;IACH;AAEJ,IACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/types.ts"],"sourcesContent":["import type { NotificationType } from '@metamask/snaps-
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/types.ts"],"sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n // This API is injected into the page by the simulator. It allows us to\n // dispatch actions to the simulator, and read the state directly from the\n // Redux store.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n __SIMULATOR_API__: {\n dispatch: Dispatch;\n subscribe: (listener: () => void) => () => void;\n getState: () => ApplicationState;\n getRequestId: () => string;\n getNotifications: (requestId: string) => {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n };\n }\n}\n\nexport {};\n"],"names":[],"mappings":"AAAA,WAwBU"}
|
package/dist/esm/matchers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type { NotificationType } from '@metamask/snaps-rpc-methods';\nimport type { Component } from '@metamask/snaps-ui';\nimport type { EnumToUnion } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["expect","hasProperty","diff","matcherErrorMessage","matcherHint","printReceived","printWithType","RECEIVED_COLOR","is","InterfaceStruct","SnapResponseStruct","assertActualIsSnapResponse","actual","matcherName","options","Error","undefined","assertHasInterface","content","toRespondWith","expected","response","message","utils","printExpected","error","pass","equals","result","toRespondWithError","toSendNotification","type","notifications","some","notification","toRender","difference","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;AAGzE,SAASA,MAAM,QAAQ,gBAAgB;AAKvC,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SACEC,IAAI,EACJC,mBAAmB,EACnBC,WAAW,EACXC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,qBAAqB;AAC5B,SAASC,EAAE,QAAQ,cAAc;AAEjC,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,cAAc;AAGlE;;;;;;CAMC,GACD,SAASC,2BACPC,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQF,qBAAqB;QACnC,MAAM,IAAIK,MACRZ,oBACEC,YAAYS,aAAaG,WAAWA,WAAWF,UAC/C,CAAC,EAAEP,eACD,YACA,uDAAuD,CAAC,EAC1DD,cAAc,YAAYM,QAAQP;IAGxC;AACF;AAEA;;;;;;;CAOC,GACD,SAASY,mBACPL,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQH,oBAAoB,CAACG,OAAOM,OAAO,EAAE;QACnD,MAAM,IAAIH,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,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACG,KAAK,CAAClB,aAAa,CAACa,SAAS,CAAC,GAChD,CAAC,EAAEkB,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC,GAC3D,IACE,CAAC,EAAE,IAAI,CAACb,KAAK,CAACnB,WAAW,CAAC,oBAAoB,IAAI,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACmB,KAAK,CAACC,aAAa,CAACJ,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACG,KAAK,CAAClB,aAAa,CAACa,SAAS,CAAC,GAChD,CAAC,EAAEkB,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEd;QAASI;IAAK;AACzB,EAAE;AAEF1B,OAAOqC,MAAM,CAAC;IACZlB;IACAU;IACAC;IACAK;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["expect","hasProperty","diff","matcherErrorMessage","matcherHint","printReceived","printWithType","RECEIVED_COLOR","is","InterfaceStruct","SnapResponseStruct","assertActualIsSnapResponse","actual","matcherName","options","Error","undefined","assertHasInterface","content","toRespondWith","expected","response","message","utils","printExpected","error","pass","equals","result","toRespondWithError","toSendNotification","type","notifications","some","notification","toRender","difference","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;AAGzE,SAASA,MAAM,QAAQ,gBAAgB;AAOvC,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SACEC,IAAI,EACJC,mBAAmB,EACnBC,WAAW,EACXC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,qBAAqB;AAC5B,SAASC,EAAE,QAAQ,cAAc;AAEjC,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,cAAc;AAGlE;;;;;;CAMC,GACD,SAASC,2BACPC,MAAe,EACfC,WAAmB,EACnBC,OAA4B;IAE5B,IAAI,CAACN,GAAGI,QAAQF,qBAAqB;QACnC,MAAM,IAAIK,MACRZ,oBACEC,YAAYS,aAAaG,WAAWA,WAAWF,UAC/C,CAAC,EAAEP,eACD,YACA,uDAAuD,CAAC,EAC1DD,cAAc,YAAYM,QAAQP;IAGxC;AACF;AAEA;;;;;;;CAOC,GACD,SAASY,mBACPL,MAAe,E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CAACH,KAAK,CAACnB,WAAW,CAAC,wBAAwB,IAAI,CAAC,GACvD,CAAC,UAAU,EAAE,IAAI,CAACmB,KAAK,CAACC,aAAa,CAACJ,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACG,KAAK,CAAClB,aAAa,CAACa,SAAS,CAAC,GAChD,CAAC,EAAEkB,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC,GAC3D,IACE,CAAC,EAAE,IAAI,CAACb,KAAK,CAACnB,WAAW,CAAC,oBAAoB,IAAI,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACmB,KAAK,CAACC,aAAa,CAACJ,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACG,KAAK,CAAClB,aAAa,CAACa,SAAS,CAAC,GAChD,CAAC,EAAEkB,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEd;QAASI;IAAK;AACzB,EAAE;AAEF1B,OAAOqC,MAAM,CAAC;IACZlB;IACAU;IACAC;IACAK;AACF"}
|
package/dist/esm/types.js
CHANGED
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JsonRpcId, JsonRpcParams } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\n\nimport type {\n Mock,\n MockJsonRpcOptions,\n MockOptions,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './internals';\n\n/* eslint-disable @typescript-eslint/consistent-type-definitions */\ndeclare module 'expect' {\n interface AsymmetricMatchers {\n toRespondWith(response: unknown): void;\n toRespondWithError(error: unknown): void;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): void;\n toRender(component: Component): void;\n }\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface Matchers<R> {\n toRespondWith(response: unknown): R;\n toRespondWithError(error: unknown): R;\n toSendNotification(\n message: string,\n type?: EnumToUnion<NotificationType>,\n ): R;\n toRender(component: Component): R;\n }\n}\n/* eslint-enable @typescript-eslint/consistent-type-definitions */\n\n/**\n * Deeply partialize a type.\n *\n * @template Type - The type to partialize.\n * @returns The deeply partialized type.\n * @example\n * ```ts\n * type Foo = {\n * bar: {\n * baz: string;\n * };\n * qux: number;\n * };\n *\n * type PartialFoo = DeepPartial<Foo>;\n * // { bar?: { baz?: string; }; qux?: number; }\n * ```\n */\nexport type DeepPartial<Type> = {\n [Key in keyof Type]?: Type[Key] extends Record<string, unknown>\n ? DeepPartial<Type[Key]>\n : Type[Key];\n};\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: Component;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: Component;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: Component;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\nexport type SnapInterface =\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * ```ts\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n * ```\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponse>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n // TODO: Find a way to do this automatically.\n close(): Promise<void>;\n\n /**\n * Enable network mocking for the snap.\n *\n * @param options - The options for the network mocking.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mock(options: DeepPartial<MockOptions>): Promise<Mock>;\n\n /**\n * Enable JSON-RPC provider mocking for the snap. This will mock any requests\n * sent through the `ethereum` global, with the specified `method`.\n *\n * @param options - The options for the JSON-RPC mocking.\n * @param options.method - The JSON-RPC method to mock, e.g.,\n * `eth_blockNumber`.\n * @param options.result - The JSON value to return.\n * @returns A {@link Mock} object, with an `unmock` function.\n */\n mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;\n};\n\nexport type SnapResponse = Infer<typeof SnapResponseStruct>;\n"],"names":[],"mappings":"AAAA,WA4S4D"}
|
|
@@ -65,8 +65,8 @@ export declare type MockOptions = Infer<typeof MockOptionsStruct>;
|
|
|
65
65
|
*/
|
|
66
66
|
export declare function mock(page: Page, options: DeepPartial<MockOptions>): Promise<Mock>;
|
|
67
67
|
declare const MockJsonRpcOptionsStruct: Struct<{
|
|
68
|
-
method: string;
|
|
69
68
|
result: import("@metamask/utils").Json;
|
|
69
|
+
method: string;
|
|
70
70
|
}, {
|
|
71
71
|
method: Struct<string, null>;
|
|
72
72
|
result: Struct<import("@metamask/utils").Json, unknown>;
|
|
@@ -21,35 +21,54 @@ export declare function request(page: Page, { origin, ...options }: RequestOptio
|
|
|
21
21
|
export declare function sendTransaction(page: Page, options: Partial<TransactionOptions>): Promise<{
|
|
22
22
|
id: string;
|
|
23
23
|
response: ({
|
|
24
|
-
result: import("@metamask/
|
|
24
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
25
25
|
} | {
|
|
26
|
-
error: import("@metamask/
|
|
26
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
27
27
|
}) & Record<"error", unknown>;
|
|
28
28
|
notifications: never[];
|
|
29
29
|
content?: undefined;
|
|
30
30
|
} | {
|
|
31
31
|
id: string;
|
|
32
32
|
response: {
|
|
33
|
-
result: import("@metamask/
|
|
33
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
34
34
|
};
|
|
35
35
|
notifications: never[];
|
|
36
|
-
content: import("@metamask/snaps-
|
|
36
|
+
content: import("@metamask/snaps-sdk").Panel | {
|
|
37
37
|
value: string;
|
|
38
|
-
type: import("@metamask/snaps-
|
|
38
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
39
|
+
sensitive?: boolean | undefined;
|
|
39
40
|
} | {
|
|
40
|
-
type: import("@metamask/snaps-
|
|
41
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
41
42
|
} | {
|
|
42
43
|
value: string;
|
|
43
|
-
type: import("@metamask/snaps-
|
|
44
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
44
45
|
} | {
|
|
45
|
-
|
|
46
|
+
value: string;
|
|
47
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
48
|
+
} | {
|
|
49
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
46
50
|
} | {
|
|
47
51
|
value: string;
|
|
48
|
-
type: import("@metamask/snaps-
|
|
52
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
49
53
|
markdown?: boolean | undefined;
|
|
50
54
|
} | {
|
|
51
55
|
value: string;
|
|
52
|
-
type: import("@metamask/snaps-
|
|
56
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
57
|
+
} | {
|
|
58
|
+
value: {
|
|
59
|
+
value: string;
|
|
60
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
61
|
+
} | {
|
|
62
|
+
value: string;
|
|
63
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
64
|
+
markdown?: boolean | undefined;
|
|
65
|
+
} | {
|
|
66
|
+
value: string;
|
|
67
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
68
|
+
};
|
|
69
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
70
|
+
label: string;
|
|
71
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
53
72
|
};
|
|
54
73
|
}>;
|
|
55
74
|
/**
|
|
@@ -4,11 +4,11 @@ export declare const TransactionOptionsStruct: import("superstruct").Struct<{
|
|
|
4
4
|
origin: string;
|
|
5
5
|
value: `0x${string}`;
|
|
6
6
|
chainId: string;
|
|
7
|
-
nonce: `0x${string}`;
|
|
8
|
-
maxPriorityFeePerGas: `0x${string}`;
|
|
9
|
-
maxFeePerGas: `0x${string}`;
|
|
10
7
|
to: `0x${string}`;
|
|
11
8
|
gasLimit: `0x${string}`;
|
|
9
|
+
maxFeePerGas: `0x${string}`;
|
|
10
|
+
maxPriorityFeePerGas: `0x${string}`;
|
|
11
|
+
nonce: `0x${string}`;
|
|
12
12
|
}, {
|
|
13
13
|
/**
|
|
14
14
|
* The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.
|
|
@@ -71,49 +71,87 @@ export declare const SnapOptionsStruct: import("superstruct").Struct<{
|
|
|
71
71
|
timeout: import("superstruct").Struct<number | undefined, null>;
|
|
72
72
|
}>;
|
|
73
73
|
export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
74
|
-
content?: import("@metamask/snaps-
|
|
74
|
+
content?: import("@metamask/snaps-sdk").Panel | {
|
|
75
75
|
value: string;
|
|
76
|
-
type: import("@metamask/snaps-
|
|
76
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
77
|
+
sensitive?: boolean | undefined;
|
|
78
|
+
} | {
|
|
79
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
77
80
|
} | {
|
|
78
|
-
|
|
81
|
+
value: string;
|
|
82
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
79
83
|
} | {
|
|
80
84
|
value: string;
|
|
81
|
-
type: import("@metamask/snaps-
|
|
85
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
82
86
|
} | {
|
|
83
|
-
type: import("@metamask/snaps-
|
|
87
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
84
88
|
} | {
|
|
85
89
|
value: string;
|
|
86
|
-
type: import("@metamask/snaps-
|
|
90
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
87
91
|
markdown?: boolean | undefined;
|
|
88
92
|
} | {
|
|
89
93
|
value: string;
|
|
90
|
-
type: import("@metamask/snaps-
|
|
94
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
95
|
+
} | {
|
|
96
|
+
value: {
|
|
97
|
+
value: string;
|
|
98
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
99
|
+
} | {
|
|
100
|
+
value: string;
|
|
101
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
102
|
+
markdown?: boolean | undefined;
|
|
103
|
+
} | {
|
|
104
|
+
value: string;
|
|
105
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
106
|
+
};
|
|
107
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
108
|
+
label: string;
|
|
109
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
91
110
|
} | undefined;
|
|
92
111
|
}, {
|
|
93
|
-
content: import("superstruct").Struct<import("@metamask/snaps-
|
|
112
|
+
content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
|
|
94
113
|
value: string;
|
|
95
|
-
type: import("@metamask/snaps-
|
|
114
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
115
|
+
sensitive?: boolean | undefined;
|
|
96
116
|
} | {
|
|
97
|
-
type: import("@metamask/snaps-
|
|
117
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
98
118
|
} | {
|
|
99
119
|
value: string;
|
|
100
|
-
type: import("@metamask/snaps-
|
|
120
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
101
121
|
} | {
|
|
102
|
-
|
|
122
|
+
value: string;
|
|
123
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
124
|
+
} | {
|
|
125
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
103
126
|
} | {
|
|
104
127
|
value: string;
|
|
105
|
-
type: import("@metamask/snaps-
|
|
128
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
106
129
|
markdown?: boolean | undefined;
|
|
107
130
|
} | {
|
|
108
131
|
value: string;
|
|
109
|
-
type: import("@metamask/snaps-
|
|
132
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
133
|
+
} | {
|
|
134
|
+
value: {
|
|
135
|
+
value: string;
|
|
136
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
137
|
+
} | {
|
|
138
|
+
value: string;
|
|
139
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
140
|
+
markdown?: boolean | undefined;
|
|
141
|
+
} | {
|
|
142
|
+
value: string;
|
|
143
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
144
|
+
};
|
|
145
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
146
|
+
label: string;
|
|
147
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
110
148
|
} | undefined, null>;
|
|
111
149
|
}>;
|
|
112
150
|
export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
113
151
|
response: {
|
|
114
|
-
result: import("@metamask/
|
|
152
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
115
153
|
} | {
|
|
116
|
-
error: import("@metamask/
|
|
154
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
117
155
|
};
|
|
118
156
|
id: string;
|
|
119
157
|
notifications: {
|
|
@@ -121,30 +159,49 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
121
159
|
type: "native" | "inApp";
|
|
122
160
|
id: string;
|
|
123
161
|
}[];
|
|
124
|
-
content?: import("@metamask/snaps-
|
|
162
|
+
content?: import("@metamask/snaps-sdk").Panel | {
|
|
125
163
|
value: string;
|
|
126
|
-
type: import("@metamask/snaps-
|
|
164
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
165
|
+
sensitive?: boolean | undefined;
|
|
127
166
|
} | {
|
|
128
|
-
type: import("@metamask/snaps-
|
|
167
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
168
|
+
} | {
|
|
169
|
+
value: string;
|
|
170
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
129
171
|
} | {
|
|
130
172
|
value: string;
|
|
131
|
-
type: import("@metamask/snaps-
|
|
173
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
132
174
|
} | {
|
|
133
|
-
type: import("@metamask/snaps-
|
|
175
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
134
176
|
} | {
|
|
135
177
|
value: string;
|
|
136
|
-
type: import("@metamask/snaps-
|
|
178
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
137
179
|
markdown?: boolean | undefined;
|
|
138
180
|
} | {
|
|
139
181
|
value: string;
|
|
140
|
-
type: import("@metamask/snaps-
|
|
182
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
183
|
+
} | {
|
|
184
|
+
value: {
|
|
185
|
+
value: string;
|
|
186
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
187
|
+
} | {
|
|
188
|
+
value: string;
|
|
189
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
190
|
+
markdown?: boolean | undefined;
|
|
191
|
+
} | {
|
|
192
|
+
value: string;
|
|
193
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
194
|
+
};
|
|
195
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
196
|
+
label: string;
|
|
197
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
141
198
|
} | undefined;
|
|
142
199
|
}, {
|
|
143
200
|
id: import("superstruct").Struct<string, null>;
|
|
144
201
|
response: import("superstruct").Struct<{
|
|
145
|
-
result: import("@metamask/
|
|
202
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
146
203
|
} | {
|
|
147
|
-
error: import("@metamask/
|
|
204
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
148
205
|
}, null>;
|
|
149
206
|
notifications: import("superstruct").Struct<{
|
|
150
207
|
message: string;
|
|
@@ -159,22 +216,41 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
159
216
|
message: import("superstruct").Struct<string, null>;
|
|
160
217
|
type: import("superstruct").Struct<"native" | "inApp", null>;
|
|
161
218
|
}>>;
|
|
162
|
-
content: import("superstruct").Struct<import("@metamask/snaps-
|
|
219
|
+
content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
|
|
163
220
|
value: string;
|
|
164
|
-
type: import("@metamask/snaps-
|
|
221
|
+
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
222
|
+
sensitive?: boolean | undefined;
|
|
223
|
+
} | {
|
|
224
|
+
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
165
225
|
} | {
|
|
166
|
-
|
|
226
|
+
value: string;
|
|
227
|
+
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
167
228
|
} | {
|
|
168
229
|
value: string;
|
|
169
|
-
type: import("@metamask/snaps-
|
|
230
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
170
231
|
} | {
|
|
171
|
-
type: import("@metamask/snaps-
|
|
232
|
+
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
172
233
|
} | {
|
|
173
234
|
value: string;
|
|
174
|
-
type: import("@metamask/snaps-
|
|
235
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
175
236
|
markdown?: boolean | undefined;
|
|
176
237
|
} | {
|
|
177
238
|
value: string;
|
|
178
|
-
type: import("@metamask/snaps-
|
|
239
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
240
|
+
} | {
|
|
241
|
+
value: {
|
|
242
|
+
value: string;
|
|
243
|
+
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
244
|
+
} | {
|
|
245
|
+
value: string;
|
|
246
|
+
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
247
|
+
markdown?: boolean | undefined;
|
|
248
|
+
} | {
|
|
249
|
+
value: string;
|
|
250
|
+
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
251
|
+
};
|
|
252
|
+
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
253
|
+
label: string;
|
|
254
|
+
variant?: "default" | "warning" | "critical" | undefined;
|
|
179
255
|
} | undefined, null>;
|
|
180
256
|
}>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { NotificationType } from '@metamask/snaps-
|
|
1
|
+
import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
|
|
2
2
|
import type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';
|
|
3
|
-
import type { EnumToUnion } from '@metamask/snaps-utils';
|
|
4
3
|
declare global {
|
|
5
4
|
interface Window {
|
|
6
5
|
__SIMULATOR_API__: {
|
package/dist/types/matchers.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { MatcherFunction } from '@jest/expect';
|
|
2
|
-
import type { NotificationType } from '@metamask/snaps-
|
|
3
|
-
import type { Component } from '@metamask/snaps-ui';
|
|
4
|
-
import type { EnumToUnion } from '@metamask/snaps-utils';
|
|
2
|
+
import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
|
|
5
3
|
import type { Json } from '@metamask/utils';
|
|
6
4
|
/**
|
|
7
5
|
* Check if a JSON-RPC response matches the expected value. This matcher is
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { NotificationType } from '@metamask/snaps-
|
|
2
|
-
import type { Component } from '@metamask/snaps-ui';
|
|
3
|
-
import type { EnumToUnion } from '@metamask/snaps-utils';
|
|
1
|
+
import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
|
|
4
2
|
import type { JsonRpcId, JsonRpcParams } from '@metamask/utils';
|
|
5
3
|
import type { Infer } from 'superstruct';
|
|
6
4
|
import type { Mock, MockJsonRpcOptions, MockOptions, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
|
|
@@ -238,4 +236,3 @@ export declare type Snap = {
|
|
|
238
236
|
mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;
|
|
239
237
|
};
|
|
240
238
|
export declare type SnapResponse = Infer<typeof SnapResponseStruct>;
|
|
241
|
-
export { NotificationType } from '@metamask/snaps-rpc-methods';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -36,12 +36,11 @@
|
|
|
36
36
|
"@jest/environment": "^29.5.0",
|
|
37
37
|
"@jest/expect": "^29.5.0",
|
|
38
38
|
"@jest/globals": "^29.5.0",
|
|
39
|
-
"@metamask/snaps-execution-environments": "^3.1
|
|
40
|
-
"@metamask/snaps-
|
|
41
|
-
"@metamask/snaps-simulator": "^2.
|
|
42
|
-
"@metamask/snaps-
|
|
43
|
-
"@metamask/
|
|
44
|
-
"@metamask/utils": "^8.1.0",
|
|
39
|
+
"@metamask/snaps-execution-environments": "^3.4.1",
|
|
40
|
+
"@metamask/snaps-sdk": "^1.2.0",
|
|
41
|
+
"@metamask/snaps-simulator": "^2.4.1",
|
|
42
|
+
"@metamask/snaps-utils": "^5.0.0",
|
|
43
|
+
"@metamask/utils": "^8.2.1",
|
|
45
44
|
"express": "^4.18.2",
|
|
46
45
|
"jest-environment-node": "^29.5.0",
|
|
47
46
|
"jest-matcher-utils": "^29.5.0",
|
|
@@ -52,7 +51,7 @@
|
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@lavamoat/allow-scripts": "^2.5.1",
|
|
55
|
-
"@metamask/auto-changelog": "^3.3
|
|
54
|
+
"@metamask/auto-changelog": "^3.4.3",
|
|
56
55
|
"@metamask/eslint-config": "^12.1.0",
|
|
57
56
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
58
57
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|