@metamask/snaps-jest 10.1.0 → 10.1.2
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 +15 -1
- 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.map +1 -1
- package/dist/helpers.d.cts +3 -3
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +3 -3
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs.map +1 -1
- package/package.json +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [10.1.2]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/snaps-controllers` from `18.0.4` to `19.0.0` and handle breaking changes ([#3922](https://github.com/MetaMask/snaps/pull/3922))
|
|
15
|
+
|
|
16
|
+
## [10.1.1]
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Track whether interface has been displayed before allowing `snap_getInterfaceState` ([#3888](https://github.com/MetaMask/snaps/pull/3888))
|
|
21
|
+
|
|
10
22
|
## [10.1.0]
|
|
11
23
|
|
|
12
24
|
### Changed
|
|
@@ -478,7 +490,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
478
490
|
- The version of the package no longer needs to match the version of all other
|
|
479
491
|
MetaMask Snaps packages.
|
|
480
492
|
|
|
481
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@10.1.
|
|
493
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@10.1.2...HEAD
|
|
494
|
+
[10.1.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@10.1.1...@metamask/snaps-jest@10.1.2
|
|
495
|
+
[10.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@10.1.0...@metamask/snaps-jest@10.1.1
|
|
482
496
|
[10.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@10.0.0...@metamask/snaps-jest@10.1.0
|
|
483
497
|
[10.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.8.0...@metamask/snaps-jest@10.0.0
|
|
484
498
|
[9.8.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.7.0...@metamask/snaps-jest@9.8.0
|
package/dist/environment.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;AAMA,iEAAyD;AAMzD,2CAA6D;AAE7D,kFAAoD;AAGpD,qDAAsD;AAEtD,2CAAuC;AAMvC,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAa,gBAAiB,SAAQ,+BAAe;IAC1C,QAAQ,CAA0B;IAE3C,OAAO,CAAqB;IAE5B,SAAS,CAA4C;IAErD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAA,oBAAU,EAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,IAAA,uBAAW,EAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,IAAI,CAAC,OAAO,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,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,IAAI,CAAC,SAAS,GAAG,MAAM,IAAA,8BAAW,EAAC,MAAgB,EAAE,OAAO,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,IAAA,cAAM,EACJ,IAAI,CAAC,OAAO,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,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 {
|
|
1
|
+
{"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;AAMA,iEAAyD;AAMzD,2CAA6D;AAE7D,kFAAoD;AAGpD,qDAAsD;AAEtD,2CAAuC;AAMvC,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAA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OAOG;IACH,IAAI,MAAM;QACR,IAAA,cAAM,EACJ,IAAI,CAAC,OAAO,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,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 { ExecutionService } 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\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n readonly #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 (\n ...args: any[]\n ) => InstanceType<typeof ExecutionService>,\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,5 +1,5 @@
|
|
|
1
1
|
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExecutionService } from "@metamask/snaps-controllers";
|
|
3
3
|
import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
|
|
4
4
|
import NodeEnvironment from "jest-environment-node";
|
|
5
5
|
declare global {
|
|
@@ -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
|
|
41
|
+
installSnap<Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>>(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,
|
|
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,gBAAgB,EAAE,oCAAoC;AAGpE,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAOpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAID,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,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,gBAAgB,CAAC,EAE1C,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,5 +1,5 @@
|
|
|
1
1
|
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExecutionService } from "@metamask/snaps-controllers";
|
|
3
3
|
import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
|
|
4
4
|
import NodeEnvironment from "jest-environment-node";
|
|
5
5
|
declare global {
|
|
@@ -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
|
|
41
|
+
installSnap<Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>>(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,
|
|
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,gBAAgB,EAAE,oCAAoC;AAGpE,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAOpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAID,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EA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AAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,IAAI,CAAC,OAAO,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,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,IAAI,CAAC,SAAS,GAAG,MAAM,WAAW,CAAC,MAAgB,EAAE,OAAO,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,MAAM,CACJ,IAAI,CAAC,OAAO,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,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 {
|
|
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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AAS,GAAG,MAAM,WAAW,CAAC,MAAgB,EAAE,OAAO,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,MAAM,CACJ,IAAI,CAAC,OAAO,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,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 { ExecutionService } 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\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n readonly #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 (\n ...args: any[]\n ) => InstanceType<typeof ExecutionService>,\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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAYA,uDAAgD;AAChD,2CAA6D;AAO7D,qDAKqB;AAErB,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,CA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G,KAAK,IAAI,OAAO,EAAE,CAAoB;QAC1E,SAAS,EAAE,OAAO,CAAC,EAAE;KACtB,CAAC;AACJ,CAAC;AARD,kDAQC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,EAAiB,EACjB,MAA8C;IAE9C,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAEzB,IAAA,cAAM,EAAC,KAAK,EAAE,kBAAkB,EAAE,mCAAmC,CAAC,CAAC;IAEvE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAE/B,OAAO;QACL,KAAK,EAAE,EAAE;QACT,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC;AAfD,8CAeC;AAED;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,IAAA,wCAA4B,GAAE,CAAC;AAqE3D;;;;;;;;;;;;;;GAcG;AACH,SAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,MAAM,GAAG,EAAE,EACX,QAAQ,GAAG,KAAK,EAChB,KAAK,GAAG,KAAK,EACb,EAAE,GAAG,mBAAmB,EAAE,EAC1B,MAAM,GAAG,IAAA,+BAAmB,EAAC,MAAM,CAAC,GACd;IACtB,OAAO;QACL,OAAO;QACP,EAAE;QACF,MAAM;QACN,QAAQ;QACR,KAAK;QACL,MAAM;KACP,CAAC;AACJ,CAAC;AAhBD,wCAgBC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type {\n AccountSelectorState,\n AssetSelectorState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n InstallSnapOptions,\n SimulationAccount,\n SimulationAsset,\n Snap,\n} from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n getEnvironment,\n getPseudoRandomUuidGenerator,\n getScopesFromAssets,\n} 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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\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\n/**\n * Get the state of an AccountSelector based on a {@link SimulationAccount}.\n *\n * @param account - The {@link SimulationAccount} to get the state from.\n * @returns The state of the AccountSelector.\n */\nexport function getStateFromAccount(\n account: SimulationAccount,\n): AccountSelectorState {\n const { address, scopes } = account;\n return {\n addresses: scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[],\n accountId: account.id,\n };\n}\n\n/**\n * Get the state of an AssetSelector based on a {@link SimulationAsset}.\n *\n * @param id - The Asset id as a CAIP-19 asset type.\n * @param assets - The {@link SimulationAsset} to get the state from.\n * @returns The state of the AssetSelector.\n */\nexport function getStateFromAsset(\n id: CaipAssetType,\n assets: Record<CaipAssetType, SimulationAsset>,\n): AssetSelectorState {\n const asset = assets[id];\n\n assert(asset, `Asset with ID \"${id}\" not found in simulation assets.`);\n\n const { symbol, name } = asset;\n\n return {\n asset: id,\n symbol,\n name,\n };\n}\n\n/**\n * Generate a pseudo-random UUID.\n *\n * @returns A pseudo-random UUID string.\n */\nconst getPseudoRandomUuid = getPseudoRandomUuidGenerator();\n\n/**\n * The base options for the {@link getMockAccount} function.\n */\nexport type BaseMockAccountOptions = {\n /**\n * The address of the account.\n */\n address: string;\n\n /**\n * The ID of the account. If not provided, a pseudo-random UUID will be\n * generated.\n */\n id?: string;\n\n /**\n * Whether the account is selected by default.\n */\n selected?: boolean;\n\n /**\n * Whether the account is owned by the snap.\n */\n owned?: boolean;\n};\n\n/**\n * Options for creating a mock account with assets or scopes. If `scopes` are\n * not provided, they will be derived from the `assets`.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithAssets = BaseMockAccountOptions & {\n /**\n * The assets associated with the account. These should be in CAIP format.\n */\n assets: CaipAssetType[];\n\n /**\n * The scopes associated with the account. If not provided, they will be\n * derived from the `assets`.\n */\n scopes?: CaipChainId[];\n};\n\n/**\n * Options for creating a mock account with scopes, and optionally assets.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithScopes = BaseMockAccountOptions & {\n /**\n * The scopes associated with the account. These should be in CAIP format.\n */\n scopes: CaipChainId[];\n\n /**\n * The assets associated with the account. If not provided, it will default\n * to an empty array.\n */\n assets?: CaipAssetType[];\n};\n\nexport type GetMockAccountOptions =\n | MockAccountOptionsWithAssets\n | MockAccountOptionsWithScopes;\n\n/**\n * Get a mock account object for testing purposes.\n *\n * @param options - The options for creating the mock account.\n * @param options.address - The address of the account.\n * @param options.scopes - The scopes associated with the account, in CAIP\n * format. If not provided, they will be derived from the `assets`.\n * @param options.assets - The assets associated with the account, in CAIP\n * format. If not provided, it will default to an empty array.\n * @param options.selected - Whether the account is selected by default.\n * @param options.owned - Whether the account is owned by the snap.\n * @param options.id - The ID of the account. If not provided, a pseudo-random\n * UUID will be generated.\n * @returns A mock account object with the specified properties.\n */\nexport function getMockAccount({\n address,\n assets = [],\n selected = false,\n owned = false,\n id = getPseudoRandomUuid(),\n scopes = getScopesFromAssets(assets),\n}: GetMockAccountOptions): SimulationAccount {\n return {\n address,\n id,\n scopes,\n selected,\n owned,\n assets,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAYA,uDAAgD;AAChD,2CAA6D;AAO7D,qDAKqB;AAErB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAGjB,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;AAiGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,WAAW,CAG/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpD,wEAAwE;IACxE,WAAW;IACX,sDAAsD;IACtD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,eAAe,EACf,KAAK,GACN,GAAG,MAAM,IAAA,0BAAc,GAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CA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M,GAAG,EAAE,EACX,QAAQ,GAAG,KAAK,EAChB,KAAK,GAAG,KAAK,EACb,EAAE,GAAG,mBAAmB,EAAE,EAC1B,MAAM,GAAG,IAAA,+BAAmB,EAAC,MAAM,CAAC,GACd;IACtB,OAAO;QACL,OAAO;QACP,EAAE;QACF,MAAM;QACN,QAAQ;QACR,KAAK;QACL,MAAM;KACP,CAAC;AACJ,CAAC;AAhBD,wCAgBC","sourcesContent":["import type { ExecutionService } from '@metamask/snaps-controllers';\nimport type {\n AccountSelectorState,\n AssetSelectorState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n InstallSnapOptions,\n SimulationAccount,\n SimulationAsset,\n Snap,\n} from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n getEnvironment,\n getPseudoRandomUuidGenerator,\n getScopesFromAssets,\n} 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<typeof ExecutionService>,\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<typeof ExecutionService>,\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<typeof ExecutionService>,\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<typeof ExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\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\n/**\n * Get the state of an AccountSelector based on a {@link SimulationAccount}.\n *\n * @param account - The {@link SimulationAccount} to get the state from.\n * @returns The state of the AccountSelector.\n */\nexport function getStateFromAccount(\n account: SimulationAccount,\n): AccountSelectorState {\n const { address, scopes } = account;\n return {\n addresses: scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[],\n accountId: account.id,\n };\n}\n\n/**\n * Get the state of an AssetSelector based on a {@link SimulationAsset}.\n *\n * @param id - The Asset id as a CAIP-19 asset type.\n * @param assets - The {@link SimulationAsset} to get the state from.\n * @returns The state of the AssetSelector.\n */\nexport function getStateFromAsset(\n id: CaipAssetType,\n assets: Record<CaipAssetType, SimulationAsset>,\n): AssetSelectorState {\n const asset = assets[id];\n\n assert(asset, `Asset with ID \"${id}\" not found in simulation assets.`);\n\n const { symbol, name } = asset;\n\n return {\n asset: id,\n symbol,\n name,\n };\n}\n\n/**\n * Generate a pseudo-random UUID.\n *\n * @returns A pseudo-random UUID string.\n */\nconst getPseudoRandomUuid = getPseudoRandomUuidGenerator();\n\n/**\n * The base options for the {@link getMockAccount} function.\n */\nexport type BaseMockAccountOptions = {\n /**\n * The address of the account.\n */\n address: string;\n\n /**\n * The ID of the account. If not provided, a pseudo-random UUID will be\n * generated.\n */\n id?: string;\n\n /**\n * Whether the account is selected by default.\n */\n selected?: boolean;\n\n /**\n * Whether the account is owned by the snap.\n */\n owned?: boolean;\n};\n\n/**\n * Options for creating a mock account with assets or scopes. If `scopes` are\n * not provided, they will be derived from the `assets`.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithAssets = BaseMockAccountOptions & {\n /**\n * The assets associated with the account. These should be in CAIP format.\n */\n assets: CaipAssetType[];\n\n /**\n * The scopes associated with the account. If not provided, they will be\n * derived from the `assets`.\n */\n scopes?: CaipChainId[];\n};\n\n/**\n * Options for creating a mock account with scopes, and optionally assets.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithScopes = BaseMockAccountOptions & {\n /**\n * The scopes associated with the account. These should be in CAIP format.\n */\n scopes: CaipChainId[];\n\n /**\n * The assets associated with the account. If not provided, it will default\n * to an empty array.\n */\n assets?: CaipAssetType[];\n};\n\nexport type GetMockAccountOptions =\n | MockAccountOptionsWithAssets\n | MockAccountOptionsWithScopes;\n\n/**\n * Get a mock account object for testing purposes.\n *\n * @param options - The options for creating the mock account.\n * @param options.address - The address of the account.\n * @param options.scopes - The scopes associated with the account, in CAIP\n * format. If not provided, they will be derived from the `assets`.\n * @param options.assets - The assets associated with the account, in CAIP\n * format. If not provided, it will default to an empty array.\n * @param options.selected - Whether the account is selected by default.\n * @param options.owned - Whether the account is owned by the snap.\n * @param options.id - The ID of the account. If not provided, a pseudo-random\n * UUID will be generated.\n * @returns A mock account object with the specified properties.\n */\nexport function getMockAccount({\n address,\n assets = [],\n selected = false,\n owned = false,\n id = getPseudoRandomUuid(),\n scopes = getScopesFromAssets(assets),\n}: GetMockAccountOptions): SimulationAccount {\n return {\n address,\n id,\n scopes,\n selected,\n owned,\n assets,\n };\n}\n"]}
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { AccountSelectorState, AssetSelectorState, SnapId } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { InstallSnapOptions, SimulationAccount, SimulationAsset, Snap } from "@metamask/snaps-simulation";
|
|
4
4
|
import type { CaipAssetType, CaipChainId } from "@metamask/utils";
|
|
@@ -53,7 +53,7 @@ export declare function installSnap(): Promise<Snap>;
|
|
|
53
53
|
* @returns The snap.
|
|
54
54
|
* @throws If the built-in server is not running, and no snap ID is provided.
|
|
55
55
|
*/
|
|
56
|
-
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof
|
|
56
|
+
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;
|
|
57
57
|
/**
|
|
58
58
|
* Load a snap into the environment. This is the main entry point for testing
|
|
59
59
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
|
@@ -86,7 +86,7 @@ export declare function installSnap<Service extends new (...args: any[]) => Inst
|
|
|
86
86
|
* @returns The snap.
|
|
87
87
|
* @throws If the built-in server is not running, and no snap ID is provided.
|
|
88
88
|
*/
|
|
89
|
-
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof
|
|
89
|
+
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>>(snapId: SnapId, options?: Partial<InstallSnapOptions<Service>>): Promise<Snap>;
|
|
90
90
|
/**
|
|
91
91
|
* Get the state of an AccountSelector based on a {@link SimulationAccount}.
|
|
92
92
|
*
|
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,
|
|
1
|
+
{"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oCAAoC;AACpE,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,IAAI,EACL,mCAAmC;AAGpC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AA+BzB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,IAAI,O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CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG,sBAAsB,GAAG;IAClE;;OAEG;IACH,MAAM,EAAE,WAAW,EAAE,CAAC;IAEtB;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,4BAA4B,GAC5B,4BAA4B,CAAC;AAEjC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,MAAW,EACX,QAAgB,EAChB,KAAa,EACb,EAA0B,EAC1B,MAAoC,GACrC,EAAE,qBAAqB,GAAG,iBAAiB,CAS3C"}
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { AccountSelectorState, AssetSelectorState, SnapId } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { InstallSnapOptions, SimulationAccount, SimulationAsset, Snap } from "@metamask/snaps-simulation";
|
|
4
4
|
import type { CaipAssetType, CaipChainId } from "@metamask/utils";
|
|
@@ -53,7 +53,7 @@ export declare function installSnap(): Promise<Snap>;
|
|
|
53
53
|
* @returns The snap.
|
|
54
54
|
* @throws If the built-in server is not running, and no snap ID is provided.
|
|
55
55
|
*/
|
|
56
|
-
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof
|
|
56
|
+
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;
|
|
57
57
|
/**
|
|
58
58
|
* Load a snap into the environment. This is the main entry point for testing
|
|
59
59
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
|
@@ -86,7 +86,7 @@ export declare function installSnap<Service extends new (...args: any[]) => Inst
|
|
|
86
86
|
* @returns The snap.
|
|
87
87
|
* @throws If the built-in server is not running, and no snap ID is provided.
|
|
88
88
|
*/
|
|
89
|
-
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof
|
|
89
|
+
export declare function installSnap<Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>>(snapId: SnapId, options?: Partial<InstallSnapOptions<Service>>): Promise<Snap>;
|
|
90
90
|
/**
|
|
91
91
|
* Get the state of an AccountSelector based on a {@link SimulationAccount}.
|
|
92
92
|
*
|
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,
|
|
1
|
+
{"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oCAAoC;AACpE,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,IAAI,EACL,mCAAmC;AAGpC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AA+BzB;;;;;;;;;;;;;;;;;;;;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,CAAC,OAAO,gBAAgB,CAAC,EAC7E,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,CAAC,OAAO,gBA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AAE;QACF,MAAM;QACN,QAAQ;QACR,KAAK;QACL,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type {\n AccountSelectorState,\n AssetSelectorState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n InstallSnapOptions,\n SimulationAccount,\n SimulationAsset,\n Snap,\n} from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n getEnvironment,\n getPseudoRandomUuidGenerator,\n getScopesFromAssets,\n} 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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\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\n/**\n * Get the state of an AccountSelector based on a {@link SimulationAccount}.\n *\n * @param account - The {@link SimulationAccount} to get the state from.\n * @returns The state of the AccountSelector.\n */\nexport function getStateFromAccount(\n account: SimulationAccount,\n): AccountSelectorState {\n const { address, scopes } = account;\n return {\n addresses: scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[],\n accountId: account.id,\n };\n}\n\n/**\n * Get the state of an AssetSelector based on a {@link SimulationAsset}.\n *\n * @param id - The Asset id as a CAIP-19 asset type.\n * @param assets - The {@link SimulationAsset} to get the state from.\n * @returns The state of the AssetSelector.\n */\nexport function getStateFromAsset(\n id: CaipAssetType,\n assets: Record<CaipAssetType, SimulationAsset>,\n): AssetSelectorState {\n const asset = assets[id];\n\n assert(asset, `Asset with ID \"${id}\" not found in simulation assets.`);\n\n const { symbol, name } = asset;\n\n return {\n asset: id,\n symbol,\n name,\n };\n}\n\n/**\n * Generate a pseudo-random UUID.\n *\n * @returns A pseudo-random UUID string.\n */\nconst getPseudoRandomUuid = getPseudoRandomUuidGenerator();\n\n/**\n * The base options for the {@link getMockAccount} function.\n */\nexport type BaseMockAccountOptions = {\n /**\n * The address of the account.\n */\n address: string;\n\n /**\n * The ID of the account. If not provided, a pseudo-random UUID will be\n * generated.\n */\n id?: string;\n\n /**\n * Whether the account is selected by default.\n */\n selected?: boolean;\n\n /**\n * Whether the account is owned by the snap.\n */\n owned?: boolean;\n};\n\n/**\n * Options for creating a mock account with assets or scopes. If `scopes` are\n * not provided, they will be derived from the `assets`.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithAssets = BaseMockAccountOptions & {\n /**\n * The assets associated with the account. These should be in CAIP format.\n */\n assets: CaipAssetType[];\n\n /**\n * The scopes associated with the account. If not provided, they will be\n * derived from the `assets`.\n */\n scopes?: CaipChainId[];\n};\n\n/**\n * Options for creating a mock account with scopes, and optionally assets.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithScopes = BaseMockAccountOptions & {\n /**\n * The scopes associated with the account. These should be in CAIP format.\n */\n scopes: CaipChainId[];\n\n /**\n * The assets associated with the account. If not provided, it will default\n * to an empty array.\n */\n assets?: CaipAssetType[];\n};\n\nexport type GetMockAccountOptions =\n | MockAccountOptionsWithAssets\n | MockAccountOptionsWithScopes;\n\n/**\n * Get a mock account object for testing purposes.\n *\n * @param options - The options for creating the mock account.\n * @param options.address - The address of the account.\n * @param options.scopes - The scopes associated with the account, in CAIP\n * format. If not provided, they will be derived from the `assets`.\n * @param options.assets - The assets associated with the account, in CAIP\n * format. If not provided, it will default to an empty array.\n * @param options.selected - Whether the account is selected by default.\n * @param options.owned - Whether the account is owned by the snap.\n * @param options.id - The ID of the account. If not provided, a pseudo-random\n * UUID will be generated.\n * @returns A mock account object with the specified properties.\n */\nexport function getMockAccount({\n address,\n assets = [],\n selected = false,\n owned = false,\n id = getPseudoRandomUuid(),\n scopes = getScopesFromAssets(assets),\n}: GetMockAccountOptions): SimulationAccount {\n return {\n address,\n id,\n scopes,\n selected,\n owned,\n assets,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,8BAA8B;AAChD,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,wBAAwB;AAO7D,OAAO,EACL,UAAU,EACV,cAAc,EACd,4BAA4B,EAC5B,mBAAmB,EACpB,8BAAoB;AAErB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAGjB,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,EA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AAO,CAAC,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAiB,EACjB,MAA8C;IAE9C,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAEzB,MAAM,CAAC,KAAK,EAAE,kBAAkB,EAAE,mCAAmC,CAAC,CAAC;IAEvE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAE/B,OAAO;QACL,KAAK,EAAE,EAAE;QACT,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,4BAA4B,EAAE,CAAC;AAqE3D;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,OAAO,EACP,MAAM,GAAG,EAAE,EACX,QAAQ,GAAG,KAAK,EAChB,KAAK,GAAG,KAAK,EACb,EAAE,GAAG,mBAAmB,EAAE,EAC1B,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,GACd;IACtB,OAAO;QACL,OAAO;QACP,EAAE;QACF,MAAM;QACN,QAAQ;QACR,KAAK;QACL,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { ExecutionService } from '@metamask/snaps-controllers';\nimport type {\n AccountSelectorState,\n AssetSelectorState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n InstallSnapOptions,\n SimulationAccount,\n SimulationAsset,\n Snap,\n} from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\n\nimport {\n rootLogger,\n getEnvironment,\n getPseudoRandomUuidGenerator,\n getScopesFromAssets,\n} 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<typeof ExecutionService>,\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<typeof ExecutionService>,\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<typeof ExecutionService>,\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<typeof ExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onStart,\n onNameLookup,\n onProtocolRequest,\n onClientRequest,\n mockJsonRpc,\n mockJsonRpcOnce,\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\n/**\n * Get the state of an AccountSelector based on a {@link SimulationAccount}.\n *\n * @param account - The {@link SimulationAccount} to get the state from.\n * @returns The state of the AccountSelector.\n */\nexport function getStateFromAccount(\n account: SimulationAccount,\n): AccountSelectorState {\n const { address, scopes } = account;\n return {\n addresses: scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[],\n accountId: account.id,\n };\n}\n\n/**\n * Get the state of an AssetSelector based on a {@link SimulationAsset}.\n *\n * @param id - The Asset id as a CAIP-19 asset type.\n * @param assets - The {@link SimulationAsset} to get the state from.\n * @returns The state of the AssetSelector.\n */\nexport function getStateFromAsset(\n id: CaipAssetType,\n assets: Record<CaipAssetType, SimulationAsset>,\n): AssetSelectorState {\n const asset = assets[id];\n\n assert(asset, `Asset with ID \"${id}\" not found in simulation assets.`);\n\n const { symbol, name } = asset;\n\n return {\n asset: id,\n symbol,\n name,\n };\n}\n\n/**\n * Generate a pseudo-random UUID.\n *\n * @returns A pseudo-random UUID string.\n */\nconst getPseudoRandomUuid = getPseudoRandomUuidGenerator();\n\n/**\n * The base options for the {@link getMockAccount} function.\n */\nexport type BaseMockAccountOptions = {\n /**\n * The address of the account.\n */\n address: string;\n\n /**\n * The ID of the account. If not provided, a pseudo-random UUID will be\n * generated.\n */\n id?: string;\n\n /**\n * Whether the account is selected by default.\n */\n selected?: boolean;\n\n /**\n * Whether the account is owned by the snap.\n */\n owned?: boolean;\n};\n\n/**\n * Options for creating a mock account with assets or scopes. If `scopes` are\n * not provided, they will be derived from the `assets`.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithAssets = BaseMockAccountOptions & {\n /**\n * The assets associated with the account. These should be in CAIP format.\n */\n assets: CaipAssetType[];\n\n /**\n * The scopes associated with the account. If not provided, they will be\n * derived from the `assets`.\n */\n scopes?: CaipChainId[];\n};\n\n/**\n * Options for creating a mock account with scopes, and optionally assets.\n *\n * @see BaseMockAccountOptions\n */\nexport type MockAccountOptionsWithScopes = BaseMockAccountOptions & {\n /**\n * The scopes associated with the account. These should be in CAIP format.\n */\n scopes: CaipChainId[];\n\n /**\n * The assets associated with the account. If not provided, it will default\n * to an empty array.\n */\n assets?: CaipAssetType[];\n};\n\nexport type GetMockAccountOptions =\n | MockAccountOptionsWithAssets\n | MockAccountOptionsWithScopes;\n\n/**\n * Get a mock account object for testing purposes.\n *\n * @param options - The options for creating the mock account.\n * @param options.address - The address of the account.\n * @param options.scopes - The scopes associated with the account, in CAIP\n * format. If not provided, they will be derived from the `assets`.\n * @param options.assets - The assets associated with the account, in CAIP\n * format. If not provided, it will default to an empty array.\n * @param options.selected - Whether the account is selected by default.\n * @param options.owned - Whether the account is owned by the snap.\n * @param options.id - The ID of the account. If not provided, a pseudo-random\n * UUID will be generated.\n * @returns A mock account object with the specified properties.\n */\nexport function getMockAccount({\n address,\n assets = [],\n selected = false,\n owned = false,\n id = getPseudoRandomUuid(),\n scopes = getScopesFromAssets(assets),\n}: GetMockAccountOptions): SimulationAccount {\n return {\n address,\n id,\n scopes,\n selected,\n owned,\n assets,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-jest",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.2",
|
|
4
4
|
"description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"@jest/environment": "^29.5.0",
|
|
61
61
|
"@jest/expect": "^29.5.0",
|
|
62
62
|
"@jest/globals": "^29.5.0",
|
|
63
|
-
"@metamask/snaps-controllers": "^
|
|
64
|
-
"@metamask/snaps-sdk": "^
|
|
65
|
-
"@metamask/snaps-simulation": "^4.1.
|
|
63
|
+
"@metamask/snaps-controllers": "^19.0.0",
|
|
64
|
+
"@metamask/snaps-sdk": "^11.0.0",
|
|
65
|
+
"@metamask/snaps-simulation": "^4.1.2",
|
|
66
66
|
"@metamask/superstruct": "^3.2.1",
|
|
67
|
-
"@metamask/utils": "^11.
|
|
67
|
+
"@metamask/utils": "^11.10.0",
|
|
68
68
|
"express": "^5.1.0",
|
|
69
69
|
"jest-environment-node": "^29.5.0",
|
|
70
70
|
"jest-matcher-utils": "^29.5.0",
|
|
@@ -72,10 +72,9 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@jest/types": "^29.6.3",
|
|
75
|
-
"@lavamoat/allow-scripts": "^
|
|
76
|
-
"@metamask/auto-changelog": "^5.
|
|
77
|
-
"@metamask/
|
|
78
|
-
"@metamask/snaps-utils": "^12.1.0",
|
|
75
|
+
"@lavamoat/allow-scripts": "^4.0.0",
|
|
76
|
+
"@metamask/auto-changelog": "^5.3.2",
|
|
77
|
+
"@metamask/snaps-utils": "^12.1.2",
|
|
79
78
|
"@swc/core": "1.11.31",
|
|
80
79
|
"@swc/jest": "^0.2.38",
|
|
81
80
|
"@ts-bridge/cli": "^0.6.1",
|