1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00
metamask-extension/app/scripts/migrations/081.test.js
Hassan Malik 7086494b72
[FLASK] BREAKING - snaps-monorepo@0.30.0 (#17718)
* updated snap permission to wallet_snap, updated tests and added migration

* updated snap packages

* yarn.lock fix

* fixed errors

* override policy

* update policy

* undo override

* updated localization message descriptions

* updated lavamoat policy

* more policy updates

* update permission controller version

* update policy

* update fixture builder

* updated code to include permission value to satisfy wallet_snap permission description call

* fix import issue

* update test-snaps version

* added missing actions, added snap permission dedupe function

* prettier fix

* fix fencing

* add more fencing

* prettier fix

* fix fencing (again)

* added new action and selector and updated view snap accordingly

* update test snaps website version

* unfence request variable

* add fencing

* add optional chaining to fix type error

* update migration #

* remove old migration

* prettier fix

* fix migration test

* fix fencing

* added missing fencing

* updated code to workaround fencing

* update test-snaps site version and remove snap confirm test

* update snap packages

* update policies

* fix merge marker issue

* update test

* more fixes

* fix permissions

* update test

* fixed test

* Bump test-snaps and iframe-execution-environment

* remove unused snap permission from fixture builder

* update policies

* undo comment removal, update selector implementation

* removed unnecessary function, updated migration, updated caveat action

* remove optional chaining

* fix type issue

* more type fixes

* fix migration test

* remove isFlask check, make migration logic more robust

* update coverage

* Update LavaMoat policies

* Update test/e2e/snaps/enums.js

* add extra bail condition

* Revert "add extra bail condition"

This reverts commit b45c53dcfc6e6e35a5e283d4955d6d6ea9ca5965.

* Revert "Revert "add extra bail condition""

This reverts commit cd2ded677935c9cdab0c02b6af55474c83727f60.

* fix test

* add SnapController entry to state object

* updated permission name and caveat type with hardcoded values

* add extra test for non-flask scenario

* update lavamoat policies

* fix locale messages

* change coverage target

* re-enable rpc snap test

* revert locale message change

* fix el message

* reverted changes

---------

Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
2023-03-08 13:29:23 -05:00

163 lines
4.5 KiB
JavaScript

import { migrate, version as newVersion } from './081';
describe('migration #81', () => {
it('should consolidate snap permissions as caveats under the wallet_snap permission', async () => {
const oldStorage = {
meta: {
version: 80,
},
data: {
SnapController: {},
PermissionController: {
subjects: {
'example.com': {
permissions: {
'wallet_snap_npm:foobar': {
caveats: null,
date: 2,
id: 'a7342F4b-beae-4525-a36c-c0635fd03359',
invoker: 'example.com',
parentCapability: 'wallet_snap_npm:foobar',
},
'wallet_snap_npm:baz': {
caveats: null,
date: 3,
id: 'x342A44-beae-4525-a36c-c0635fd03359',
invoker: 'example.com',
parentCapability: 'wallet_snap_npm:baz',
},
},
},
'aave.com': {
permissions: {
'wallet_snap_npm:filsnap': {
caveats: null,
date: 10,
id: 'a7342F4b-beae-4525-a36c-c0635fd03359',
invoker: 'aave.com',
parentCapability: 'wallet_snap_npm:foobar',
},
'wallet_snap_npm:btcsnap': {
caveats: null,
date: 3,
id: 'x342A44-beae-4525-a36c-c0635fd03359',
invoker: 'aave.com',
parentCapability: 'wallet_snap_npm:btcsnap',
},
},
},
},
},
},
};
const newStorage = await migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: { version: newVersion },
data: {
SnapController: {},
PermissionController: {
subjects: {
'example.com': {
permissions: {
wallet_snap: {
caveats: [
{
type: 'snapIds',
value: {
'npm:foobar': {},
'npm:baz': {},
},
},
],
date: 3,
id: 'x342A44-beae-4525-a36c-c0635fd03359',
invoker: 'example.com',
parentCapability: 'wallet_snap',
},
},
},
'aave.com': {
permissions: {
wallet_snap: {
caveats: [
{
type: 'snapIds',
value: {
'npm:btcsnap': {},
'npm:filsnap': {},
},
},
],
date: 10,
id: 'a7342F4b-beae-4525-a36c-c0635fd03359',
invoker: 'aave.com',
parentCapability: 'wallet_snap',
},
},
},
},
},
},
});
});
it('should leave state unchanged if there are no snap permissions', async () => {
const oldStorage = {
meta: {
version: 80,
},
data: {
SnapController: {},
PermissionController: {
subjects: {
'example.com': {
permissions: {
eth_accounts: {
date: 2,
id: 'a7342F4b-beae-4525-a36c-c0635fd03359',
invoker: 'example.com',
parentCapability: 'eth_accounts',
},
},
},
},
},
},
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
it('should leave state unchanged if there is no SnapController installed (i.e. not a flask build)', async () => {
const oldStorage = {
meta: {
version: 80,
},
data: {
PermissionController: {
subjects: {
'example.com': {
permissions: {
eth_accounts: {
date: 2,
id: 'a7342F4b-beae-4525-a36c-c0635fd03359',
invoker: 'example.com',
parentCapability: 'eth_accounts',
},
},
},
},
},
},
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
});