1
- import { migrate , version } from './126' ;
2
1
import { SnapEndowments } from '@metamask/snaps-rpc-methods' ;
3
2
import { CaveatFactories , PermissionNames } from '../controllers/permissions' ;
4
- import { CaveatTypes } from '../../../shared/constants/permissions.ts' ;
5
- import { CHAIN_IDS , NETWORK_TYPES } from '../../../shared/constants/network.ts' ;
3
+ import { CaveatTypes } from '../../../shared/constants/permissions' ;
4
+ import { CHAIN_IDS , NETWORK_TYPES } from '../../../shared/constants/network' ;
5
+ import { migrate , version } from './126' ;
6
6
7
7
const oldVersion = 125 ;
8
8
const newVersion = 126 ;
@@ -13,7 +13,10 @@ const MOCK_SNAP_ID = 'npm:foo-snap';
13
13
jest . useFakeTimers ( ) ;
14
14
jest . setSystemTime ( 1723635247705 ) ;
15
15
16
- function getMockState ( selectedNetworkClientId : string = NETWORK_TYPES . MAINNET , networkConfigurations = { } ) {
16
+ function getMockState (
17
+ selectedNetworkClientId : string = NETWORK_TYPES . MAINNET ,
18
+ networkConfigurations = { } ,
19
+ ) {
17
20
return {
18
21
meta : { version : oldVersion } ,
19
22
data : {
@@ -35,12 +38,12 @@ function getMockState(selectedNetworkClientId: string = NETWORK_TYPES.MAINNET, n
35
38
} ,
36
39
} ,
37
40
} ,
38
- }
41
+ } ,
39
42
} ,
40
43
41
44
SelectedNetworkController : {
42
- domains : { }
43
- }
45
+ domains : { } ,
46
+ } ,
44
47
} ,
45
48
} ;
46
49
}
@@ -75,24 +78,24 @@ describe('migration #126', () => {
75
78
} ,
76
79
[ PermissionNames . permittedChains ] : {
77
80
caveats : [
78
- CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] (
79
- [ CHAIN_IDS . MAINNET ] ,
80
- )
81
+ CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] ( [
82
+ CHAIN_IDS . MAINNET ,
83
+ ] ) ,
81
84
] ,
82
85
date : 1723635247705 ,
83
86
id : expect . any ( String ) ,
84
87
invoker : MOCK_SNAP_ID ,
85
88
parentCapability : PermissionNames . permittedChains ,
86
- }
89
+ } ,
87
90
} ,
88
91
} ,
89
- }
92
+ } ,
90
93
} ) ;
91
94
92
95
expect ( newStorage . data . SelectedNetworkController ) . toStrictEqual ( {
93
96
domains : {
94
- [ MOCK_SNAP_ID ] : NETWORK_TYPES . MAINNET
95
- }
97
+ [ MOCK_SNAP_ID ] : NETWORK_TYPES . MAINNET ,
98
+ } ,
96
99
} ) ;
97
100
} ) ;
98
101
@@ -113,24 +116,24 @@ describe('migration #126', () => {
113
116
} ,
114
117
[ PermissionNames . permittedChains ] : {
115
118
caveats : [
116
- CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] (
117
- [ CHAIN_IDS . SEPOLIA ] ,
118
- )
119
+ CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] ( [
120
+ CHAIN_IDS . SEPOLIA ,
121
+ ] ) ,
119
122
] ,
120
123
date : 1723635247705 ,
121
124
id : expect . any ( String ) ,
122
125
invoker : MOCK_SNAP_ID ,
123
126
parentCapability : PermissionNames . permittedChains ,
124
- }
127
+ } ,
125
128
} ,
126
129
} ,
127
- }
130
+ } ,
128
131
} ) ;
129
132
130
133
expect ( newStorage . data . SelectedNetworkController ) . toStrictEqual ( {
131
134
domains : {
132
- [ MOCK_SNAP_ID ] : NETWORK_TYPES . SEPOLIA
133
- }
135
+ [ MOCK_SNAP_ID ] : NETWORK_TYPES . SEPOLIA ,
136
+ } ,
134
137
} ) ;
135
138
} ) ;
136
139
@@ -142,6 +145,8 @@ describe('migration #126', () => {
142
145
} ) ;
143
146
144
147
const newStorage = await migrate ( oldStorage ) ;
148
+ console . log ( JSON . stringify ( newStorage . data . PermissionController , null , 2 ) ) ;
149
+
145
150
expect ( newStorage . data . PermissionController ) . toStrictEqual ( {
146
151
subjects : {
147
152
[ MOCK_SNAP_ID ] : {
@@ -155,24 +160,24 @@ describe('migration #126', () => {
155
160
} ,
156
161
[ PermissionNames . permittedChains ] : {
157
162
caveats : [
158
- CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] (
159
- [ CHAIN_IDS . LINEA_SEPOLIA ] ,
160
- )
163
+ CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] ( [
164
+ CHAIN_IDS . LINEA_SEPOLIA ,
165
+ ] ) ,
161
166
] ,
162
167
date : 1723635247705 ,
163
168
id : expect . any ( String ) ,
164
169
invoker : MOCK_SNAP_ID ,
165
170
parentCapability : PermissionNames . permittedChains ,
166
- }
171
+ } ,
167
172
} ,
168
173
} ,
169
- }
174
+ } ,
170
175
} ) ;
171
176
172
177
expect ( newStorage . data . SelectedNetworkController ) . toStrictEqual ( {
173
178
domains : {
174
- [ MOCK_SNAP_ID ] : NETWORK_TYPES . SEPOLIA
175
- }
179
+ [ MOCK_SNAP_ID ] : NETWORK_TYPES . SEPOLIA ,
180
+ } ,
176
181
} ) ;
177
182
} ) ;
178
183
@@ -194,21 +199,21 @@ describe('migration #126', () => {
194
199
} ,
195
200
[ PermissionNames . permittedChains ] : {
196
201
caveats : [
197
- CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] (
198
- [ CHAIN_IDS . SEPOLIA ] ,
199
- )
202
+ CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] ( [
203
+ CHAIN_IDS . SEPOLIA ,
204
+ ] ) ,
200
205
] ,
201
206
date : 1723635247705 ,
202
207
id : expect . any ( String ) ,
203
208
invoker : MOCK_SNAP_ID ,
204
209
parentCapability : PermissionNames . permittedChains ,
205
- }
210
+ } ,
206
211
} ,
207
212
} ,
208
- }
213
+ } ,
209
214
} ,
210
215
selectedNetworkControllerState : {
211
- domains : { }
216
+ domains : { } ,
212
217
} ,
213
218
} ,
214
219
{
@@ -217,7 +222,7 @@ describe('migration #126', () => {
217
222
} ,
218
223
permissionControllerState : [ ] ,
219
224
selectedNetworkControllerState : {
220
- domains : { }
225
+ domains : { } ,
221
226
} ,
222
227
} ,
223
228
{
@@ -237,18 +242,18 @@ describe('migration #126', () => {
237
242
} ,
238
243
[ PermissionNames . permittedChains ] : {
239
244
caveats : [
240
- CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] (
241
- [ CHAIN_IDS . SEPOLIA ] ,
242
- )
245
+ CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] ( [
246
+ CHAIN_IDS . SEPOLIA ,
247
+ ] ) ,
243
248
] ,
244
249
date : 1723635247705 ,
245
250
id : expect . any ( String ) ,
246
251
invoker : MOCK_SNAP_ID ,
247
252
parentCapability : PermissionNames . permittedChains ,
248
- }
253
+ } ,
249
254
} ,
250
255
} ,
251
- }
256
+ } ,
252
257
} ,
253
258
selectedNetworkControllerState : [ ] ,
254
259
} ,
@@ -269,33 +274,36 @@ describe('migration #126', () => {
269
274
} ,
270
275
[ PermissionNames . permittedChains ] : {
271
276
caveats : [
272
- CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] (
273
- [ CHAIN_IDS . SEPOLIA ] ,
274
- )
277
+ CaveatFactories [ CaveatTypes . restrictNetworkSwitching ] ( [
278
+ CHAIN_IDS . SEPOLIA ,
279
+ ] ) ,
275
280
] ,
276
281
date : 1723635247705 ,
277
282
id : expect . any ( String ) ,
278
283
invoker : MOCK_SNAP_ID ,
279
284
parentCapability : PermissionNames . permittedChains ,
280
- }
285
+ } ,
281
286
} ,
282
287
} ,
283
- }
288
+ } ,
284
289
} ,
285
290
selectedNetworkControllerState : {
286
- domains : { }
291
+ domains : { } ,
287
292
} ,
288
293
} ,
289
- ] ) ( 'does not update the state if the state is invalid (#%#)' , async ( data : Record < string , unknown > ) => {
290
- const oldStorage = {
291
- meta : { version : oldVersion } ,
292
- data,
293
- } ;
294
+ ] ) (
295
+ 'does not update the state if the state is invalid (#%#)' ,
296
+ async ( data : Record < string , unknown > ) => {
297
+ const oldStorage = {
298
+ meta : { version : oldVersion } ,
299
+ data,
300
+ } ;
294
301
295
- const newStorage = await migrate ( oldStorage ) ;
296
- expect ( newStorage ) . toStrictEqual ( {
297
- meta : { version : newVersion } ,
298
- data
299
- } ) ;
300
- } )
302
+ const newStorage = await migrate ( oldStorage ) ;
303
+ expect ( newStorage ) . toStrictEqual ( {
304
+ meta : { version : newVersion } ,
305
+ data,
306
+ } ) ;
307
+ } ,
308
+ ) ;
301
309
} ) ;
0 commit comments