@metamask/snaps-jest 8.3.2 → 8.4.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 +11 -1
- package/dist/environment.cjs +2 -1
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.cts +1 -1
- package/dist/environment.d.cts.map +1 -1
- package/dist/environment.d.mts +1 -1
- package/dist/environment.d.mts.map +1 -1
- package/dist/environment.mjs +3 -2
- package/dist/environment.mjs.map +1 -1
- package/dist/helpers.cjs +13 -80
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +2 -44
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +2 -44
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +4 -64
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/internals/index.cjs +0 -3
- package/dist/internals/index.cjs.map +1 -1
- package/dist/internals/index.d.cts +0 -3
- package/dist/internals/index.d.cts.map +1 -1
- package/dist/internals/index.d.mts +0 -3
- package/dist/internals/index.d.mts.map +1 -1
- package/dist/internals/index.mjs +0 -3
- package/dist/internals/index.mjs.map +1 -1
- package/dist/matchers.cjs +3 -3
- 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 +1 -1
- package/dist/matchers.mjs.map +1 -1
- package/dist/types/types.cjs.map +1 -1
- package/dist/types/types.d.cts +8 -1
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.mts +8 -1
- package/dist/types/types.d.mts.map +1 -1
- package/dist/types/types.mjs.map +1 -1
- package/package.json +4 -17
- package/dist/internals/request.cjs +0 -143
- package/dist/internals/request.cjs.map +0 -1
- package/dist/internals/request.d.cts +0 -56
- package/dist/internals/request.d.cts.map +0 -1
- package/dist/internals/request.d.mts +0 -56
- package/dist/internals/request.d.mts.map +0 -1
- package/dist/internals/request.mjs +0 -138
- package/dist/internals/request.mjs.map +0 -1
- package/dist/internals/simulation/constants.cjs +0 -21
- package/dist/internals/simulation/constants.cjs.map +0 -1
- package/dist/internals/simulation/constants.d.cts +0 -18
- package/dist/internals/simulation/constants.d.cts.map +0 -1
- package/dist/internals/simulation/constants.d.mts +0 -18
- package/dist/internals/simulation/constants.d.mts.map +0 -1
- package/dist/internals/simulation/constants.mjs +0 -18
- package/dist/internals/simulation/constants.mjs.map +0 -1
- package/dist/internals/simulation/controllers.cjs +0 -101
- package/dist/internals/simulation/controllers.cjs.map +0 -1
- package/dist/internals/simulation/controllers.d.cts +0 -41
- package/dist/internals/simulation/controllers.d.cts.map +0 -1
- package/dist/internals/simulation/controllers.d.mts +0 -41
- package/dist/internals/simulation/controllers.d.mts.map +0 -1
- package/dist/internals/simulation/controllers.mjs +0 -96
- package/dist/internals/simulation/controllers.mjs.map +0 -1
- package/dist/internals/simulation/files.cjs +0 -94
- package/dist/internals/simulation/files.cjs.map +0 -1
- package/dist/internals/simulation/files.d.cts +0 -49
- package/dist/internals/simulation/files.d.cts.map +0 -1
- package/dist/internals/simulation/files.d.mts +0 -49
- package/dist/internals/simulation/files.d.mts.map +0 -1
- package/dist/internals/simulation/files.mjs +0 -91
- package/dist/internals/simulation/files.mjs.map +0 -1
- package/dist/internals/simulation/index.cjs +0 -22
- package/dist/internals/simulation/index.cjs.map +0 -1
- package/dist/internals/simulation/index.d.cts +0 -6
- package/dist/internals/simulation/index.d.cts.map +0 -1
- package/dist/internals/simulation/index.d.mts +0 -6
- package/dist/internals/simulation/index.d.mts.map +0 -1
- package/dist/internals/simulation/index.mjs +0 -6
- package/dist/internals/simulation/index.mjs.map +0 -1
- package/dist/internals/simulation/interface.cjs +0 -527
- package/dist/internals/simulation/interface.cjs.map +0 -1
- package/dist/internals/simulation/interface.d.cts +0 -152
- package/dist/internals/simulation/interface.d.cts.map +0 -1
- package/dist/internals/simulation/interface.d.mts +0 -152
- package/dist/internals/simulation/interface.d.mts.map +0 -1
- package/dist/internals/simulation/interface.mjs +0 -513
- package/dist/internals/simulation/interface.mjs.map +0 -1
- package/dist/internals/simulation/methods/constants.cjs +0 -72
- package/dist/internals/simulation/methods/constants.cjs.map +0 -1
- package/dist/internals/simulation/methods/constants.d.cts +0 -11
- package/dist/internals/simulation/methods/constants.d.cts.map +0 -1
- package/dist/internals/simulation/methods/constants.d.mts +0 -11
- package/dist/internals/simulation/methods/constants.d.mts.map +0 -1
- package/dist/internals/simulation/methods/constants.mjs +0 -69
- package/dist/internals/simulation/methods/constants.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs +0 -18
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.cjs +0 -22
- package/dist/internals/simulation/methods/hooks/index.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.d.cts +0 -6
- package/dist/internals/simulation/methods/hooks/index.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.d.mts +0 -6
- package/dist/internals/simulation/methods/hooks/index.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.mjs +0 -6
- package/dist/internals/simulation/methods/hooks/index.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.cjs +0 -24
- package/dist/internals/simulation/methods/hooks/interface.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.d.cts +0 -17
- package/dist/internals/simulation/methods/hooks/interface.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.d.mts +0 -17
- package/dist/internals/simulation/methods/hooks/interface.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.mjs +0 -19
- package/dist/internals/simulation/methods/hooks/interface.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.cjs +0 -58
- package/dist/internals/simulation/methods/hooks/notifications.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.d.cts +0 -17
- package/dist/internals/simulation/methods/hooks/notifications.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.d.mts +0 -17
- package/dist/internals/simulation/methods/hooks/notifications.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.mjs +0 -55
- package/dist/internals/simulation/methods/hooks/notifications.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs +0 -38
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts +0 -16
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts +0 -16
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +0 -35
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.cjs +0 -84
- package/dist/internals/simulation/methods/hooks/state.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.d.cts +0 -24
- package/dist/internals/simulation/methods/hooks/state.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.d.mts +0 -24
- package/dist/internals/simulation/methods/hooks/state.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.mjs +0 -79
- package/dist/internals/simulation/methods/hooks/state.mjs.map +0 -1
- package/dist/internals/simulation/methods/index.cjs +0 -18
- package/dist/internals/simulation/methods/index.cjs.map +0 -1
- package/dist/internals/simulation/methods/index.d.cts +0 -2
- package/dist/internals/simulation/methods/index.d.cts.map +0 -1
- package/dist/internals/simulation/methods/index.d.mts +0 -2
- package/dist/internals/simulation/methods/index.d.mts.map +0 -1
- package/dist/internals/simulation/methods/index.mjs +0 -2
- package/dist/internals/simulation/methods/index.mjs.map +0 -1
- package/dist/internals/simulation/methods/specifications.cjs +0 -85
- package/dist/internals/simulation/methods/specifications.cjs.map +0 -1
- package/dist/internals/simulation/methods/specifications.d.cts +0 -57
- package/dist/internals/simulation/methods/specifications.d.cts.map +0 -1
- package/dist/internals/simulation/methods/specifications.d.mts +0 -57
- package/dist/internals/simulation/methods/specifications.d.mts.map +0 -1
- package/dist/internals/simulation/methods/specifications.mjs +0 -78
- package/dist/internals/simulation/methods/specifications.mjs.map +0 -1
- package/dist/internals/simulation/middleware/engine.cjs +0 -37
- package/dist/internals/simulation/middleware/engine.cjs.map +0 -1
- package/dist/internals/simulation/middleware/engine.d.cts +0 -27
- package/dist/internals/simulation/middleware/engine.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/engine.d.mts +0 -27
- package/dist/internals/simulation/middleware/engine.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/engine.mjs +0 -34
- package/dist/internals/simulation/middleware/engine.mjs.map +0 -1
- package/dist/internals/simulation/middleware/index.cjs +0 -18
- package/dist/internals/simulation/middleware/index.cjs.map +0 -1
- package/dist/internals/simulation/middleware/index.d.cts +0 -2
- package/dist/internals/simulation/middleware/index.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/index.d.mts +0 -2
- package/dist/internals/simulation/middleware/index.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/index.mjs +0 -2
- package/dist/internals/simulation/middleware/index.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs +0 -34
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts +0 -20
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts +0 -20
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +0 -30
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.cjs +0 -18
- package/dist/internals/simulation/middleware/internal-methods/index.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.mjs +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs +0 -44
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts +0 -23
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts +0 -23
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +0 -40
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs +0 -28
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts +0 -16
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts +0 -16
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +0 -24
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +0 -1
- package/dist/internals/simulation/middleware/mock.cjs +0 -22
- package/dist/internals/simulation/middleware/mock.cjs.map +0 -1
- package/dist/internals/simulation/middleware/mock.d.cts +0 -11
- package/dist/internals/simulation/middleware/mock.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/mock.d.mts +0 -11
- package/dist/internals/simulation/middleware/mock.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/mock.mjs +0 -18
- package/dist/internals/simulation/middleware/mock.mjs.map +0 -1
- package/dist/internals/simulation/options.cjs +0 -25
- package/dist/internals/simulation/options.cjs.map +0 -1
- package/dist/internals/simulation/options.d.cts +0 -40
- package/dist/internals/simulation/options.d.cts.map +0 -1
- package/dist/internals/simulation/options.d.mts +0 -40
- package/dist/internals/simulation/options.d.mts.map +0 -1
- package/dist/internals/simulation/options.mjs +0 -21
- package/dist/internals/simulation/options.mjs.map +0 -1
- package/dist/internals/simulation/simulation.cjs +0 -155
- package/dist/internals/simulation/simulation.cjs.map +0 -1
- package/dist/internals/simulation/simulation.d.cts +0 -103
- package/dist/internals/simulation/simulation.d.cts.map +0 -1
- package/dist/internals/simulation/simulation.d.mts +0 -103
- package/dist/internals/simulation/simulation.d.mts.map +0 -1
- package/dist/internals/simulation/simulation.mjs +0 -150
- package/dist/internals/simulation/simulation.mjs.map +0 -1
- package/dist/internals/simulation/store/index.cjs +0 -21
- package/dist/internals/simulation/store/index.cjs.map +0 -1
- package/dist/internals/simulation/store/index.d.cts +0 -5
- package/dist/internals/simulation/store/index.d.cts.map +0 -1
- package/dist/internals/simulation/store/index.d.mts +0 -5
- package/dist/internals/simulation/store/index.d.mts.map +0 -1
- package/dist/internals/simulation/store/index.mjs +0 -5
- package/dist/internals/simulation/store/index.mjs.map +0 -1
- package/dist/internals/simulation/store/mocks.cjs +0 -39
- package/dist/internals/simulation/store/mocks.cjs.map +0 -1
- package/dist/internals/simulation/store/mocks.d.cts +0 -36
- package/dist/internals/simulation/store/mocks.d.cts.map +0 -1
- package/dist/internals/simulation/store/mocks.d.mts +0 -36
- package/dist/internals/simulation/store/mocks.d.mts.map +0 -1
- package/dist/internals/simulation/store/mocks.mjs +0 -35
- package/dist/internals/simulation/store/mocks.mjs.map +0 -1
- package/dist/internals/simulation/store/notifications.cjs +0 -35
- package/dist/internals/simulation/store/notifications.cjs.map +0 -1
- package/dist/internals/simulation/store/notifications.d.cts +0 -45
- package/dist/internals/simulation/store/notifications.d.cts.map +0 -1
- package/dist/internals/simulation/store/notifications.d.mts +0 -45
- package/dist/internals/simulation/store/notifications.d.mts.map +0 -1
- package/dist/internals/simulation/store/notifications.mjs +0 -32
- package/dist/internals/simulation/store/notifications.mjs.map +0 -1
- package/dist/internals/simulation/store/state.cjs +0 -54
- package/dist/internals/simulation/store/state.cjs.map +0 -1
- package/dist/internals/simulation/store/state.d.cts +0 -56
- package/dist/internals/simulation/store/state.d.cts.map +0 -1
- package/dist/internals/simulation/store/state.d.mts +0 -56
- package/dist/internals/simulation/store/state.d.mts.map +0 -1
- package/dist/internals/simulation/store/state.mjs +0 -50
- package/dist/internals/simulation/store/state.mjs.map +0 -1
- package/dist/internals/simulation/store/store.cjs +0 -51
- package/dist/internals/simulation/store/store.cjs.map +0 -1
- package/dist/internals/simulation/store/store.d.cts +0 -22
- package/dist/internals/simulation/store/store.d.cts.map +0 -1
- package/dist/internals/simulation/store/store.d.mts +0 -22
- package/dist/internals/simulation/store/store.d.mts.map +0 -1
- package/dist/internals/simulation/store/store.mjs +0 -45
- package/dist/internals/simulation/store/store.mjs.map +0 -1
- package/dist/internals/simulation/store/ui.cjs +0 -24
- package/dist/internals/simulation/store/ui.cjs.map +0 -1
- package/dist/internals/simulation/store/ui.d.cts +0 -27
- package/dist/internals/simulation/store/ui.d.cts.map +0 -1
- package/dist/internals/simulation/store/ui.d.mts +0 -27
- package/dist/internals/simulation/store/ui.d.mts.map +0 -1
- package/dist/internals/simulation/store/ui.mjs +0 -21
- package/dist/internals/simulation/store/ui.mjs.map +0 -1
- package/dist/internals/structs.cjs +0 -157
- package/dist/internals/structs.cjs.map +0 -1
- package/dist/internals/structs.d.cts +0 -205
- package/dist/internals/structs.d.cts.map +0 -1
- package/dist/internals/structs.d.mts +0 -205
- package/dist/internals/structs.d.mts.map +0 -1
- package/dist/internals/structs.mjs +0 -154
- package/dist/internals/structs.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [8.4.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add support for selector component ([#2724](https://github.com/MetaMask/snaps/pull/2724))
|
|
12
|
+
- Interfaces now have a `selectFromSelector` function that can be used to
|
|
13
|
+
select an option from a selector.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Extract simulation part of `snaps-jest` to separate package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
|
|
17
|
+
|
|
9
18
|
## [8.3.2]
|
|
10
19
|
### Fixed
|
|
11
20
|
- Fix invalid types in type declaration in some cases ([#2714](https://github.com/MetaMask/snaps/pull/2714))
|
|
@@ -193,7 +202,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
193
202
|
- The version of the package no longer needs to match the version of all other
|
|
194
203
|
MetaMask Snaps packages.
|
|
195
204
|
|
|
196
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.
|
|
205
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.4.0...HEAD
|
|
206
|
+
[8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.2...@metamask/snaps-jest@8.4.0
|
|
197
207
|
[8.3.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.1...@metamask/snaps-jest@8.3.2
|
|
198
208
|
[8.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.0...@metamask/snaps-jest@8.3.1
|
|
199
209
|
[8.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.2.0...@metamask/snaps-jest@8.3.0
|
package/dist/environment.cjs
CHANGED
|
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
var _SnapsEnvironment_options, _SnapsEnvironment_server, _SnapsEnvironment_instance;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SnapsEnvironment = void 0;
|
|
19
|
+
const snaps_simulation_1 = require("@metamask/snaps-simulation");
|
|
19
20
|
const utils_1 = require("@metamask/utils");
|
|
20
21
|
const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
|
|
21
22
|
const internals_1 = require("./internals/index.cjs");
|
|
@@ -73,7 +74,7 @@ class SnapsEnvironment extends jest_environment_node_1.default {
|
|
|
73
74
|
*/
|
|
74
75
|
async installSnap(snapId = this.snapId, options = {}) {
|
|
75
76
|
await __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f")?.executionService.terminateAllSnaps();
|
|
76
|
-
__classPrivateFieldSet(this, _SnapsEnvironment_instance, await (0,
|
|
77
|
+
__classPrivateFieldSet(this, _SnapsEnvironment_instance, await (0, snaps_simulation_1.installSnap)(snapId, options), "f");
|
|
77
78
|
return __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f");
|
|
78
79
|
}
|
|
79
80
|
/**
|
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":["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AgB,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 type {\n InstalledSnap,\n InstallSnapOptions,\n} from '@metamask/snaps-simulation';\nimport { installSnap } 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 | 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,7 +1,7 @@
|
|
|
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
4
|
import NodeEnvironment from "jest-environment-node";
|
|
4
|
-
import type { InstalledSnap, InstallSnapOptions } from "./internals/index.cjs";
|
|
5
5
|
declare global {
|
|
6
6
|
const snapsEnvironment: SnapsEnvironment;
|
|
7
7
|
}
|
|
@@ -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;AAE5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EACnB,mCAAmC;AAIpC,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,7 +1,7 @@
|
|
|
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
4
|
import NodeEnvironment from "jest-environment-node";
|
|
4
|
-
import type { InstalledSnap, InstallSnapOptions } from "./internals/index.mjs";
|
|
5
5
|
declare global {
|
|
6
6
|
const snapsEnvironment: SnapsEnvironment;
|
|
7
7
|
}
|
|
@@ -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;AAE5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EACnB,mCAAmC;AAIpC,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
CHANGED
|
@@ -16,10 +16,11 @@ function $importDefault(module) {
|
|
|
16
16
|
}
|
|
17
17
|
return module;
|
|
18
18
|
}
|
|
19
|
+
import { installSnap } from "@metamask/snaps-simulation";
|
|
19
20
|
import { assert, createModuleLogger } from "@metamask/utils";
|
|
20
21
|
import $NodeEnvironment from "jest-environment-node";
|
|
21
22
|
const NodeEnvironment = $importDefault($NodeEnvironment);
|
|
22
|
-
import {
|
|
23
|
+
import { rootLogger, startServer } from "./internals/index.mjs";
|
|
23
24
|
import { getOptions } from "./options.mjs";
|
|
24
25
|
/* eslint-enable */
|
|
25
26
|
const log = createModuleLogger(rootLogger, 'environment');
|
|
@@ -74,7 +75,7 @@ export class SnapsEnvironment extends NodeEnvironment {
|
|
|
74
75
|
*/
|
|
75
76
|
async installSnap(snapId = this.snapId, options = {}) {
|
|
76
77
|
await __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f")?.executionService.terminateAllSnaps();
|
|
77
|
-
__classPrivateFieldSet(this, _SnapsEnvironment_instance, await
|
|
78
|
+
__classPrivateFieldSet(this, _SnapsEnvironment_instance, await installSnap(snapId, options), "f");
|
|
78
79
|
return __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f");
|
|
79
80
|
}
|
|
80
81
|
/**
|
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":";;;;;;;;;;;;;;;;;;AAUA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AACzD,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;AAE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B,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 type {\n InstalledSnap,\n InstallSnapOptions,\n} from '@metamask/snaps-simulation';\nimport { installSnap } 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 | 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,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installSnap =
|
|
4
|
-
const
|
|
3
|
+
exports.installSnap = void 0;
|
|
4
|
+
const snaps_simulation_1 = require("@metamask/snaps-simulation");
|
|
5
5
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
6
|
const superstruct_1 = require("@metamask/superstruct");
|
|
7
7
|
const utils_1 = require("@metamask/utils");
|
|
8
8
|
const internals_1 = require("./internals/index.cjs");
|
|
9
|
-
const mocks_1 = require("./internals/simulation/store/mocks.cjs");
|
|
10
9
|
const log = (0, utils_1.createModuleLogger)(internals_1.rootLogger, 'helpers');
|
|
11
10
|
/**
|
|
12
11
|
* Get the options for {@link installSnap}.
|
|
@@ -27,74 +26,8 @@ function getOptions(snapId, options) {
|
|
|
27
26
|
* @param response - The response of the handler.
|
|
28
27
|
*/
|
|
29
28
|
function assertIsResponseWithInterface(response) {
|
|
30
|
-
(0, utils_1.assertStruct)(response,
|
|
29
|
+
(0, utils_1.assertStruct)(response, snaps_simulation_1.SnapResponseWithInterfaceStruct);
|
|
31
30
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Ensure that the actual interface is an alert dialog.
|
|
34
|
-
*
|
|
35
|
-
* @param ui - The interface to verify.
|
|
36
|
-
*/
|
|
37
|
-
function assertIsAlertDialog(ui) {
|
|
38
|
-
(0, utils_1.assert)((0, utils_1.hasProperty)(ui, 'type') && ui.type === snaps_sdk_1.DialogType.Alert);
|
|
39
|
-
}
|
|
40
|
-
exports.assertIsAlertDialog = assertIsAlertDialog;
|
|
41
|
-
/**
|
|
42
|
-
* Ensure that the actual interface is a confirmation dialog.
|
|
43
|
-
*
|
|
44
|
-
* @param ui - The interface to verify.
|
|
45
|
-
*/
|
|
46
|
-
function assertIsConfirmationDialog(ui) {
|
|
47
|
-
(0, utils_1.assert)((0, utils_1.hasProperty)(ui, 'type') && ui.type === snaps_sdk_1.DialogType.Confirmation);
|
|
48
|
-
}
|
|
49
|
-
exports.assertIsConfirmationDialog = assertIsConfirmationDialog;
|
|
50
|
-
/**
|
|
51
|
-
* Ensure that the actual interface is a Prompt dialog.
|
|
52
|
-
*
|
|
53
|
-
* @param ui - The interface to verify.
|
|
54
|
-
*/
|
|
55
|
-
function assertIsPromptDialog(ui) {
|
|
56
|
-
(0, utils_1.assert)((0, utils_1.hasProperty)(ui, 'type') && ui.type === snaps_sdk_1.DialogType.Prompt);
|
|
57
|
-
}
|
|
58
|
-
exports.assertIsPromptDialog = assertIsPromptDialog;
|
|
59
|
-
/**
|
|
60
|
-
* Ensure that the actual interface is a custom dialog.
|
|
61
|
-
*
|
|
62
|
-
* @param ui - The interface to verify.
|
|
63
|
-
*/
|
|
64
|
-
function assertIsCustomDialog(ui) {
|
|
65
|
-
(0, utils_1.assert)(!(0, utils_1.hasProperty)(ui, 'type'));
|
|
66
|
-
}
|
|
67
|
-
exports.assertIsCustomDialog = assertIsCustomDialog;
|
|
68
|
-
/**
|
|
69
|
-
* Ensure that the actual interface is a custom dialog with a complete footer.
|
|
70
|
-
*
|
|
71
|
-
* @param ui - The interface to verify.
|
|
72
|
-
*/
|
|
73
|
-
function assertCustomDialogHasFooter(ui) {
|
|
74
|
-
const footer = (0, internals_1.getElementByType)(ui.content, 'Footer');
|
|
75
|
-
(0, utils_1.assert)(footer && (0, snaps_utils_1.getJsxChildren)(footer).length === 2);
|
|
76
|
-
}
|
|
77
|
-
exports.assertCustomDialogHasFooter = assertCustomDialogHasFooter;
|
|
78
|
-
/**
|
|
79
|
-
* Ensure that the actual interface is a custom dialog with a partial footer.
|
|
80
|
-
*
|
|
81
|
-
* @param ui - The interface to verify.
|
|
82
|
-
*/
|
|
83
|
-
function assertCustomDialogHasPartialFooter(ui) {
|
|
84
|
-
const footer = (0, internals_1.getElementByType)(ui.content, 'Footer');
|
|
85
|
-
(0, utils_1.assert)(footer && (0, snaps_utils_1.getJsxChildren)(footer).length === 1);
|
|
86
|
-
}
|
|
87
|
-
exports.assertCustomDialogHasPartialFooter = assertCustomDialogHasPartialFooter;
|
|
88
|
-
/**
|
|
89
|
-
* Ensure that the actual interface is a custom dialog without a footer.
|
|
90
|
-
*
|
|
91
|
-
* @param ui - The interface to verify.
|
|
92
|
-
*/
|
|
93
|
-
function assertCustomDialogHasNoFooter(ui) {
|
|
94
|
-
const footer = (0, internals_1.getElementByType)(ui.content, 'Footer');
|
|
95
|
-
(0, utils_1.assert)(!footer);
|
|
96
|
-
}
|
|
97
|
-
exports.assertCustomDialogHasNoFooter = assertCustomDialogHasNoFooter;
|
|
98
31
|
/**
|
|
99
32
|
* Load a snap into the environment. This is the main entry point for testing
|
|
100
33
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
|
@@ -132,8 +65,8 @@ async function installSnap(snapId, options = {}) {
|
|
|
132
65
|
const { snapId: installedSnapId, store, executionService, runSaga, controllerMessenger, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
|
|
133
66
|
const onTransaction = async (request) => {
|
|
134
67
|
log('Sending transaction %o.', request);
|
|
135
|
-
const { origin: transactionOrigin, chainId, ...transaction } = (0, superstruct_1.create)(request,
|
|
136
|
-
const response = await (0,
|
|
68
|
+
const { origin: transactionOrigin, chainId, ...transaction } = (0, superstruct_1.create)(request, snaps_simulation_1.TransactionOptionsStruct);
|
|
69
|
+
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
137
70
|
snapId: installedSnapId,
|
|
138
71
|
store,
|
|
139
72
|
executionService,
|
|
@@ -154,7 +87,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
154
87
|
};
|
|
155
88
|
const onCronjob = (request) => {
|
|
156
89
|
log('Running cronjob %o.', options);
|
|
157
|
-
return (0,
|
|
90
|
+
return (0, snaps_simulation_1.handleRequest)({
|
|
158
91
|
snapId: installedSnapId,
|
|
159
92
|
store,
|
|
160
93
|
executionService,
|
|
@@ -167,7 +100,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
167
100
|
return {
|
|
168
101
|
request: (request) => {
|
|
169
102
|
log('Sending request %o.', request);
|
|
170
|
-
return (0,
|
|
103
|
+
return (0, snaps_simulation_1.handleRequest)({
|
|
171
104
|
snapId: installedSnapId,
|
|
172
105
|
store,
|
|
173
106
|
executionService,
|
|
@@ -181,8 +114,8 @@ async function installSnap(snapId, options = {}) {
|
|
|
181
114
|
sendTransaction: onTransaction,
|
|
182
115
|
onSignature: async (request) => {
|
|
183
116
|
log('Requesting signature %o.', request);
|
|
184
|
-
const { origin: signatureOrigin, ...signature } = (0, superstruct_1.create)(request,
|
|
185
|
-
const response = await (0,
|
|
117
|
+
const { origin: signatureOrigin, ...signature } = (0, superstruct_1.create)(request, snaps_simulation_1.SignatureOptionsStruct);
|
|
118
|
+
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
186
119
|
snapId: installedSnapId,
|
|
187
120
|
store,
|
|
188
121
|
executionService,
|
|
@@ -204,7 +137,7 @@ async function installSnap(snapId, options = {}) {
|
|
|
204
137
|
runCronjob: onCronjob,
|
|
205
138
|
onHomePage: async () => {
|
|
206
139
|
log('Rendering home page.');
|
|
207
|
-
const response = await (0,
|
|
140
|
+
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
208
141
|
snapId: installedSnapId,
|
|
209
142
|
store,
|
|
210
143
|
executionService,
|
|
@@ -220,12 +153,12 @@ async function installSnap(snapId, options = {}) {
|
|
|
220
153
|
},
|
|
221
154
|
mockJsonRpc(mock) {
|
|
222
155
|
log('Mocking JSON-RPC request %o.', mock);
|
|
223
|
-
const { method, result } = (0, superstruct_1.create)(mock,
|
|
224
|
-
store.dispatch((0,
|
|
156
|
+
const { method, result } = (0, superstruct_1.create)(mock, snaps_simulation_1.JsonRpcMockOptionsStruct);
|
|
157
|
+
store.dispatch((0, snaps_simulation_1.addJsonRpcMock)({ method, result }));
|
|
225
158
|
return {
|
|
226
159
|
unmock() {
|
|
227
160
|
log('Unmocking JSON-RPC request %o.', mock);
|
|
228
|
-
store.dispatch((0,
|
|
161
|
+
store.dispatch((0, snaps_simulation_1.removeJsonRpcMock)(method));
|
|
229
162
|
},
|
|
230
163
|
};
|
|
231
164
|
},
|
package/dist/helpers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAEA,mDAAiD;AAEjD,uDAA6E;AAC7E,uDAA+C;AAC/C,2CAKyB;AAEzB,qDASqB;AAErB,kEAG4C;AAmB5C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;I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,IAAA,qBAAO,EACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC;AAhKD,kCAgKC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DialogType } from '@metamask/snaps-sdk';\nimport type { FooterElement } from '@metamask/snaps-sdk/jsx';\nimport { HandlerType, getJsxChildren, logInfo } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport {\n assert,\n assertStruct,\n createModuleLogger,\n hasProperty,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n handleRequest,\n TransactionOptionsStruct,\n getEnvironment,\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n SnapResponseWithInterfaceStruct,\n getElementByType,\n} from './internals';\nimport type { InstallSnapOptions } from './internals';\nimport {\n addJsonRpcMock,\n removeJsonRpcMock,\n} from './internals/simulation/store/mocks';\nimport type {\n SnapResponseWithInterface,\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n SnapInterface,\n SnapAlertInterface,\n SnapInterfaceActions,\n SnapConfirmationInterface,\n SnapPromptInterface,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\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 * Ensure that the actual interface is an alert dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsAlertDialog(\n ui: SnapInterface,\n): asserts ui is SnapAlertInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Alert);\n}\n\n/**\n * Ensure that the actual interface is a confirmation dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsConfirmationDialog(\n ui: SnapInterface,\n): asserts ui is SnapConfirmationInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Confirmation);\n}\n\n/**\n * Ensure that the actual interface is a Prompt dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsPromptDialog(\n ui: SnapInterface,\n): asserts ui is SnapPromptInterface & SnapInterfaceActions {\n assert(hasProperty(ui, 'type') && ui.type === DialogType.Prompt);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog.\n *\n * @param ui - The interface to verify.\n */\nexport function assertIsCustomDialog(\n ui: SnapInterface,\n): asserts ui is DefaultSnapInterface & SnapInterfaceActions {\n assert(!hasProperty(ui, 'type'));\n}\n\n/**\n * Ensure that the actual interface is a custom dialog with a complete footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(footer && getJsxChildren(footer).length === 2);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog with a partial footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasPartialFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithPartialFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(footer && getJsxChildren(footer).length === 1);\n}\n\n/**\n * Ensure that the actual interface is a custom dialog without a footer.\n *\n * @param ui - The interface to verify.\n */\nexport function assertCustomDialogHasNoFooter(\n ui: DefaultSnapInterface & SnapInterfaceActions,\n): asserts ui is DefaultSnapInterfaceWithoutFooter & SnapInterfaceActions {\n const footer = getElementByType<FooterElement>(ui.content, 'Footer');\n\n assert(!footer);\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,iEAQoC;AACpC,uDAA6D;AAC7D,uDAA+C;AAC/C,2CAAmE;AAEnE,qDAAyD;AAUzD,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;AAED;;;;GAIG;AACH,SAAS,6BAA6B,CACpC,QAAsB;IAEtB,IAAA,oBAAY,EAAC,QAAQ,EAAE,kDAA+B,CAAC,CAAC;AAC1D,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE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,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,oBAAM,EAAC,IAAI,EAAE,2CAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,IAAA,iCAAc,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,IAAA,oCAAiB,EAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,IAAA,qBAAO,EACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC;AAhKD,kCAgKC","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"]}
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,49 +1,7 @@
|
|
|
1
1
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { InstallSnapOptions } from "
|
|
4
|
-
import type { Snap
|
|
5
|
-
/**
|
|
6
|
-
* Ensure that the actual interface is an alert dialog.
|
|
7
|
-
*
|
|
8
|
-
* @param ui - The interface to verify.
|
|
9
|
-
*/
|
|
10
|
-
export declare function assertIsAlertDialog(ui: SnapInterface): asserts ui is SnapAlertInterface & SnapInterfaceActions;
|
|
11
|
-
/**
|
|
12
|
-
* Ensure that the actual interface is a confirmation dialog.
|
|
13
|
-
*
|
|
14
|
-
* @param ui - The interface to verify.
|
|
15
|
-
*/
|
|
16
|
-
export declare function assertIsConfirmationDialog(ui: SnapInterface): asserts ui is SnapConfirmationInterface & SnapInterfaceActions;
|
|
17
|
-
/**
|
|
18
|
-
* Ensure that the actual interface is a Prompt dialog.
|
|
19
|
-
*
|
|
20
|
-
* @param ui - The interface to verify.
|
|
21
|
-
*/
|
|
22
|
-
export declare function assertIsPromptDialog(ui: SnapInterface): asserts ui is SnapPromptInterface & SnapInterfaceActions;
|
|
23
|
-
/**
|
|
24
|
-
* Ensure that the actual interface is a custom dialog.
|
|
25
|
-
*
|
|
26
|
-
* @param ui - The interface to verify.
|
|
27
|
-
*/
|
|
28
|
-
export declare function assertIsCustomDialog(ui: SnapInterface): asserts ui is DefaultSnapInterface & SnapInterfaceActions;
|
|
29
|
-
/**
|
|
30
|
-
* Ensure that the actual interface is a custom dialog with a complete footer.
|
|
31
|
-
*
|
|
32
|
-
* @param ui - The interface to verify.
|
|
33
|
-
*/
|
|
34
|
-
export declare function assertCustomDialogHasFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithFooter & SnapInterfaceActions;
|
|
35
|
-
/**
|
|
36
|
-
* Ensure that the actual interface is a custom dialog with a partial footer.
|
|
37
|
-
*
|
|
38
|
-
* @param ui - The interface to verify.
|
|
39
|
-
*/
|
|
40
|
-
export declare function assertCustomDialogHasPartialFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithPartialFooter & SnapInterfaceActions;
|
|
41
|
-
/**
|
|
42
|
-
* Ensure that the actual interface is a custom dialog without a footer.
|
|
43
|
-
*
|
|
44
|
-
* @param ui - The interface to verify.
|
|
45
|
-
*/
|
|
46
|
-
export declare function assertCustomDialogHasNoFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithoutFooter & SnapInterfaceActions;
|
|
3
|
+
import type { InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
4
|
+
import type { Snap } from "./types/index.cjs";
|
|
47
5
|
/**
|
|
48
6
|
* Load a snap into the environment. This is the main entry point for testing
|
|
49
7
|
* 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;
|
|
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,mCAAmC;AAerE,OAAO,KAAK,EAIV,IAAI,EAGL,0BAAgB;AAqCjB;;;;;;;;;;;;;;;;;;;;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"}
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,49 +1,7 @@
|
|
|
1
1
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { InstallSnapOptions } from "
|
|
4
|
-
import type { Snap
|
|
5
|
-
/**
|
|
6
|
-
* Ensure that the actual interface is an alert dialog.
|
|
7
|
-
*
|
|
8
|
-
* @param ui - The interface to verify.
|
|
9
|
-
*/
|
|
10
|
-
export declare function assertIsAlertDialog(ui: SnapInterface): asserts ui is SnapAlertInterface & SnapInterfaceActions;
|
|
11
|
-
/**
|
|
12
|
-
* Ensure that the actual interface is a confirmation dialog.
|
|
13
|
-
*
|
|
14
|
-
* @param ui - The interface to verify.
|
|
15
|
-
*/
|
|
16
|
-
export declare function assertIsConfirmationDialog(ui: SnapInterface): asserts ui is SnapConfirmationInterface & SnapInterfaceActions;
|
|
17
|
-
/**
|
|
18
|
-
* Ensure that the actual interface is a Prompt dialog.
|
|
19
|
-
*
|
|
20
|
-
* @param ui - The interface to verify.
|
|
21
|
-
*/
|
|
22
|
-
export declare function assertIsPromptDialog(ui: SnapInterface): asserts ui is SnapPromptInterface & SnapInterfaceActions;
|
|
23
|
-
/**
|
|
24
|
-
* Ensure that the actual interface is a custom dialog.
|
|
25
|
-
*
|
|
26
|
-
* @param ui - The interface to verify.
|
|
27
|
-
*/
|
|
28
|
-
export declare function assertIsCustomDialog(ui: SnapInterface): asserts ui is DefaultSnapInterface & SnapInterfaceActions;
|
|
29
|
-
/**
|
|
30
|
-
* Ensure that the actual interface is a custom dialog with a complete footer.
|
|
31
|
-
*
|
|
32
|
-
* @param ui - The interface to verify.
|
|
33
|
-
*/
|
|
34
|
-
export declare function assertCustomDialogHasFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithFooter & SnapInterfaceActions;
|
|
35
|
-
/**
|
|
36
|
-
* Ensure that the actual interface is a custom dialog with a partial footer.
|
|
37
|
-
*
|
|
38
|
-
* @param ui - The interface to verify.
|
|
39
|
-
*/
|
|
40
|
-
export declare function assertCustomDialogHasPartialFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithPartialFooter & SnapInterfaceActions;
|
|
41
|
-
/**
|
|
42
|
-
* Ensure that the actual interface is a custom dialog without a footer.
|
|
43
|
-
*
|
|
44
|
-
* @param ui - The interface to verify.
|
|
45
|
-
*/
|
|
46
|
-
export declare function assertCustomDialogHasNoFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithoutFooter & SnapInterfaceActions;
|
|
3
|
+
import type { InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
4
|
+
import type { Snap } from "./types/index.mjs";
|
|
47
5
|
/**
|
|
48
6
|
* Load a snap into the environment. This is the main entry point for testing
|
|
49
7
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
package/dist/helpers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"helpers.d.mts","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,mCAAmC;AAerE,OAAO,KAAK,EAIV,IAAI,EAGL,0BAAgB;AAqCjB;;;;;;;;;;;;;;;;;;;;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"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HandlerType,
|
|
1
|
+
import { JsonRpcMockOptionsStruct, SignatureOptionsStruct, handleRequest, TransactionOptionsStruct, addJsonRpcMock, removeJsonRpcMock, SnapResponseWithInterfaceStruct } from "@metamask/snaps-simulation";
|
|
2
|
+
import { HandlerType, logInfo } from "@metamask/snaps-utils";
|
|
3
3
|
import { create } from "@metamask/superstruct";
|
|
4
|
-
import {
|
|
5
|
-
import { rootLogger,
|
|
6
|
-
import { addJsonRpcMock, removeJsonRpcMock } from "./internals/simulation/store/mocks.mjs";
|
|
4
|
+
import { assertStruct, createModuleLogger } from "@metamask/utils";
|
|
5
|
+
import { rootLogger, getEnvironment } from "./internals/index.mjs";
|
|
7
6
|
const log = createModuleLogger(rootLogger, 'helpers');
|
|
8
7
|
/**
|
|
9
8
|
* Get the options for {@link installSnap}.
|
|
@@ -26,65 +25,6 @@ function getOptions(snapId, options) {
|
|
|
26
25
|
function assertIsResponseWithInterface(response) {
|
|
27
26
|
assertStruct(response, SnapResponseWithInterfaceStruct);
|
|
28
27
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Ensure that the actual interface is an alert dialog.
|
|
31
|
-
*
|
|
32
|
-
* @param ui - The interface to verify.
|
|
33
|
-
*/
|
|
34
|
-
export function assertIsAlertDialog(ui) {
|
|
35
|
-
assert(hasProperty(ui, 'type') && ui.type === DialogType.Alert);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Ensure that the actual interface is a confirmation dialog.
|
|
39
|
-
*
|
|
40
|
-
* @param ui - The interface to verify.
|
|
41
|
-
*/
|
|
42
|
-
export function assertIsConfirmationDialog(ui) {
|
|
43
|
-
assert(hasProperty(ui, 'type') && ui.type === DialogType.Confirmation);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Ensure that the actual interface is a Prompt dialog.
|
|
47
|
-
*
|
|
48
|
-
* @param ui - The interface to verify.
|
|
49
|
-
*/
|
|
50
|
-
export function assertIsPromptDialog(ui) {
|
|
51
|
-
assert(hasProperty(ui, 'type') && ui.type === DialogType.Prompt);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Ensure that the actual interface is a custom dialog.
|
|
55
|
-
*
|
|
56
|
-
* @param ui - The interface to verify.
|
|
57
|
-
*/
|
|
58
|
-
export function assertIsCustomDialog(ui) {
|
|
59
|
-
assert(!hasProperty(ui, 'type'));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Ensure that the actual interface is a custom dialog with a complete footer.
|
|
63
|
-
*
|
|
64
|
-
* @param ui - The interface to verify.
|
|
65
|
-
*/
|
|
66
|
-
export function assertCustomDialogHasFooter(ui) {
|
|
67
|
-
const footer = getElementByType(ui.content, 'Footer');
|
|
68
|
-
assert(footer && getJsxChildren(footer).length === 2);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Ensure that the actual interface is a custom dialog with a partial footer.
|
|
72
|
-
*
|
|
73
|
-
* @param ui - The interface to verify.
|
|
74
|
-
*/
|
|
75
|
-
export function assertCustomDialogHasPartialFooter(ui) {
|
|
76
|
-
const footer = getElementByType(ui.content, 'Footer');
|
|
77
|
-
assert(footer && getJsxChildren(footer).length === 1);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Ensure that the actual interface is a custom dialog without a footer.
|
|
81
|
-
*
|
|
82
|
-
* @param ui - The interface to verify.
|
|
83
|
-
*/
|
|
84
|
-
export function assertCustomDialogHasNoFooter(ui) {
|
|
85
|
-
const footer = getElementByType(ui.content, 'Footer');
|
|
86
|
-
assert(!footer);
|
|
87
|
-
}
|
|
88
28
|
/**
|
|
89
29
|
* Load a snap into the environment. This is the main entry point for testing
|
|
90
30
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|