@metamask/snaps-jest 4.0.0 → 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.
Files changed (217) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/README.md +66 -179
  3. package/dist/cjs/environment.js +21 -82
  4. package/dist/cjs/environment.js.map +1 -1
  5. package/dist/cjs/helpers.js +118 -43
  6. package/dist/cjs/helpers.js.map +1 -1
  7. package/dist/cjs/internals/environment.js +1 -1
  8. package/dist/cjs/internals/environment.js.map +1 -1
  9. package/dist/cjs/internals/index.js +1 -4
  10. package/dist/cjs/internals/index.js.map +1 -1
  11. package/dist/cjs/internals/request.js +42 -94
  12. package/dist/cjs/internals/request.js.map +1 -1
  13. package/dist/cjs/internals/server.js +0 -4
  14. package/dist/cjs/internals/server.js.map +1 -1
  15. package/dist/cjs/internals/simulation/constants.js +29 -0
  16. package/dist/cjs/internals/simulation/constants.js.map +1 -0
  17. package/dist/cjs/internals/simulation/controllers.js +95 -0
  18. package/dist/cjs/internals/simulation/controllers.js.map +1 -0
  19. package/dist/cjs/internals/simulation/files.js +22 -0
  20. package/dist/cjs/internals/simulation/files.js.map +1 -0
  21. package/dist/cjs/internals/simulation/index.js +24 -0
  22. package/dist/cjs/internals/simulation/index.js.map +1 -0
  23. package/dist/cjs/internals/simulation/interface.js +98 -0
  24. package/dist/cjs/internals/simulation/interface.js.map +1 -0
  25. package/dist/cjs/internals/simulation/methods/constants.js +84 -0
  26. package/dist/cjs/internals/simulation/methods/constants.js.map +1 -0
  27. package/dist/cjs/internals/simulation/methods/hooks/encryption.js +33 -0
  28. package/dist/cjs/internals/simulation/methods/hooks/encryption.js.map +1 -0
  29. package/dist/cjs/internals/simulation/methods/hooks/get-locale.js +17 -0
  30. package/dist/cjs/internals/simulation/methods/hooks/get-locale.js.map +1 -0
  31. package/dist/cjs/internals/simulation/methods/hooks/index.js +25 -0
  32. package/dist/cjs/internals/simulation/methods/hooks/index.js.map +1 -0
  33. package/dist/cjs/internals/simulation/methods/hooks/interface.js +26 -0
  34. package/dist/cjs/internals/simulation/methods/hooks/interface.js.map +1 -0
  35. package/dist/cjs/internals/simulation/methods/hooks/notifications.js +66 -0
  36. package/dist/cjs/internals/simulation/methods/hooks/notifications.js.map +1 -0
  37. package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js +43 -0
  38. package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
  39. package/dist/cjs/internals/simulation/methods/hooks/state.js +80 -0
  40. package/dist/cjs/internals/simulation/methods/hooks/state.js.map +1 -0
  41. package/dist/cjs/internals/simulation/methods/index.js +20 -0
  42. package/dist/cjs/internals/simulation/methods/index.js.map +1 -0
  43. package/dist/cjs/internals/simulation/methods/specifications.js +81 -0
  44. package/dist/cjs/internals/simulation/methods/specifications.js.map +1 -0
  45. package/dist/cjs/internals/simulation/middleware/engine.js +31 -0
  46. package/dist/cjs/internals/simulation/middleware/engine.js.map +1 -0
  47. package/dist/cjs/internals/simulation/middleware/index.js +20 -0
  48. package/dist/cjs/internals/simulation/middleware/index.js.map +1 -0
  49. package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js +30 -0
  50. package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
  51. package/dist/cjs/internals/simulation/middleware/internal-methods/index.js +20 -0
  52. package/dist/cjs/internals/simulation/middleware/internal-methods/index.js.map +1 -0
  53. package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js +37 -0
  54. package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
  55. package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
  56. package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
  57. package/dist/cjs/internals/simulation/middleware/mock.js +23 -0
  58. package/dist/cjs/internals/simulation/middleware/mock.js.map +1 -0
  59. package/dist/cjs/internals/simulation/options.js +24 -0
  60. package/dist/cjs/internals/simulation/options.js.map +1 -0
  61. package/dist/cjs/internals/simulation/simulation.js +124 -0
  62. package/dist/cjs/internals/simulation/simulation.js.map +1 -0
  63. package/dist/cjs/internals/simulation/store/index.js +23 -0
  64. package/dist/cjs/internals/simulation/store/index.js.map +1 -0
  65. package/dist/cjs/internals/simulation/store/mocks.js +52 -0
  66. package/dist/cjs/internals/simulation/store/mocks.js.map +1 -0
  67. package/dist/cjs/internals/simulation/store/notifications.js +52 -0
  68. package/dist/cjs/internals/simulation/store/notifications.js.map +1 -0
  69. package/dist/cjs/internals/simulation/store/state.js +64 -0
  70. package/dist/cjs/internals/simulation/store/state.js.map +1 -0
  71. package/dist/cjs/internals/simulation/store/store.js +57 -0
  72. package/dist/cjs/internals/simulation/store/store.js.map +1 -0
  73. package/dist/cjs/internals/simulation/store/ui.js +48 -0
  74. package/dist/cjs/internals/simulation/store/ui.js.map +1 -0
  75. package/dist/cjs/internals/structs.js +47 -5
  76. package/dist/cjs/internals/structs.js.map +1 -1
  77. package/dist/cjs/matchers.js +5 -2
  78. package/dist/cjs/matchers.js.map +1 -1
  79. package/dist/cjs/options.js +0 -6
  80. package/dist/cjs/options.js.map +1 -1
  81. package/dist/esm/environment.js +22 -83
  82. package/dist/esm/environment.js.map +1 -1
  83. package/dist/esm/helpers.js +127 -46
  84. package/dist/esm/helpers.js.map +1 -1
  85. package/dist/esm/internals/environment.js +1 -1
  86. package/dist/esm/internals/environment.js.map +1 -1
  87. package/dist/esm/internals/index.js +1 -5
  88. package/dist/esm/internals/index.js.map +1 -1
  89. package/dist/esm/internals/request.js +61 -104
  90. package/dist/esm/internals/request.js.map +1 -1
  91. package/dist/esm/internals/server.js +1 -5
  92. package/dist/esm/internals/server.js.map +1 -1
  93. package/dist/esm/internals/simulation/constants.js +12 -0
  94. package/dist/esm/internals/simulation/constants.js.map +1 -0
  95. package/dist/esm/internals/simulation/controllers.js +90 -0
  96. package/dist/esm/internals/simulation/controllers.js.map +1 -0
  97. package/dist/esm/internals/simulation/files.js +19 -0
  98. package/dist/esm/internals/simulation/files.js.map +1 -0
  99. package/dist/esm/internals/simulation/index.js +7 -0
  100. package/dist/esm/internals/simulation/index.js.map +1 -0
  101. package/dist/esm/internals/simulation/interface.js +95 -0
  102. package/dist/esm/internals/simulation/interface.js.map +1 -0
  103. package/dist/esm/internals/simulation/methods/constants.js +69 -0
  104. package/dist/esm/internals/simulation/methods/constants.js.map +1 -0
  105. package/dist/esm/internals/simulation/methods/hooks/encryption.js +39 -0
  106. package/dist/esm/internals/simulation/methods/hooks/encryption.js.map +1 -0
  107. package/dist/esm/internals/simulation/methods/hooks/get-locale.js +13 -0
  108. package/dist/esm/internals/simulation/methods/hooks/get-locale.js.map +1 -0
  109. package/dist/esm/internals/simulation/methods/hooks/index.js +8 -0
  110. package/dist/esm/internals/simulation/methods/hooks/index.js.map +1 -0
  111. package/dist/esm/internals/simulation/methods/hooks/interface.js +18 -0
  112. package/dist/esm/internals/simulation/methods/hooks/interface.js.map +1 -0
  113. package/dist/esm/internals/simulation/methods/hooks/notifications.js +58 -0
  114. package/dist/esm/internals/simulation/methods/hooks/notifications.js.map +1 -0
  115. package/dist/esm/internals/simulation/methods/hooks/show-dialog.js +38 -0
  116. package/dist/esm/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
  117. package/dist/esm/internals/simulation/methods/hooks/state.js +74 -0
  118. package/dist/esm/internals/simulation/methods/hooks/state.js.map +1 -0
  119. package/dist/esm/internals/simulation/methods/index.js +3 -0
  120. package/dist/esm/internals/simulation/methods/index.js.map +1 -0
  121. package/dist/esm/internals/simulation/methods/specifications.js +84 -0
  122. package/dist/esm/internals/simulation/methods/specifications.js.map +1 -0
  123. package/dist/esm/internals/simulation/middleware/engine.js +33 -0
  124. package/dist/esm/internals/simulation/middleware/engine.js.map +1 -0
  125. package/dist/esm/internals/simulation/middleware/index.js +3 -0
  126. package/dist/esm/internals/simulation/middleware/index.js.map +1 -0
  127. package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js +31 -0
  128. package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
  129. package/dist/esm/internals/simulation/middleware/internal-methods/index.js +3 -0
  130. package/dist/esm/internals/simulation/middleware/internal-methods/index.js.map +1 -0
  131. package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js +37 -0
  132. package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
  133. package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
  134. package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
  135. package/dist/esm/internals/simulation/middleware/mock.js +18 -0
  136. package/dist/esm/internals/simulation/middleware/mock.js.map +1 -0
  137. package/dist/esm/internals/simulation/options.js +20 -0
  138. package/dist/esm/internals/simulation/options.js.map +1 -0
  139. package/dist/esm/internals/simulation/simulation.js +128 -0
  140. package/dist/esm/internals/simulation/simulation.js.map +1 -0
  141. package/dist/esm/internals/simulation/store/index.js +6 -0
  142. package/dist/esm/internals/simulation/store/index.js.map +1 -0
  143. package/dist/esm/internals/simulation/store/mocks.js +32 -0
  144. package/dist/esm/internals/simulation/store/mocks.js.map +1 -0
  145. package/dist/esm/internals/simulation/store/notifications.js +30 -0
  146. package/dist/esm/internals/simulation/store/notifications.js.map +1 -0
  147. package/dist/esm/internals/simulation/store/state.js +47 -0
  148. package/dist/esm/internals/simulation/store/state.js.map +1 -0
  149. package/dist/esm/internals/simulation/store/store.js +50 -0
  150. package/dist/esm/internals/simulation/store/store.js.map +1 -0
  151. package/dist/esm/internals/simulation/store/ui.js +21 -0
  152. package/dist/esm/internals/simulation/store/ui.js.map +1 -0
  153. package/dist/esm/internals/structs.js +41 -5
  154. package/dist/esm/internals/structs.js.map +1 -1
  155. package/dist/esm/matchers.js +5 -2
  156. package/dist/esm/matchers.js.map +1 -1
  157. package/dist/esm/options.js +1 -7
  158. package/dist/esm/options.js.map +1 -1
  159. package/dist/esm/types.js.map +1 -1
  160. package/dist/types/environment.d.ts +14 -15
  161. package/dist/types/helpers.d.ts +64 -3
  162. package/dist/types/internals/index.d.ts +1 -4
  163. package/dist/types/internals/request.d.ts +38 -56
  164. package/dist/types/internals/simulation/constants.d.ts +13 -0
  165. package/dist/types/internals/simulation/controllers.d.ts +40 -0
  166. package/dist/types/internals/simulation/files.d.ts +11 -0
  167. package/dist/types/internals/simulation/index.d.ts +5 -0
  168. package/dist/types/internals/simulation/interface.d.ts +25 -0
  169. package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
  170. package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
  171. package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
  172. package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
  173. package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
  174. package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
  175. package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
  176. package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
  177. package/dist/types/internals/simulation/methods/index.d.ts +1 -0
  178. package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
  179. package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
  180. package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
  181. package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
  182. package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
  183. package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
  184. package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
  185. package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
  186. package/dist/types/internals/simulation/options.d.ts +37 -0
  187. package/dist/types/internals/simulation/simulation.d.ts +98 -0
  188. package/dist/types/internals/simulation/store/index.d.ts +4 -0
  189. package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
  190. package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
  191. package/dist/types/internals/simulation/store/state.d.ts +55 -0
  192. package/dist/types/internals/simulation/store/store.d.ts +22 -0
  193. package/dist/types/internals/simulation/store/ui.d.ts +25 -0
  194. package/dist/types/internals/structs.d.ts +229 -16
  195. package/dist/types/options.d.ts +3 -35
  196. package/dist/types/types.d.ts +88 -41
  197. package/package.json +21 -12
  198. package/dist/cjs/internals/interface.js +0 -103
  199. package/dist/cjs/internals/interface.js.map +0 -1
  200. package/dist/cjs/internals/network.js +0 -148
  201. package/dist/cjs/internals/network.js.map +0 -1
  202. package/dist/cjs/internals/types.js +0 -6
  203. package/dist/cjs/internals/types.js.map +0 -1
  204. package/dist/cjs/internals/wait-for.js +0 -63
  205. package/dist/cjs/internals/wait-for.js.map +0 -1
  206. package/dist/esm/internals/interface.js +0 -100
  207. package/dist/esm/internals/interface.js.map +0 -1
  208. package/dist/esm/internals/network.js +0 -143
  209. package/dist/esm/internals/network.js.map +0 -1
  210. package/dist/esm/internals/types.js +0 -3
  211. package/dist/esm/internals/types.js.map +0 -1
  212. package/dist/esm/internals/wait-for.js +0 -63
  213. package/dist/esm/internals/wait-for.js.map +0 -1
  214. package/dist/types/internals/interface.d.ts +0 -25
  215. package/dist/types/internals/network.d.ts +0 -87
  216. package/dist/types/internals/types.d.ts +0 -18
  217. 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;
@@ -87,11 +120,56 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
87
120
  type: import("@metamask/snaps-sdk").NodeType.Spinner;
88
121
  } | {
89
122
  value: string;
90
- type: import("@metamask/snaps-sdk").NodeType.Text; /**
91
- * The timeout in milliseconds to use for requests to the snap. Defaults to
92
- * `1000`.
93
- */
123
+ type: import("@metamask/snaps-sdk").NodeType.Text;
94
124
  markdown?: boolean | undefined;
125
+ } | {
126
+ value: string;
127
+ type: import("@metamask/snaps-sdk").NodeType.Address;
128
+ } | {
129
+ value: {
130
+ value: string;
131
+ type: import("@metamask/snaps-sdk").NodeType.Image;
132
+ } | {
133
+ value: string;
134
+ type: import("@metamask/snaps-sdk").NodeType.Text;
135
+ markdown?: boolean | undefined;
136
+ } | {
137
+ value: string;
138
+ type: import("@metamask/snaps-sdk").NodeType.Address;
139
+ };
140
+ type: import("@metamask/snaps-sdk").NodeType.Row;
141
+ label: string;
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
+ })[];
95
173
  } | undefined;
96
174
  }, {
97
175
  content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
@@ -110,11 +188,56 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
110
188
  type: import("@metamask/snaps-sdk").NodeType.Spinner;
111
189
  } | {
112
190
  value: string;
113
- type: import("@metamask/snaps-sdk").NodeType.Text; /**
114
- * The timeout in milliseconds to use for requests to the snap. Defaults to
115
- * `1000`.
116
- */
191
+ type: import("@metamask/snaps-sdk").NodeType.Text;
117
192
  markdown?: boolean | undefined;
193
+ } | {
194
+ value: string;
195
+ type: import("@metamask/snaps-sdk").NodeType.Address;
196
+ } | {
197
+ value: {
198
+ value: string;
199
+ type: import("@metamask/snaps-sdk").NodeType.Image;
200
+ } | {
201
+ value: string;
202
+ type: import("@metamask/snaps-sdk").NodeType.Text;
203
+ markdown?: boolean | undefined;
204
+ } | {
205
+ value: string;
206
+ type: import("@metamask/snaps-sdk").NodeType.Address;
207
+ };
208
+ type: import("@metamask/snaps-sdk").NodeType.Row;
209
+ label: string;
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
+ })[];
118
241
  } | undefined, null>;
119
242
  }>;
120
243
  export declare const SnapResponseStruct: import("superstruct").Struct<{
@@ -145,11 +268,56 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
145
268
  type: import("@metamask/snaps-sdk").NodeType.Spinner;
146
269
  } | {
147
270
  value: string;
148
- type: import("@metamask/snaps-sdk").NodeType.Text; /**
149
- * The timeout in milliseconds to use for requests to the snap. Defaults to
150
- * `1000`.
151
- */
271
+ type: import("@metamask/snaps-sdk").NodeType.Text;
152
272
  markdown?: boolean | undefined;
273
+ } | {
274
+ value: string;
275
+ type: import("@metamask/snaps-sdk").NodeType.Address;
276
+ } | {
277
+ value: {
278
+ value: string;
279
+ type: import("@metamask/snaps-sdk").NodeType.Image;
280
+ } | {
281
+ value: string;
282
+ type: import("@metamask/snaps-sdk").NodeType.Text;
283
+ markdown?: boolean | undefined;
284
+ } | {
285
+ value: string;
286
+ type: import("@metamask/snaps-sdk").NodeType.Address;
287
+ };
288
+ type: import("@metamask/snaps-sdk").NodeType.Row;
289
+ label: string;
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
+ })[];
153
321
  } | undefined;
154
322
  }, {
155
323
  id: import("superstruct").Struct<string, null>;
@@ -187,10 +355,55 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
187
355
  type: import("@metamask/snaps-sdk").NodeType.Spinner;
188
356
  } | {
189
357
  value: string;
190
- type: import("@metamask/snaps-sdk").NodeType.Text; /**
191
- * The timeout in milliseconds to use for requests to the snap. Defaults to
192
- * `1000`.
193
- */
358
+ type: import("@metamask/snaps-sdk").NodeType.Text;
194
359
  markdown?: boolean | undefined;
360
+ } | {
361
+ value: string;
362
+ type: import("@metamask/snaps-sdk").NodeType.Address;
363
+ } | {
364
+ value: {
365
+ value: string;
366
+ type: import("@metamask/snaps-sdk").NodeType.Image;
367
+ } | {
368
+ value: string;
369
+ type: import("@metamask/snaps-sdk").NodeType.Text;
370
+ markdown?: boolean | undefined;
371
+ } | {
372
+ value: string;
373
+ type: import("@metamask/snaps-sdk").NodeType.Address;
374
+ };
375
+ type: import("@metamask/snaps-sdk").NodeType.Row;
376
+ label: string;
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
+ })[];
195
408
  } | undefined, null>;
196
409
  }>;
@@ -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 {};
@@ -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 { Mock, MockJsonRpcOptions, MockOptions, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
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
- * Close the page running the snap. This is mainly useful for cleaning up
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 A promise that resolves when the page is closed.
247
+ * @returns The response.
217
248
  */
218
- close(): Promise<void>;
249
+ onHomePage(): Promise<SnapResponse>;
219
250
  /**
220
- * Enable network mocking for the snap.
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 options - The options for the network mocking.
223
- * @returns A {@link Mock} object, with an `unmock` function.
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(options: DeepPartial<MockOptions>): Promise<Mock>;
269
+ mockJsonRpc(mock: JsonRpcMockOptions): {
270
+ /**
271
+ * Remove the mock.
272
+ */
273
+ unmock(): void;
274
+ };
226
275
  /**
227
- * Enable JSON-RPC provider mocking for the snap. This will mock any requests
228
- * sent through the `ethereum` global, with the specified `method`.
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
- * @param options - The options for the JSON-RPC mocking.
231
- * @param options.method - The JSON-RPC method to mock, e.g.,
232
- * `eth_blockNumber`.
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
- mockJsonRpc(options: MockJsonRpcOptions): Promise<Mock>;
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": "4.0.0",
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/snaps-execution-environments": "^3.3.0",
40
- "@metamask/snaps-sdk": "^1.0.0",
41
- "@metamask/snaps-simulator": "^2.4.0",
42
- "@metamask/snaps-utils": "^4.0.0",
43
- "@metamask/utils": "^8.1.0",
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
- "pptr-testing-library": "^0.7.0",
48
- "puppeteer": "21.1.1",
49
- "superstruct": "^1.0.3",
50
- "webdriverio": "^8.19.0"
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
- "@lavamoat/allow-scripts": "^2.5.1",
54
- "@metamask/auto-changelog": "^3.4.3",
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",