@metamask/snaps-jest 8.4.0 → 8.6.0
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 +78 -1
- package/LICENSE +15 -0
- package/README.md +33 -0
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.cts +2 -2
- package/dist/environment.d.cts.map +1 -1
- package/dist/environment.d.mts +2 -2
- package/dist/environment.d.mts.map +1 -1
- package/dist/environment.mjs.map +1 -1
- package/dist/helpers.cjs +9 -108
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -2
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +1 -2
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +11 -110
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.cts.map +1 -1
- package/dist/matchers.d.mts.map +1 -1
- package/dist/matchers.mjs.map +1 -1
- package/package.json +37 -19
- package/dist/types/index.cjs +0 -18
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -2
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -2
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/types.cjs +0 -3
- package/dist/types/types.cjs.map +0 -1
- package/dist/types/types.d.cts +0 -393
- package/dist/types/types.d.cts.map +0 -1
- package/dist/types/types.d.mts +0 -393
- package/dist/types/types.d.mts.map +0 -1
- package/dist/types/types.mjs +0 -2
- package/dist/types/types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
|
|
2
3
|
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
4
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
@@ -6,21 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
7
|
|
|
7
8
|
## [Unreleased]
|
|
8
9
|
|
|
10
|
+
## [8.6.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add function to test `onKeyringRequest` ([#2777](https://github.com/MetaMask/snaps/pull/2777))
|
|
15
|
+
- The `onKeyringRequest` function can be used to test keyring requests.
|
|
16
|
+
|
|
17
|
+
## [8.5.0]
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Move helper functions to simulation package ([#2769](https://github.com/MetaMask/snaps/pull/2769))
|
|
22
|
+
|
|
9
23
|
## [8.4.0]
|
|
24
|
+
|
|
10
25
|
### Added
|
|
26
|
+
|
|
11
27
|
- Add support for selector component ([#2724](https://github.com/MetaMask/snaps/pull/2724))
|
|
12
28
|
- Interfaces now have a `selectFromSelector` function that can be used to
|
|
13
29
|
select an option from a selector.
|
|
14
30
|
|
|
15
31
|
### Changed
|
|
32
|
+
|
|
16
33
|
- Extract simulation part of `snaps-jest` to separate package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
|
|
17
34
|
|
|
18
35
|
## [8.3.2]
|
|
36
|
+
|
|
19
37
|
### Fixed
|
|
38
|
+
|
|
20
39
|
- Fix invalid types in type declaration in some cases ([#2714](https://github.com/MetaMask/snaps/pull/2714))
|
|
21
40
|
|
|
22
41
|
## [8.3.1]
|
|
42
|
+
|
|
23
43
|
### Fixed
|
|
44
|
+
|
|
24
45
|
- Fix ESM version of the package ([#2682](https://github.com/MetaMask/snaps/pull/2682))
|
|
25
46
|
- This fixes the ESM version of the package to be fully compliant with the ESM
|
|
26
47
|
standard.
|
|
@@ -28,44 +49,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
28
49
|
- Bump other MetaMask dependencies ([#2703](https://github.com/MetaMask/snaps/pull/2703))
|
|
29
50
|
|
|
30
51
|
## [8.3.0]
|
|
52
|
+
|
|
31
53
|
### Added
|
|
54
|
+
|
|
32
55
|
- Add support for `snap_getPreferences` ([#2607](https://github.com/MetaMask/snaps/pull/2607))
|
|
33
56
|
- Add `RadioGroup` component ([#2592](https://github.com/MetaMask/snaps/pull/2592))
|
|
34
57
|
- Add support for custom dialogs in `snaps-jest` ([#2526](https://github.com/MetaMask/snaps/pull/2526), [#2509](https://github.com/MetaMask/snaps/pull/2509))
|
|
35
58
|
|
|
36
59
|
### Changed
|
|
60
|
+
|
|
37
61
|
- Replace `superstruct` with ESM-compatible fork `@metamask/superstruct` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
38
62
|
|
|
39
63
|
## [8.2.0]
|
|
64
|
+
|
|
40
65
|
### Added
|
|
66
|
+
|
|
41
67
|
- Add support for `Checkbox` to `snaps-jest` ([#2515](https://github.com/MetaMask/snaps/pull/2515))
|
|
42
68
|
- Checkboxes can be interacted with using `clickElement`.
|
|
43
69
|
- Add support for `FileInput` to `snaps-jest` ([#2494](https://github.com/MetaMask/snaps/pull/2494))
|
|
44
70
|
- Files can be uploaded to file inputs using `uploadFile`.
|
|
45
71
|
|
|
46
72
|
## [8.1.3]
|
|
73
|
+
|
|
47
74
|
### Changed
|
|
75
|
+
|
|
48
76
|
- Bump MetaMask dependencies ([#2460](https://github.com/MetaMask/snaps/pull/2460), [#2477](https://github.com/MetaMask/snaps/pull/2477))
|
|
49
77
|
|
|
50
78
|
## [8.1.2]
|
|
79
|
+
|
|
51
80
|
### Fixed
|
|
81
|
+
|
|
52
82
|
- Fix invalid `@metamask/snaps-sdk` imports ([#2452](https://github.com/MetaMask/snaps/pull/2452))
|
|
53
83
|
|
|
54
84
|
## [8.1.1]
|
|
85
|
+
|
|
55
86
|
### Changed
|
|
87
|
+
|
|
56
88
|
- Bump `@metamask/key-tree` from `9.1.0` to `9.1.1` ([#2431](https://github.com/MetaMask/snaps/pull/2431))
|
|
57
89
|
|
|
58
90
|
## [8.1.0]
|
|
91
|
+
|
|
59
92
|
### Added
|
|
93
|
+
|
|
60
94
|
- Add `selectInDropdown` to be used with the newly added `Dropdown` component ([#2420](https://github.com/MetaMask/snaps/pull/2420))
|
|
61
95
|
- Add `context` field to `snap_createInterface` ([#2413](https://github.com/MetaMask/snaps/pull/2413))
|
|
62
96
|
|
|
63
97
|
### Fixed
|
|
98
|
+
|
|
64
99
|
- Properly handle invalid interfaces during test ([#2433](https://github.com/MetaMask/snaps/pull/2433))
|
|
65
100
|
- Properly diff when using legacy UI with `toRender` matcher ([#2432](https://github.com/MetaMask/snaps/pull/2432))
|
|
66
101
|
|
|
67
102
|
## [8.0.0]
|
|
103
|
+
|
|
68
104
|
### Added
|
|
105
|
+
|
|
69
106
|
- **BREAKING:** Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
|
|
70
107
|
- It's now possible to use JSX components from `@metamask/snaps-sdk` to build
|
|
71
108
|
user interfaces for Snaps.
|
|
@@ -75,38 +112,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
75
112
|
need to update your tests to check the JSX format.
|
|
76
113
|
|
|
77
114
|
### Changed
|
|
115
|
+
|
|
78
116
|
- Bump `@metamask/base-controller` from `5.0.1` to `5.0.2` ([#2375](https://github.com/MetaMask/snaps/pull/2375))
|
|
79
117
|
|
|
80
118
|
## [7.0.2]
|
|
119
|
+
|
|
81
120
|
### Changed
|
|
121
|
+
|
|
82
122
|
- Bump `@metamask/snaps-execution-environments` to latest ([#2339](https://github.com/MetaMask/snaps/pull/2339))
|
|
83
123
|
|
|
84
124
|
## [7.0.1]
|
|
125
|
+
|
|
85
126
|
### Fixed
|
|
127
|
+
|
|
86
128
|
- Improve correctness of `clickElement` ([#2334](https://github.com/MetaMask/snaps/pull/2334))
|
|
87
129
|
- The function should now behave closer to the client implementation.
|
|
88
130
|
|
|
89
131
|
## [7.0.0]
|
|
132
|
+
|
|
90
133
|
### Added
|
|
134
|
+
|
|
91
135
|
- **BREAKING:** Support Interactive UI in `snaps-jest` ([#2286](https://github.com/MetaMask/snaps/pull/2286))
|
|
92
136
|
- Remove `content` from the Snap response, instead `getInterface()` must be used
|
|
93
137
|
- `clickElement` and `typeInField` can be used on the interface return value to simulate actions
|
|
94
138
|
|
|
95
139
|
### Changed
|
|
140
|
+
|
|
96
141
|
- Improve Jest expect types ([#2308](https://github.com/MetaMask/snaps/pull/2308))
|
|
97
142
|
- Refactor to support changes to encryption ([#2316](https://github.com/MetaMask/snaps/pull/2316))
|
|
98
143
|
|
|
99
144
|
## [6.0.2]
|
|
145
|
+
|
|
100
146
|
### Changed
|
|
147
|
+
|
|
101
148
|
- Bump MetaMask dependencies ([#2270](https://github.com/MetaMask/snaps/pull/2270))
|
|
102
149
|
- Bump @metamask/json-rpc-engine from 7.3.2 to 7.3.3 ([#2247](https://github.com/MetaMask/snaps/pull/2247))
|
|
103
150
|
|
|
104
151
|
## [6.0.1]
|
|
152
|
+
|
|
105
153
|
### Fixed
|
|
154
|
+
|
|
106
155
|
- Fix minor build configuration problems ([#2220](https://github.com/MetaMask/snaps/pull/2220))
|
|
107
156
|
|
|
108
157
|
## [6.0.0]
|
|
158
|
+
|
|
109
159
|
### Changed
|
|
160
|
+
|
|
110
161
|
- **BREAKING:** Update ESM build to be fully compliant with the ESM standard ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
111
162
|
- **BREAKING:** Move Node.js exports to separate export ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
112
163
|
- The default export is now browser-compatible.
|
|
@@ -114,7 +165,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
114
165
|
- Bump `@metamask/rpc-errors` to `^6.2.1` ([#2209](https://github.com/MetaMask/snaps/pull/2209))
|
|
115
166
|
|
|
116
167
|
## [5.0.0]
|
|
168
|
+
|
|
117
169
|
### Added
|
|
170
|
+
|
|
118
171
|
- **BREAKING:** Implement testing framework using Node.js executor ([#1982](https://github.com/MetaMask/snaps/pull/1982), [#2118](https://github.com/MetaMask/snaps/pull/2118))
|
|
119
172
|
- The network mocking functionality was removed, but may be reintroduced in a future version.
|
|
120
173
|
- `mockJsonRpc` no longer returns a `Promise`.
|
|
@@ -125,30 +178,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
125
178
|
- Add `snap_getClientStatus` support ([#2159](https://github.com/MetaMask/snaps/pull/2159))
|
|
126
179
|
|
|
127
180
|
### Changed
|
|
181
|
+
|
|
128
182
|
- Bump several MetaMask dependencies ([#2101](https://github.com/MetaMask/snaps/pull/2101), [#2100](https://github.com/MetaMask/snaps/pull/2100), [#2129](https://github.com/MetaMask/snaps/pull/2129), [#2140](https://github.com/MetaMask/snaps/pull/2140), [#2141](https://github.com/MetaMask/snaps/pull/2141), [#2142](https://github.com/MetaMask/snaps/pull/2142))
|
|
129
183
|
|
|
130
184
|
## [4.0.1]
|
|
185
|
+
|
|
131
186
|
### Fixed
|
|
187
|
+
|
|
132
188
|
- Fix coercing of address values in `sendTransaction` function ([#1970](https://github.com/MetaMask/snaps/pull/1970))
|
|
133
189
|
|
|
134
190
|
## [4.0.0]
|
|
191
|
+
|
|
135
192
|
### Changed
|
|
193
|
+
|
|
136
194
|
- Use `@metamask/snaps-sdk` package ([#1930](https://github.com/MetaMask/snaps/pull/1930),
|
|
137
195
|
[#1950](https://github.com/MetaMask/snaps/pull/1950), [#1954](https://github.com/MetaMask/snaps/pull/1954))
|
|
138
196
|
- This package replaces the `@metamask/snaps-types` and
|
|
139
197
|
- `@metamask/snaps-ui` packages.
|
|
140
198
|
|
|
141
199
|
### Removed
|
|
200
|
+
|
|
142
201
|
- **BREAKING**: `DialogType`, `ManageStateOperation`, `NotificationType` are no
|
|
143
202
|
longer re-exported from `@metamask/snaps-jest` ([#1930](https://github.com/MetaMask/snaps/pull/1930))
|
|
144
203
|
- These enums can now be imported from `@metamask/snaps-sdk` instead.
|
|
145
204
|
|
|
146
205
|
## [3.1.0]
|
|
206
|
+
|
|
147
207
|
### Added
|
|
208
|
+
|
|
148
209
|
- Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
|
|
149
210
|
|
|
150
211
|
## [3.0.0]
|
|
212
|
+
|
|
151
213
|
### Changed
|
|
214
|
+
|
|
152
215
|
- **BREAKING:** Improve error handling ([#1841](https://github.com/MetaMask/snaps/pull/1841))
|
|
153
216
|
- This is a breaking change, because errors returned by the Snap now have a different format. For example, if the Snap throws a JSON-RPC method not found error, previously, the following error would be returned:
|
|
154
217
|
```ts
|
|
@@ -177,32 +240,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
177
240
|
```
|
|
178
241
|
|
|
179
242
|
## [2.0.0]
|
|
243
|
+
|
|
180
244
|
### Changed
|
|
245
|
+
|
|
181
246
|
- **BREAKING:** Bump minimum Node.js version to `^18.16.0` ([#1741](https://github.com/MetaMask/snaps/pull/1741))
|
|
182
247
|
|
|
183
248
|
## [1.0.0]
|
|
249
|
+
|
|
184
250
|
### Changed
|
|
251
|
+
|
|
185
252
|
- Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
|
|
186
253
|
|
|
187
254
|
## [0.37.5-flask.1]
|
|
255
|
+
|
|
188
256
|
### Changed
|
|
257
|
+
|
|
189
258
|
- Bump `metamask/utils` and `metamask/snaps-registry` ([#1738](https://github.com/MetaMask/snaps/pull/1738), [#1694](https://github.com/MetaMask/snaps/pull/1694))
|
|
190
259
|
|
|
191
260
|
## [0.37.4-flask.1]
|
|
261
|
+
|
|
192
262
|
### Fixed
|
|
263
|
+
|
|
193
264
|
- Remove unused dependencies ([#1680](https://github.com/MetaMask/snaps/pull/1680))
|
|
194
265
|
|
|
195
266
|
## [0.37.3-flask.1]
|
|
267
|
+
|
|
196
268
|
### Changed
|
|
269
|
+
|
|
197
270
|
- Bump `semver` to `^7.5.4` ([#1631](https://github.com/MetaMask/snaps/pull/1631))
|
|
198
271
|
|
|
199
272
|
## [0.37.2-flask.1]
|
|
273
|
+
|
|
200
274
|
### Changed
|
|
275
|
+
|
|
201
276
|
- Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
|
|
202
277
|
- The version of the package no longer needs to match the version of all other
|
|
203
278
|
MetaMask Snaps packages.
|
|
204
279
|
|
|
205
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.
|
|
280
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.6.0...HEAD
|
|
281
|
+
[8.6.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.5.0...@metamask/snaps-jest@8.6.0
|
|
282
|
+
[8.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.4.0...@metamask/snaps-jest@8.5.0
|
|
206
283
|
[8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.2...@metamask/snaps-jest@8.4.0
|
|
207
284
|
[8.3.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.1...@metamask/snaps-jest@8.3.2
|
|
208
285
|
[8.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.0...@metamask/snaps-jest@8.3.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -329,6 +329,39 @@ describe('MySnap', () => {
|
|
|
329
329
|
});
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
+
### `snap.onKeyringRequest`
|
|
333
|
+
|
|
334
|
+
The `onKeyringRequest` function can be used to process keyring request. It takes
|
|
335
|
+
few arguments, which are similar to a JSON-RPC request object. It returns
|
|
336
|
+
a promise that resolves to the response from the keyring request handler.
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
import { installSnap } from '@metamask/snaps-jest';
|
|
340
|
+
|
|
341
|
+
describe('onKeyringRequest', () => {
|
|
342
|
+
it('sends keyring request', async () => {
|
|
343
|
+
const { onKeyringRequest } = await installSnap();
|
|
344
|
+
|
|
345
|
+
const response = await onKeyringRequest({
|
|
346
|
+
origin: 'https://metamask.github.io',
|
|
347
|
+
params: {
|
|
348
|
+
options: {
|
|
349
|
+
privateKey: 'foo-bar',
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
method: 'keyring_createAccount',
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
expect(response).toBe({
|
|
356
|
+
/* Add expected result here */
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
It returns an object with a response, and some additional metadata, which can be
|
|
363
|
+
checked using the [Jest matchers](#jest-matchers):
|
|
364
|
+
|
|
332
365
|
### Jest matchers
|
|
333
366
|
|
|
334
367
|
`@metamask/snaps-jest` includes a set of Jest matchers that can be used to
|
package/dist/environment.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,iEAAyD;AAMzD,2CAA6D;AAE7D,kFAAoD;AAGpD,qDAAsD;AAEtD,2CAAuC;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAa,gBAAiB,SAAQ,+BAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqD;QAUnD,uBAAA,IAAI,6BAAY,IAAA,oBAAU,EAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,IAAA,uBAAW,EAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,IAAA,8BAAW,EAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QAC9D,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,IAAA,cAAM,EACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;AAvFD,4CAuFC;;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { installSnap } from '@metamask/snaps-simulation';\nimport type {\n InstalledSnap,\n InstallSnapOptions,\n SnapHelpers,\n} from '@metamask/snaps-simulation';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: (InstalledSnap & SnapHelpers) | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await installSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
|
package/dist/environment.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
2
2
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
3
|
-
import type { InstalledSnap, InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
3
|
+
import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
|
|
4
4
|
import NodeEnvironment from "jest-environment-node";
|
|
5
5
|
declare global {
|
|
6
6
|
const snapsEnvironment: SnapsEnvironment;
|
|
@@ -38,7 +38,7 @@ export declare class SnapsEnvironment extends NodeEnvironment {
|
|
|
38
38
|
* @template Service - The type of the execution service.
|
|
39
39
|
* @returns The installed Snap.
|
|
40
40
|
*/
|
|
41
|
-
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap>;
|
|
41
|
+
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap & SnapHelpers>;
|
|
42
42
|
/**
|
|
43
43
|
* Get the snap ID for the current environment, which is used if no snap ID is
|
|
44
44
|
* passed to {@link installSnap}. This assumes that the built-in server is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.cts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"environment.d.cts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAG5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAQpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/environment.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
2
2
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
3
|
-
import type { InstalledSnap, InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
3
|
+
import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
|
|
4
4
|
import NodeEnvironment from "jest-environment-node";
|
|
5
5
|
declare global {
|
|
6
6
|
const snapsEnvironment: SnapsEnvironment;
|
|
@@ -38,7 +38,7 @@ export declare class SnapsEnvironment extends NodeEnvironment {
|
|
|
38
38
|
* @template Service - The type of the execution service.
|
|
39
39
|
* @returns The installed Snap.
|
|
40
40
|
*/
|
|
41
|
-
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap>;
|
|
41
|
+
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap & SnapHelpers>;
|
|
42
42
|
/**
|
|
43
43
|
* Get the snap ID for the current environment, which is used if no snap ID is
|
|
44
44
|
* passed to {@link installSnap}. This assumes that the built-in server is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.mts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"environment.d.mts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAG5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAQpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/environment.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.mjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"environment.mjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAMzD,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,wBAAwB;AAE7D,OAAO,gBAAe,8BAA8B;;AAGpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,8BAAoB;AAEtD,OAAO,EAAE,UAAU,EAAE,sBAAkB;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqD;QAUnD,uBAAA,IAAI,6BAAY,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,WAAW,CAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,WAAW,CAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QAC9D,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,MAAM,CACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;;AAED,eAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { installSnap } from '@metamask/snaps-simulation';\nimport type {\n InstalledSnap,\n InstallSnapOptions,\n SnapHelpers,\n} from '@metamask/snaps-simulation';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: (InstalledSnap & SnapHelpers) | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await installSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.installSnap = void 0;
|
|
4
|
-
const snaps_simulation_1 = require("@metamask/snaps-simulation");
|
|
5
4
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
7
5
|
const utils_1 = require("@metamask/utils");
|
|
8
6
|
const internals_1 = require("./internals/index.cjs");
|
|
9
7
|
const log = (0, utils_1.createModuleLogger)(internals_1.rootLogger, 'helpers');
|
|
@@ -20,14 +18,6 @@ function getOptions(snapId, options) {
|
|
|
20
18
|
}
|
|
21
19
|
return [snapId, options];
|
|
22
20
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Ensure that the actual response contains `getInterface`.
|
|
25
|
-
*
|
|
26
|
-
* @param response - The response of the handler.
|
|
27
|
-
*/
|
|
28
|
-
function assertIsResponseWithInterface(response) {
|
|
29
|
-
(0, utils_1.assertStruct)(response, snaps_simulation_1.SnapResponseWithInterfaceStruct);
|
|
30
|
-
}
|
|
31
21
|
/**
|
|
32
22
|
* Load a snap into the environment. This is the main entry point for testing
|
|
33
23
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
|
@@ -62,110 +52,21 @@ function assertIsResponseWithInterface(response) {
|
|
|
62
52
|
*/
|
|
63
53
|
async function installSnap(snapId, options = {}) {
|
|
64
54
|
const resolvedOptions = getOptions(snapId, options);
|
|
65
|
-
const {
|
|
66
|
-
const onTransaction = async (request) => {
|
|
67
|
-
log('Sending transaction %o.', request);
|
|
68
|
-
const { origin: transactionOrigin, chainId, ...transaction } = (0, superstruct_1.create)(request, snaps_simulation_1.TransactionOptionsStruct);
|
|
69
|
-
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
70
|
-
snapId: installedSnapId,
|
|
71
|
-
store,
|
|
72
|
-
executionService,
|
|
73
|
-
runSaga,
|
|
74
|
-
controllerMessenger,
|
|
75
|
-
handler: snaps_utils_1.HandlerType.OnTransaction,
|
|
76
|
-
request: {
|
|
77
|
-
method: '',
|
|
78
|
-
params: {
|
|
79
|
-
chainId,
|
|
80
|
-
transaction,
|
|
81
|
-
transactionOrigin,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
assertIsResponseWithInterface(response);
|
|
86
|
-
return response;
|
|
87
|
-
};
|
|
88
|
-
const onCronjob = (request) => {
|
|
89
|
-
log('Running cronjob %o.', options);
|
|
90
|
-
return (0, snaps_simulation_1.handleRequest)({
|
|
91
|
-
snapId: installedSnapId,
|
|
92
|
-
store,
|
|
93
|
-
executionService,
|
|
94
|
-
controllerMessenger,
|
|
95
|
-
runSaga,
|
|
96
|
-
handler: snaps_utils_1.HandlerType.OnCronjob,
|
|
97
|
-
request,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
55
|
+
const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onHomePage, onKeyringRequest, mockJsonRpc, close, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
|
|
100
56
|
return {
|
|
101
|
-
request
|
|
102
|
-
log('Sending request %o.', request);
|
|
103
|
-
return (0, snaps_simulation_1.handleRequest)({
|
|
104
|
-
snapId: installedSnapId,
|
|
105
|
-
store,
|
|
106
|
-
executionService,
|
|
107
|
-
controllerMessenger,
|
|
108
|
-
runSaga,
|
|
109
|
-
handler: snaps_utils_1.HandlerType.OnRpcRequest,
|
|
110
|
-
request,
|
|
111
|
-
});
|
|
112
|
-
},
|
|
57
|
+
request,
|
|
113
58
|
onTransaction,
|
|
114
|
-
sendTransaction
|
|
115
|
-
onSignature
|
|
116
|
-
log('Requesting signature %o.', request);
|
|
117
|
-
const { origin: signatureOrigin, ...signature } = (0, superstruct_1.create)(request, snaps_simulation_1.SignatureOptionsStruct);
|
|
118
|
-
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
119
|
-
snapId: installedSnapId,
|
|
120
|
-
store,
|
|
121
|
-
executionService,
|
|
122
|
-
controllerMessenger,
|
|
123
|
-
runSaga,
|
|
124
|
-
handler: snaps_utils_1.HandlerType.OnSignature,
|
|
125
|
-
request: {
|
|
126
|
-
method: '',
|
|
127
|
-
params: {
|
|
128
|
-
signature,
|
|
129
|
-
signatureOrigin,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
assertIsResponseWithInterface(response);
|
|
134
|
-
return response;
|
|
135
|
-
},
|
|
59
|
+
sendTransaction,
|
|
60
|
+
onSignature,
|
|
136
61
|
onCronjob,
|
|
137
|
-
runCronjob
|
|
138
|
-
onHomePage
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
snapId: installedSnapId,
|
|
142
|
-
store,
|
|
143
|
-
executionService,
|
|
144
|
-
controllerMessenger,
|
|
145
|
-
runSaga,
|
|
146
|
-
handler: snaps_utils_1.HandlerType.OnHomePage,
|
|
147
|
-
request: {
|
|
148
|
-
method: '',
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
assertIsResponseWithInterface(response);
|
|
152
|
-
return response;
|
|
153
|
-
},
|
|
154
|
-
mockJsonRpc(mock) {
|
|
155
|
-
log('Mocking JSON-RPC request %o.', mock);
|
|
156
|
-
const { method, result } = (0, superstruct_1.create)(mock, snaps_simulation_1.JsonRpcMockOptionsStruct);
|
|
157
|
-
store.dispatch((0, snaps_simulation_1.addJsonRpcMock)({ method, result }));
|
|
158
|
-
return {
|
|
159
|
-
unmock() {
|
|
160
|
-
log('Unmocking JSON-RPC request %o.', mock);
|
|
161
|
-
store.dispatch((0, snaps_simulation_1.removeJsonRpcMock)(method));
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
},
|
|
62
|
+
runCronjob,
|
|
63
|
+
onHomePage,
|
|
64
|
+
onKeyringRequest,
|
|
65
|
+
mockJsonRpc,
|
|
165
66
|
close: async () => {
|
|
166
67
|
log('Closing execution service.');
|
|
167
68
|
(0, snaps_utils_1.logInfo)('Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.');
|
|
168
|
-
await
|
|
69
|
+
await close();
|
|
169
70
|
},
|
|
170
71
|
};
|
|
171
72
|
}
|
package/dist/helpers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"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","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { InstallSnapOptions } from '@metamask/snaps-simulation';\nimport {\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n handleRequest,\n TransactionOptionsStruct,\n addJsonRpcMock,\n removeJsonRpcMock,\n SnapResponseWithInterfaceStruct,\n} from '@metamask/snaps-simulation';\nimport { HandlerType, logInfo } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport { assertStruct, createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger, getEnvironment } from './internals';\nimport type {\n SnapResponseWithInterface,\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nfunction assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n return {\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAGA,uDAAgD;AAChD,2CAAqD;AAErD,qDAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,GACN,GAAG,MAAM,IAAA,0BAAc,GAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAE3D,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,UAAU;QACV,gBAAgB;QAChB,WAAW;QACX,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,IAAA,qBAAO,EACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC;AAzCD,kCAyCC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { InstallSnapOptions, Snap } from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger, getEnvironment } from './internals';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onHomePage,\n onKeyringRequest,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onHomePage,\n onKeyringRequest,\n mockJsonRpc,\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await close();\n },\n };\n}\n"]}
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
4
|
-
import type { Snap } from "./types/index.cjs";
|
|
3
|
+
import type { InstallSnapOptions, Snap } from "@metamask/snaps-simulation";
|
|
5
4
|
/**
|
|
6
5
|
* Load a snap into the environment. This is the main entry point for testing
|
|
7
6
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
package/dist/helpers.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,mCAAmC;AA8B3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EACD,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC"}
|