@metamask/snaps-jest 4.0.1 → 5.0.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 +16 -1
- package/README.md +66 -179
- package/dist/cjs/environment.js +21 -82
- package/dist/cjs/environment.js.map +1 -1
- package/dist/cjs/helpers.js +118 -43
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/internals/environment.js +1 -1
- package/dist/cjs/internals/environment.js.map +1 -1
- package/dist/cjs/internals/index.js +1 -4
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/internals/request.js +42 -94
- package/dist/cjs/internals/request.js.map +1 -1
- package/dist/cjs/internals/server.js +0 -4
- package/dist/cjs/internals/server.js.map +1 -1
- package/dist/cjs/internals/simulation/constants.js +29 -0
- package/dist/cjs/internals/simulation/constants.js.map +1 -0
- package/dist/cjs/internals/simulation/controllers.js +95 -0
- package/dist/cjs/internals/simulation/controllers.js.map +1 -0
- package/dist/cjs/internals/simulation/files.js +22 -0
- package/dist/cjs/internals/simulation/files.js.map +1 -0
- package/dist/cjs/internals/simulation/index.js +24 -0
- package/dist/cjs/internals/simulation/index.js.map +1 -0
- package/dist/cjs/internals/simulation/interface.js +98 -0
- package/dist/cjs/internals/simulation/interface.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/constants.js +84 -0
- package/dist/cjs/internals/simulation/methods/constants.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/encryption.js +33 -0
- package/dist/cjs/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/get-locale.js +17 -0
- package/dist/cjs/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/index.js +25 -0
- package/dist/cjs/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/interface.js +26 -0
- package/dist/cjs/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/notifications.js +66 -0
- package/dist/cjs/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js +43 -0
- package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/state.js +80 -0
- package/dist/cjs/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/index.js +20 -0
- package/dist/cjs/internals/simulation/methods/index.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/specifications.js +81 -0
- package/dist/cjs/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/engine.js +31 -0
- package/dist/cjs/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/index.js +20 -0
- package/dist/cjs/internals/simulation/middleware/index.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js +30 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/index.js +20 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js +37 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/mock.js +23 -0
- package/dist/cjs/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/cjs/internals/simulation/options.js +24 -0
- package/dist/cjs/internals/simulation/options.js.map +1 -0
- package/dist/cjs/internals/simulation/simulation.js +124 -0
- package/dist/cjs/internals/simulation/simulation.js.map +1 -0
- package/dist/cjs/internals/simulation/store/index.js +23 -0
- package/dist/cjs/internals/simulation/store/index.js.map +1 -0
- package/dist/cjs/internals/simulation/store/mocks.js +52 -0
- package/dist/cjs/internals/simulation/store/mocks.js.map +1 -0
- package/dist/cjs/internals/simulation/store/notifications.js +52 -0
- package/dist/cjs/internals/simulation/store/notifications.js.map +1 -0
- package/dist/cjs/internals/simulation/store/state.js +64 -0
- package/dist/cjs/internals/simulation/store/state.js.map +1 -0
- package/dist/cjs/internals/simulation/store/store.js +57 -0
- package/dist/cjs/internals/simulation/store/store.js.map +1 -0
- package/dist/cjs/internals/simulation/store/ui.js +48 -0
- package/dist/cjs/internals/simulation/store/ui.js.map +1 -0
- package/dist/cjs/internals/structs.js +43 -0
- package/dist/cjs/internals/structs.js.map +1 -1
- package/dist/cjs/matchers.js +5 -2
- package/dist/cjs/matchers.js.map +1 -1
- package/dist/cjs/options.js +0 -6
- package/dist/cjs/options.js.map +1 -1
- package/dist/esm/environment.js +22 -83
- package/dist/esm/environment.js.map +1 -1
- package/dist/esm/helpers.js +127 -46
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/internals/environment.js +1 -1
- package/dist/esm/internals/environment.js.map +1 -1
- package/dist/esm/internals/index.js +1 -5
- package/dist/esm/internals/index.js.map +1 -1
- package/dist/esm/internals/request.js +61 -104
- package/dist/esm/internals/request.js.map +1 -1
- package/dist/esm/internals/server.js +1 -5
- package/dist/esm/internals/server.js.map +1 -1
- package/dist/esm/internals/simulation/constants.js +12 -0
- package/dist/esm/internals/simulation/constants.js.map +1 -0
- package/dist/esm/internals/simulation/controllers.js +90 -0
- package/dist/esm/internals/simulation/controllers.js.map +1 -0
- package/dist/esm/internals/simulation/files.js +19 -0
- package/dist/esm/internals/simulation/files.js.map +1 -0
- package/dist/esm/internals/simulation/index.js +7 -0
- package/dist/esm/internals/simulation/index.js.map +1 -0
- package/dist/esm/internals/simulation/interface.js +95 -0
- package/dist/esm/internals/simulation/interface.js.map +1 -0
- package/dist/esm/internals/simulation/methods/constants.js +69 -0
- package/dist/esm/internals/simulation/methods/constants.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/encryption.js +39 -0
- package/dist/esm/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/get-locale.js +13 -0
- package/dist/esm/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/index.js +8 -0
- package/dist/esm/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/interface.js +18 -0
- package/dist/esm/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/notifications.js +58 -0
- package/dist/esm/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/show-dialog.js +38 -0
- package/dist/esm/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/state.js +74 -0
- package/dist/esm/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/esm/internals/simulation/methods/index.js +3 -0
- package/dist/esm/internals/simulation/methods/index.js.map +1 -0
- package/dist/esm/internals/simulation/methods/specifications.js +84 -0
- package/dist/esm/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/engine.js +33 -0
- package/dist/esm/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/index.js +3 -0
- package/dist/esm/internals/simulation/middleware/index.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js +31 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/index.js +3 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js +37 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/mock.js +18 -0
- package/dist/esm/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/esm/internals/simulation/options.js +20 -0
- package/dist/esm/internals/simulation/options.js.map +1 -0
- package/dist/esm/internals/simulation/simulation.js +128 -0
- package/dist/esm/internals/simulation/simulation.js.map +1 -0
- package/dist/esm/internals/simulation/store/index.js +6 -0
- package/dist/esm/internals/simulation/store/index.js.map +1 -0
- package/dist/esm/internals/simulation/store/mocks.js +32 -0
- package/dist/esm/internals/simulation/store/mocks.js.map +1 -0
- package/dist/esm/internals/simulation/store/notifications.js +30 -0
- package/dist/esm/internals/simulation/store/notifications.js.map +1 -0
- package/dist/esm/internals/simulation/store/state.js +47 -0
- package/dist/esm/internals/simulation/store/state.js.map +1 -0
- package/dist/esm/internals/simulation/store/store.js +50 -0
- package/dist/esm/internals/simulation/store/store.js.map +1 -0
- package/dist/esm/internals/simulation/store/ui.js +21 -0
- package/dist/esm/internals/simulation/store/ui.js.map +1 -0
- package/dist/esm/internals/structs.js +38 -1
- package/dist/esm/internals/structs.js.map +1 -1
- package/dist/esm/matchers.js +5 -2
- package/dist/esm/matchers.js.map +1 -1
- package/dist/esm/options.js +1 -7
- package/dist/esm/options.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/environment.d.ts +14 -15
- package/dist/types/helpers.d.ts +64 -3
- package/dist/types/internals/index.d.ts +1 -4
- package/dist/types/internals/request.d.ts +38 -74
- package/dist/types/internals/simulation/constants.d.ts +13 -0
- package/dist/types/internals/simulation/controllers.d.ts +40 -0
- package/dist/types/internals/simulation/files.d.ts +11 -0
- package/dist/types/internals/simulation/index.d.ts +5 -0
- package/dist/types/internals/simulation/interface.d.ts +25 -0
- package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
- package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
- package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
- package/dist/types/internals/simulation/methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
- package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
- package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
- package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
- package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
- package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
- package/dist/types/internals/simulation/options.d.ts +37 -0
- package/dist/types/internals/simulation/simulation.d.ts +98 -0
- package/dist/types/internals/simulation/store/index.d.ts +4 -0
- package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
- package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
- package/dist/types/internals/simulation/store/state.d.ts +55 -0
- package/dist/types/internals/simulation/store/store.d.ts +22 -0
- package/dist/types/internals/simulation/store/ui.d.ts +25 -0
- package/dist/types/internals/structs.d.ts +153 -0
- package/dist/types/options.d.ts +3 -35
- package/dist/types/types.d.ts +88 -41
- package/package.json +21 -12
- package/dist/cjs/internals/interface.js +0 -103
- package/dist/cjs/internals/interface.js.map +0 -1
- package/dist/cjs/internals/network.js +0 -148
- package/dist/cjs/internals/network.js.map +0 -1
- package/dist/cjs/internals/types.js +0 -6
- package/dist/cjs/internals/types.js.map +0 -1
- package/dist/cjs/internals/wait-for.js +0 -63
- package/dist/cjs/internals/wait-for.js.map +0 -1
- package/dist/esm/internals/interface.js +0 -100
- package/dist/esm/internals/interface.js.map +0 -1
- package/dist/esm/internals/network.js +0 -143
- package/dist/esm/internals/network.js.map +0 -1
- package/dist/esm/internals/types.js +0 -3
- package/dist/esm/internals/types.js.map +0 -1
- package/dist/esm/internals/wait-for.js +0 -63
- package/dist/esm/internals/wait-for.js.map +0 -1
- package/dist/types/internals/interface.d.ts +0 -25
- package/dist/types/internals/network.d.ts +0 -87
- package/dist/types/internals/types.d.ts +0 -18
- package/dist/types/internals/wait-for.d.ts +0 -38
|
@@ -61,6 +61,32 @@ export declare const TransactionOptionsStruct: import("superstruct").Struct<{
|
|
|
61
61
|
*/
|
|
62
62
|
data: import("superstruct").Struct<`0x${string}`, null>;
|
|
63
63
|
}>;
|
|
64
|
+
export declare const SignatureOptionsStruct: import("superstruct").Struct<{
|
|
65
|
+
data: `0x${string}` | Record<string, any> | Record<string, any>[];
|
|
66
|
+
from: `0x${string}`;
|
|
67
|
+
origin: string;
|
|
68
|
+
signatureMethod: "eth_sign" | "personal_sign" | "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4";
|
|
69
|
+
}, {
|
|
70
|
+
/**
|
|
71
|
+
* The origin making the signature request.
|
|
72
|
+
*/
|
|
73
|
+
origin: import("superstruct").Struct<string, null>;
|
|
74
|
+
/**
|
|
75
|
+
* The address signing the signature request. Defaults to a randomly generated
|
|
76
|
+
* address.
|
|
77
|
+
*/
|
|
78
|
+
from: import("superstruct").Struct<`0x${string}`, null>;
|
|
79
|
+
/**
|
|
80
|
+
* The data to send with the transaction. The data may be specified as a
|
|
81
|
+
* `string`, an object, or an array of objects. This covers the data types
|
|
82
|
+
* for the supported signature methods. Defaults to `0x`.
|
|
83
|
+
*/
|
|
84
|
+
data: import("superstruct").Struct<`0x${string}` | Record<string, any> | Record<string, any>[], null>;
|
|
85
|
+
/**
|
|
86
|
+
* The signature method being used.
|
|
87
|
+
*/
|
|
88
|
+
signatureMethod: import("superstruct").Struct<"eth_sign" | "personal_sign" | "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4", null>;
|
|
89
|
+
}>;
|
|
64
90
|
export declare const SnapOptionsStruct: import("superstruct").Struct<{
|
|
65
91
|
timeout?: number | undefined;
|
|
66
92
|
}, {
|
|
@@ -70,6 +96,13 @@ export declare const SnapOptionsStruct: import("superstruct").Struct<{
|
|
|
70
96
|
*/
|
|
71
97
|
timeout: import("superstruct").Struct<number | undefined, null>;
|
|
72
98
|
}>;
|
|
99
|
+
export declare const JsonRpcMockOptionsStruct: import("superstruct").Struct<{
|
|
100
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
101
|
+
method: string;
|
|
102
|
+
}, {
|
|
103
|
+
method: import("superstruct").Struct<string, null>;
|
|
104
|
+
result: import("superstruct").Struct<import("@metamask/snaps-sdk").Json, unknown>;
|
|
105
|
+
}>;
|
|
73
106
|
export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
74
107
|
content?: import("@metamask/snaps-sdk").Panel | {
|
|
75
108
|
value: string;
|
|
@@ -107,6 +140,36 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
107
140
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
108
141
|
label: string;
|
|
109
142
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
143
|
+
} | {
|
|
144
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
145
|
+
name: string;
|
|
146
|
+
value?: string | undefined;
|
|
147
|
+
label?: string | undefined;
|
|
148
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
149
|
+
placeholder?: string | undefined;
|
|
150
|
+
} | {
|
|
151
|
+
value: string;
|
|
152
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
153
|
+
name?: string | undefined;
|
|
154
|
+
variant?: "primary" | "secondary" | undefined;
|
|
155
|
+
buttonType?: "button" | "submit" | undefined;
|
|
156
|
+
} | {
|
|
157
|
+
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
158
|
+
name: string;
|
|
159
|
+
children: ({
|
|
160
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
161
|
+
name: string;
|
|
162
|
+
value?: string | undefined;
|
|
163
|
+
label?: string | undefined;
|
|
164
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
165
|
+
placeholder?: string | undefined;
|
|
166
|
+
} | {
|
|
167
|
+
value: string;
|
|
168
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
169
|
+
name?: string | undefined;
|
|
170
|
+
variant?: "primary" | "secondary" | undefined;
|
|
171
|
+
buttonType?: "button" | "submit" | undefined;
|
|
172
|
+
})[];
|
|
110
173
|
} | undefined;
|
|
111
174
|
}, {
|
|
112
175
|
content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
|
|
@@ -145,6 +208,36 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
145
208
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
146
209
|
label: string;
|
|
147
210
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
211
|
+
} | {
|
|
212
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
213
|
+
name: string;
|
|
214
|
+
value?: string | undefined;
|
|
215
|
+
label?: string | undefined;
|
|
216
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
217
|
+
placeholder?: string | undefined;
|
|
218
|
+
} | {
|
|
219
|
+
value: string;
|
|
220
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
221
|
+
name?: string | undefined;
|
|
222
|
+
variant?: "primary" | "secondary" | undefined;
|
|
223
|
+
buttonType?: "button" | "submit" | undefined;
|
|
224
|
+
} | {
|
|
225
|
+
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
226
|
+
name: string;
|
|
227
|
+
children: ({
|
|
228
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
229
|
+
name: string;
|
|
230
|
+
value?: string | undefined;
|
|
231
|
+
label?: string | undefined;
|
|
232
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
233
|
+
placeholder?: string | undefined;
|
|
234
|
+
} | {
|
|
235
|
+
value: string;
|
|
236
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
237
|
+
name?: string | undefined;
|
|
238
|
+
variant?: "primary" | "secondary" | undefined;
|
|
239
|
+
buttonType?: "button" | "submit" | undefined;
|
|
240
|
+
})[];
|
|
148
241
|
} | undefined, null>;
|
|
149
242
|
}>;
|
|
150
243
|
export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
@@ -195,6 +288,36 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
195
288
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
196
289
|
label: string;
|
|
197
290
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
291
|
+
} | {
|
|
292
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
293
|
+
name: string;
|
|
294
|
+
value?: string | undefined;
|
|
295
|
+
label?: string | undefined;
|
|
296
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
297
|
+
placeholder?: string | undefined;
|
|
298
|
+
} | {
|
|
299
|
+
value: string;
|
|
300
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
301
|
+
name?: string | undefined;
|
|
302
|
+
variant?: "primary" | "secondary" | undefined;
|
|
303
|
+
buttonType?: "button" | "submit" | undefined;
|
|
304
|
+
} | {
|
|
305
|
+
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
306
|
+
name: string;
|
|
307
|
+
children: ({
|
|
308
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
309
|
+
name: string;
|
|
310
|
+
value?: string | undefined;
|
|
311
|
+
label?: string | undefined;
|
|
312
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
313
|
+
placeholder?: string | undefined;
|
|
314
|
+
} | {
|
|
315
|
+
value: string;
|
|
316
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
317
|
+
name?: string | undefined;
|
|
318
|
+
variant?: "primary" | "secondary" | undefined;
|
|
319
|
+
buttonType?: "button" | "submit" | undefined;
|
|
320
|
+
})[];
|
|
198
321
|
} | undefined;
|
|
199
322
|
}, {
|
|
200
323
|
id: import("superstruct").Struct<string, null>;
|
|
@@ -252,5 +375,35 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
252
375
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
253
376
|
label: string;
|
|
254
377
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
378
|
+
} | {
|
|
379
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
380
|
+
name: string;
|
|
381
|
+
value?: string | undefined;
|
|
382
|
+
label?: string | undefined;
|
|
383
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
384
|
+
placeholder?: string | undefined;
|
|
385
|
+
} | {
|
|
386
|
+
value: string;
|
|
387
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
388
|
+
name?: string | undefined;
|
|
389
|
+
variant?: "primary" | "secondary" | undefined;
|
|
390
|
+
buttonType?: "button" | "submit" | undefined;
|
|
391
|
+
} | {
|
|
392
|
+
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
393
|
+
name: string;
|
|
394
|
+
children: ({
|
|
395
|
+
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
396
|
+
name: string;
|
|
397
|
+
value?: string | undefined;
|
|
398
|
+
label?: string | undefined;
|
|
399
|
+
inputType?: "number" | "text" | "password" | undefined;
|
|
400
|
+
placeholder?: string | undefined;
|
|
401
|
+
} | {
|
|
402
|
+
value: string;
|
|
403
|
+
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
404
|
+
name?: string | undefined;
|
|
405
|
+
variant?: "primary" | "secondary" | undefined;
|
|
406
|
+
buttonType?: "button" | "submit" | undefined;
|
|
407
|
+
})[];
|
|
255
408
|
} | undefined, null>;
|
|
256
409
|
}>;
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,41 +1,26 @@
|
|
|
1
1
|
import type { Infer } from 'superstruct';
|
|
2
2
|
declare const SnapsEnvironmentOptionsStruct: import("superstruct").Struct<{
|
|
3
|
-
keepAlive: boolean;
|
|
4
3
|
server: {
|
|
5
4
|
port: number;
|
|
6
|
-
root: string;
|
|
7
5
|
enabled: boolean;
|
|
6
|
+
root: string;
|
|
8
7
|
};
|
|
9
|
-
browser: {
|
|
10
|
-
headless: boolean;
|
|
11
|
-
};
|
|
12
|
-
executionEnvironmentUrl?: string | undefined;
|
|
13
|
-
simulatorUrl?: string | undefined;
|
|
14
8
|
}, {
|
|
15
|
-
executionEnvironmentUrl: import("superstruct").Struct<string | undefined, null>;
|
|
16
|
-
simulatorUrl: import("superstruct").Struct<string | undefined, null>;
|
|
17
|
-
keepAlive: import("superstruct").Struct<boolean, null>;
|
|
18
9
|
server: import("superstruct").Struct<{
|
|
19
10
|
port: number;
|
|
20
|
-
root: string;
|
|
21
11
|
enabled: boolean;
|
|
12
|
+
root: string;
|
|
22
13
|
}, {
|
|
23
14
|
enabled: import("superstruct").Struct<boolean, null>;
|
|
24
15
|
port: import("superstruct").Struct<number, null>;
|
|
25
16
|
root: import("superstruct").Struct<string, null>;
|
|
26
17
|
}>;
|
|
27
|
-
browser: import("superstruct").Struct<{
|
|
28
|
-
headless: boolean;
|
|
29
|
-
}, {
|
|
30
|
-
headless: import("superstruct").Struct<boolean, null>;
|
|
31
|
-
}>;
|
|
32
18
|
}>;
|
|
33
19
|
/**
|
|
34
20
|
* The options for the environment. These can be specified in the Jest
|
|
35
21
|
* configuration under `testEnvironmentOptions`.
|
|
36
22
|
*
|
|
37
23
|
* @example
|
|
38
|
-
* ```json
|
|
39
24
|
* {
|
|
40
25
|
* "testEnvironment": "@metamask/snaps-jest",
|
|
41
26
|
* "testEnvironmentOptions": {
|
|
@@ -46,14 +31,6 @@ declare const SnapsEnvironmentOptionsStruct: import("superstruct").Struct<{
|
|
|
46
31
|
* }
|
|
47
32
|
* }
|
|
48
33
|
* }
|
|
49
|
-
* ```
|
|
50
|
-
* @property executionEnvironmentUrl - The URL of the execution environment. If
|
|
51
|
-
* this is not provided, the execution environment will be served from the
|
|
52
|
-
* built-in HTTP server.
|
|
53
|
-
* @property simulatorUrl - The URL of the simulator. If this is not provided,
|
|
54
|
-
* the simulator will be served from the built-in HTTP server.
|
|
55
|
-
* @property keepAlive - Whether to keep the browser open after the tests have
|
|
56
|
-
* finished. This is useful for debugging. Defaults to `false`.
|
|
57
34
|
* @property server - The options for the built-in HTTP server.
|
|
58
35
|
* @property server.enabled - Whether to run the built-in HTTP server. Defaults
|
|
59
36
|
* to `true`.
|
|
@@ -63,9 +40,6 @@ declare const SnapsEnvironmentOptionsStruct: import("superstruct").Struct<{
|
|
|
63
40
|
* server. Defaults to the current working directory. This is assumed to be the
|
|
64
41
|
* directory containing the snap manifest and `dist` files. If this is a
|
|
65
42
|
* relative path, it will be resolved relative to the current working directory.
|
|
66
|
-
* @property browser - The options for the browser.
|
|
67
|
-
* @property browser.headless - Whether to run the browser in headless mode.
|
|
68
|
-
* Defaults to `true`.
|
|
69
43
|
*/
|
|
70
44
|
export declare type SnapsEnvironmentOptions = Infer<typeof SnapsEnvironmentOptionsStruct>;
|
|
71
45
|
/**
|
|
@@ -77,16 +51,10 @@ export declare type SnapsEnvironmentOptions = Infer<typeof SnapsEnvironmentOptio
|
|
|
77
51
|
* @returns The environment options.
|
|
78
52
|
*/
|
|
79
53
|
export declare function getOptions(testEnvironmentOptions: Record<string, unknown>): {
|
|
80
|
-
keepAlive: boolean;
|
|
81
54
|
server: {
|
|
82
55
|
port: number;
|
|
83
|
-
root: string;
|
|
84
56
|
enabled: boolean;
|
|
57
|
+
root: string;
|
|
85
58
|
};
|
|
86
|
-
browser: {
|
|
87
|
-
headless: boolean;
|
|
88
|
-
};
|
|
89
|
-
executionEnvironmentUrl?: string | undefined;
|
|
90
|
-
simulatorUrl?: string | undefined;
|
|
91
59
|
};
|
|
92
60
|
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
|
|
2
|
-
import type { JsonRpcId, JsonRpcParams } from '@metamask/utils';
|
|
2
|
+
import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';
|
|
3
3
|
import type { Infer } from 'superstruct';
|
|
4
|
-
import type {
|
|
4
|
+
import type { SignatureOptionsStruct, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
|
|
5
5
|
declare module 'expect' {
|
|
6
6
|
interface AsymmetricMatchers {
|
|
7
7
|
toRespondWith(response: unknown): void;
|
|
@@ -16,27 +16,6 @@ declare module 'expect' {
|
|
|
16
16
|
toRender(component: Component): R;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Deeply partialize a type.
|
|
21
|
-
*
|
|
22
|
-
* @template Type - The type to partialize.
|
|
23
|
-
* @returns The deeply partialized type.
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* type Foo = {
|
|
27
|
-
* bar: {
|
|
28
|
-
* baz: string;
|
|
29
|
-
* };
|
|
30
|
-
* qux: number;
|
|
31
|
-
* };
|
|
32
|
-
*
|
|
33
|
-
* type PartialFoo = DeepPartial<Foo>;
|
|
34
|
-
* // { bar?: { baz?: string; }; qux?: number; }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare type DeepPartial<Type> = {
|
|
38
|
-
[Key in keyof Type]?: Type[Key] extends Record<string, unknown> ? DeepPartial<Type[Key]> : Type[Key];
|
|
39
|
-
};
|
|
40
19
|
export declare type RequestOptions = {
|
|
41
20
|
/**
|
|
42
21
|
* The JSON-RPC request ID.
|
|
@@ -82,6 +61,17 @@ export declare type CronjobOptions = Omit<RequestOptions, 'origin'>;
|
|
|
82
61
|
* @property nonce - The nonce to use for the transaction. Defaults to `0`.
|
|
83
62
|
*/
|
|
84
63
|
export declare type TransactionOptions = Infer<typeof TransactionOptionsStruct>;
|
|
64
|
+
/**
|
|
65
|
+
* The options to use for signature requests.
|
|
66
|
+
*
|
|
67
|
+
* @property origin - The origin to send the signature request from. Defaults to
|
|
68
|
+
* `metamask.io`.
|
|
69
|
+
* @property from - The address to send the signature from. Defaults to a
|
|
70
|
+
* randomly generated address.
|
|
71
|
+
* @property data - The data to sign. Defaults to `0x`.
|
|
72
|
+
* @property signatureMethod - The signature method.
|
|
73
|
+
*/
|
|
74
|
+
export declare type SignatureOptions = Infer<typeof SignatureOptionsStruct>;
|
|
85
75
|
/**
|
|
86
76
|
* The options to use for requests to the snap.
|
|
87
77
|
*
|
|
@@ -167,19 +157,31 @@ export declare type SnapRequestObject = {
|
|
|
167
157
|
* {@link SnapRequestObject} fields.
|
|
168
158
|
*/
|
|
169
159
|
export declare type SnapRequest = Promise<SnapResponse> & SnapRequestObject;
|
|
160
|
+
/**
|
|
161
|
+
* The options to use for mocking a JSON-RPC request.
|
|
162
|
+
*/
|
|
163
|
+
export declare type JsonRpcMockOptions = {
|
|
164
|
+
/**
|
|
165
|
+
* The JSON-RPC request method.
|
|
166
|
+
*/
|
|
167
|
+
method: string;
|
|
168
|
+
/**
|
|
169
|
+
* The JSON-RPC response, which will be returned when a request with the
|
|
170
|
+
* specified method is sent.
|
|
171
|
+
*/
|
|
172
|
+
result: Json;
|
|
173
|
+
};
|
|
170
174
|
/**
|
|
171
175
|
* This is the main entry point to interact with the snap. It is returned by
|
|
172
176
|
* {@link installSnap}, and has methods to send requests to the snap.
|
|
173
177
|
*
|
|
174
178
|
* @example
|
|
175
|
-
* ```ts
|
|
176
179
|
* import { installSnap } from '@metamask/snaps-jest';
|
|
177
180
|
*
|
|
178
181
|
* const snap = await installSnap();
|
|
179
182
|
* const response = await snap.request({ method: 'hello' });
|
|
180
183
|
*
|
|
181
184
|
* expect(response).toRespondWith('Hello, world!');
|
|
182
|
-
* ```
|
|
183
185
|
*/
|
|
184
186
|
export declare type Snap = {
|
|
185
187
|
/**
|
|
@@ -198,7 +200,26 @@ export declare type Snap = {
|
|
|
198
200
|
* will be filled in with default values.
|
|
199
201
|
* @returns The response.
|
|
200
202
|
*/
|
|
203
|
+
onTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponse>;
|
|
204
|
+
/**
|
|
205
|
+
* Send a transaction to the snap.
|
|
206
|
+
*
|
|
207
|
+
* @param transaction - The transaction. This is similar to an Ethereum
|
|
208
|
+
* transaction object, but has an extra `origin` field. Any missing fields
|
|
209
|
+
* will be filled in with default values.
|
|
210
|
+
* @returns The response.
|
|
211
|
+
* @deprecated Use {@link onTransaction} instead.
|
|
212
|
+
*/
|
|
201
213
|
sendTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponse>;
|
|
214
|
+
/**
|
|
215
|
+
* Send a signature request to the snap.
|
|
216
|
+
*
|
|
217
|
+
* @param signature - The signature request object. Contains the params from
|
|
218
|
+
* the various signature methods, but has an extra `origin` and `signatureMethod` field.
|
|
219
|
+
* Any missing fields will be filled in with default values.
|
|
220
|
+
* @returns The response.
|
|
221
|
+
*/
|
|
222
|
+
onSignature(signature?: Partial<SignatureOptions>): Promise<SnapResponse>;
|
|
202
223
|
/**
|
|
203
224
|
* Run a cronjob in the snap. This is similar to {@link request}, but the
|
|
204
225
|
* request will be sent to the `onCronjob` method of the snap.
|
|
@@ -208,31 +229,57 @@ export declare type Snap = {
|
|
|
208
229
|
* `endowment:cronjob` permission.
|
|
209
230
|
* @returns The response promise, with extra {@link SnapRequestObject} fields.
|
|
210
231
|
*/
|
|
232
|
+
onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;
|
|
233
|
+
/**
|
|
234
|
+
* Run a cronjob in the snap. This is similar to {@link request}, but the
|
|
235
|
+
* request will be sent to the `onCronjob` method of the snap.
|
|
236
|
+
*
|
|
237
|
+
* @param cronjob - The cronjob request. This is similar to a JSON-RPC
|
|
238
|
+
* request, and is normally specified in the snap manifest, under the
|
|
239
|
+
* `endowment:cronjob` permission.
|
|
240
|
+
* @returns The response promise, with extra {@link SnapRequestObject} fields.
|
|
241
|
+
* @deprecated Use {@link onCronjob} instead.
|
|
242
|
+
*/
|
|
211
243
|
runCronjob(cronjob: CronjobOptions): SnapRequest;
|
|
212
244
|
/**
|
|
213
|
-
*
|
|
214
|
-
* the test environment, and calling it is not strictly necessary.
|
|
245
|
+
* Get the response from the snap's `onHomePage` method.
|
|
215
246
|
*
|
|
216
|
-
* @returns
|
|
247
|
+
* @returns The response.
|
|
217
248
|
*/
|
|
218
|
-
|
|
249
|
+
onHomePage(): Promise<SnapResponse>;
|
|
219
250
|
/**
|
|
220
|
-
*
|
|
251
|
+
* Mock a JSON-RPC request. This will cause the snap to respond with the
|
|
252
|
+
* specified response when a request with the specified method is sent.
|
|
221
253
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @
|
|
254
|
+
* @param mock - The mock options.
|
|
255
|
+
* @param mock.method - The JSON-RPC request method.
|
|
256
|
+
* @param mock.result - The JSON-RPC response, which will be returned when a
|
|
257
|
+
* request with the specified method is sent.
|
|
258
|
+
* @example
|
|
259
|
+
* import { installSnap } from '@metamask/snaps-jest';
|
|
260
|
+
*
|
|
261
|
+
* // In the test
|
|
262
|
+
* const snap = await installSnap();
|
|
263
|
+
* snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });
|
|
264
|
+
*
|
|
265
|
+
* // In the Snap
|
|
266
|
+
* const response =
|
|
267
|
+
* await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']
|
|
224
268
|
*/
|
|
225
|
-
mock
|
|
269
|
+
mockJsonRpc(mock: JsonRpcMockOptions): {
|
|
270
|
+
/**
|
|
271
|
+
* Remove the mock.
|
|
272
|
+
*/
|
|
273
|
+
unmock(): void;
|
|
274
|
+
};
|
|
226
275
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
276
|
+
* Close the page running the snap. This is mainly useful for cleaning up
|
|
277
|
+
* the test environment, and calling it is not strictly necessary.
|
|
229
278
|
*
|
|
230
|
-
* @
|
|
231
|
-
* @
|
|
232
|
-
*
|
|
233
|
-
* @param options.result - The JSON value to return.
|
|
234
|
-
* @returns A {@link Mock} object, with an `unmock` function.
|
|
279
|
+
* @returns A promise that resolves when the page is closed.
|
|
280
|
+
* @deprecated Snaps are now automatically closed when the test ends. This
|
|
281
|
+
* method will be removed in a future release.
|
|
235
282
|
*/
|
|
236
|
-
|
|
283
|
+
close(): Promise<void>;
|
|
237
284
|
};
|
|
238
285
|
export declare type SnapResponse = Infer<typeof SnapResponseStruct>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -36,22 +36,31 @@
|
|
|
36
36
|
"@jest/environment": "^29.5.0",
|
|
37
37
|
"@jest/expect": "^29.5.0",
|
|
38
38
|
"@jest/globals": "^29.5.0",
|
|
39
|
-
"@metamask/
|
|
40
|
-
"@metamask/
|
|
41
|
-
"@metamask/
|
|
42
|
-
"@metamask/
|
|
43
|
-
"@metamask/
|
|
39
|
+
"@metamask/base-controller": "^4.1.0",
|
|
40
|
+
"@metamask/eth-json-rpc-middleware": "^12.1.0",
|
|
41
|
+
"@metamask/json-rpc-engine": "^7.3.2",
|
|
42
|
+
"@metamask/json-rpc-middleware-stream": "^6.0.2",
|
|
43
|
+
"@metamask/key-tree": "^9.0.0",
|
|
44
|
+
"@metamask/permission-controller": "^8.0.0",
|
|
45
|
+
"@metamask/snaps-controllers": "^5.0.0",
|
|
46
|
+
"@metamask/snaps-execution-environments": "^4.0.0",
|
|
47
|
+
"@metamask/snaps-rpc-methods": "^6.0.0",
|
|
48
|
+
"@metamask/snaps-sdk": "^2.0.0",
|
|
49
|
+
"@metamask/snaps-utils": "^6.0.0",
|
|
50
|
+
"@metamask/utils": "^8.3.0",
|
|
51
|
+
"@reduxjs/toolkit": "^1.9.5",
|
|
44
52
|
"express": "^4.18.2",
|
|
45
53
|
"jest-environment-node": "^29.5.0",
|
|
46
54
|
"jest-matcher-utils": "^29.5.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
55
|
+
"readable-stream": "^3.6.2",
|
|
56
|
+
"redux": "^4.2.1",
|
|
57
|
+
"redux-saga": "^1.2.3",
|
|
58
|
+
"superstruct": "^1.0.3"
|
|
51
59
|
},
|
|
52
60
|
"devDependencies": {
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
61
|
+
"@jest/types": "^29.6.3",
|
|
62
|
+
"@lavamoat/allow-scripts": "^3.0.0",
|
|
63
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
55
64
|
"@metamask/eslint-config": "^12.1.0",
|
|
56
65
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
57
66
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
getInterface: function() {
|
|
13
|
-
return getInterface;
|
|
14
|
-
},
|
|
15
|
-
getNotifications: function() {
|
|
16
|
-
return getNotifications;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _snapssdk = require("@metamask/snaps-sdk");
|
|
20
|
-
const _utils = require("@metamask/utils");
|
|
21
|
-
const _superstruct = require("superstruct");
|
|
22
|
-
const _structs = require("./structs");
|
|
23
|
-
const _waitfor = require("./wait-for");
|
|
24
|
-
async function getInterface(page, options = {}) {
|
|
25
|
-
const { timeout } = (0, _superstruct.create)(options, _structs.SnapOptionsStruct);
|
|
26
|
-
const { type, node: content } = await (0, _waitfor.waitFor)(async ()=>{
|
|
27
|
-
const ui = await page.evaluate(()=>{
|
|
28
|
-
const state = window.__SIMULATOR_API__.getState();
|
|
29
|
-
return state.simulation.ui;
|
|
30
|
-
});
|
|
31
|
-
(0, _utils.assert)(ui);
|
|
32
|
-
return ui;
|
|
33
|
-
}, {
|
|
34
|
-
timeout,
|
|
35
|
-
message: 'Timed out waiting for snap interface to be shown.'
|
|
36
|
-
});
|
|
37
|
-
switch(type){
|
|
38
|
-
case _snapssdk.DialogType.Alert:
|
|
39
|
-
return {
|
|
40
|
-
type: 'alert',
|
|
41
|
-
content,
|
|
42
|
-
ok: async ()=>{
|
|
43
|
-
await page.evaluate(()=>{
|
|
44
|
-
window.__SIMULATOR_API__.dispatch({
|
|
45
|
-
type: 'simulation/resolveUserInterface',
|
|
46
|
-
payload: null
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
case _snapssdk.DialogType.Confirmation:
|
|
52
|
-
return {
|
|
53
|
-
type: 'confirmation',
|
|
54
|
-
content,
|
|
55
|
-
ok: async ()=>{
|
|
56
|
-
await page.evaluate(()=>{
|
|
57
|
-
window.__SIMULATOR_API__.dispatch({
|
|
58
|
-
type: 'simulation/resolveUserInterface',
|
|
59
|
-
payload: true
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
cancel: async ()=>{
|
|
64
|
-
await page.evaluate(()=>{
|
|
65
|
-
window.__SIMULATOR_API__.dispatch({
|
|
66
|
-
type: 'simulation/resolveUserInterface',
|
|
67
|
-
payload: false
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
case _snapssdk.DialogType.Prompt:
|
|
73
|
-
return {
|
|
74
|
-
type: 'prompt',
|
|
75
|
-
content,
|
|
76
|
-
ok: async (value)=>{
|
|
77
|
-
await page.evaluate((payload)=>{
|
|
78
|
-
window.__SIMULATOR_API__.dispatch({
|
|
79
|
-
type: 'simulation/resolveUserInterface',
|
|
80
|
-
payload
|
|
81
|
-
});
|
|
82
|
-
}, value);
|
|
83
|
-
},
|
|
84
|
-
cancel: async ()=>{
|
|
85
|
-
await page.evaluate(()=>{
|
|
86
|
-
window.__SIMULATOR_API__.dispatch({
|
|
87
|
-
type: 'simulation/resolveUserInterface',
|
|
88
|
-
payload: null
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
default:
|
|
94
|
-
throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async function getNotifications(page, requestId) {
|
|
98
|
-
return await page.evaluate((id)=>{
|
|
99
|
-
return window.__SIMULATOR_API__.getNotifications(id);
|
|
100
|
-
}, requestId);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=interface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/interface.ts"],"sourcesContent":["import { DialogType } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\nimport type { Page } from 'puppeteer';\nimport { create } from 'superstruct';\n\nimport type { SnapInterface, SnapOptions } from '../types';\nimport { SnapOptionsStruct } from './structs';\nimport { waitFor } from './wait-for';\n\n/**\n * Get the current snap user interface (i.e., dialog). This will throw an error\n * if the snap does not show a user interface within the timeout.\n *\n * @param page - The page to get the interface from.\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\nexport async function getInterface(\n page: Page,\n options: SnapOptions = {},\n): Promise<SnapInterface> {\n const { timeout } = create(options, SnapOptionsStruct);\n\n const { type, node: content } = await waitFor(\n async () => {\n const ui = await page.evaluate(() => {\n const state = window.__SIMULATOR_API__.getState();\n return state.simulation.ui;\n });\n\n assert(ui);\n return ui;\n },\n {\n timeout,\n message: 'Timed out waiting for snap interface to be shown.',\n },\n );\n\n switch (type) {\n case DialogType.Alert:\n return {\n type: 'alert',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n case DialogType.Confirmation:\n return {\n type: 'confirmation',\n content,\n\n ok: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: true,\n });\n });\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: false,\n });\n });\n },\n };\n\n case DialogType.Prompt:\n return {\n type: 'prompt',\n content,\n\n ok: async (value) => {\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload,\n });\n }, value);\n },\n\n cancel: async () => {\n await page.evaluate(() => {\n window.__SIMULATOR_API__.dispatch({\n type: 'simulation/resolveUserInterface',\n payload: null,\n });\n });\n },\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: ${String(type)}.`);\n }\n}\n\n/**\n * Get the text of the notifications.\n *\n * @param page - The page to get the notifications from.\n * @param requestId - The ID of the request to get the notifications for.\n * @returns The text of the notifications, in order of appearance.\n */\nexport async function getNotifications(page: Page, requestId: string) {\n return await page.evaluate((id) => {\n return window.__SIMULATOR_API__.getNotifications(id);\n }, requestId);\n}\n"],"names":["getInterface","getNotifications","page","options","timeout","create","SnapOptionsStruct","type","node","content","waitFor","ui","evaluate","state","window","__SIMULATOR_API__","getState","simulation","assert","message","DialogType","Alert","ok","dispatch","payload","Confirmation","cancel","Prompt","value","Error","String","requestId","id"],"mappings":";;;;;;;;;;;IAmBsBA,YAAY;eAAZA;;IAkGAC,gBAAgB;eAAhBA;;;0BArHK;uBACJ;6BAEA;yBAGW;yBACV;AAYjB,eAAeD,aACpBE,IAAU,EACVC,UAAuB,CAAC,CAAC;IAEzB,MAAM,EAAEC,OAAO,EAAE,GAAGC,IAAAA,mBAAM,EAACF,SAASG,0BAAiB;IAErD,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMC,IAAAA,gBAAO,EAC3C;QACE,MAAMC,KAAK,MAAMT,KAAKU,QAAQ,CAAC;YAC7B,MAAMC,QAAQC,OAAOC,iBAAiB,CAACC,QAAQ;YAC/C,OAAOH,MAAMI,UAAU,CAACN,EAAE;QAC5B;QAEAO,IAAAA,aAAM,EAACP;QACP,OAAOA;IACT,GACA;QACEP;QACAe,SAAS;IACX;IAGF,OAAQZ;QACN,KAAKa,oBAAU,CAACC,KAAK;YACnB,OAAO;gBACLd,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,oBAAU,CAACK,YAAY;YAC1B,OAAO;gBACLlB,MAAM;gBACNE;gBAEAa,IAAI;oBACF,MAAMpB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;gBAEAE,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF,KAAKJ,oBAAU,CAACO,MAAM;YACpB,OAAO;gBACLpB,MAAM;gBACNE;gBAEAa,IAAI,OAAOM;oBACT,MAAM1B,KAAKU,QAAQ,CAAC,CAACY;wBACnBV,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB;wBACF;oBACF,GAAGI;gBACL;gBAEAF,QAAQ;oBACN,MAAMxB,KAAKU,QAAQ,CAAC;wBAClBE,OAAOC,iBAAiB,CAACQ,QAAQ,CAAC;4BAChChB,MAAM;4BACNiB,SAAS;wBACX;oBACF;gBACF;YACF;QAEF;YACE,MAAM,IAAIK,MAAM,CAAC,oCAAoC,EAAEC,OAAOvB,MAAM,CAAC,CAAC;IAC1E;AACF;AASO,eAAeN,iBAAiBC,IAAU,EAAE6B,SAAiB;IAClE,OAAO,MAAM7B,KAAKU,QAAQ,CAAC,CAACoB;QAC1B,OAAOlB,OAAOC,iBAAiB,CAACd,gBAAgB,CAAC+B;IACnD,GAAGD;AACL"}
|