Skip to content

Commit

Permalink
Delete unencrypted state when uninstalling a Snap (#2311)
Browse files Browse the repository at this point in the history
Unencrypted state is currently not deleted when uninstalling a Snap.
I've fixed this, and also added a test to check this behaviour.
  • Loading branch information
Mrtenz authored Apr 3, 2024
1 parent e93693f commit 85422bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/snaps-controllers/src/snaps/SnapController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6792,6 +6792,30 @@ describe('SnapController', () => {

snapController.destroy();
});

it('removes snap state', async () => {
const messenger = getSnapControllerMessenger();
const snapController = getSnapController(
getSnapControllerOptions({
messenger,
state: {
snaps: getPersistedSnapsState(),
snapStates: {
[MOCK_SNAP_ID]: 'foo',
},
unencryptedSnapStates: {
[MOCK_SNAP_ID]: 'bar',
},
},
}),
);

await snapController.removeSnap(MOCK_SNAP_ID);
expect(snapController.state.snapStates).toStrictEqual({});
expect(snapController.state.unencryptedSnapStates).toStrictEqual({});

snapController.destroy();
});
});

describe('enableSnap', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,7 @@ export class SnapController extends BaseController<
this.update((state: any) => {
delete state.snaps[snapId];
delete state.snapStates[snapId];
delete state.unencryptedSnapStates[snapId];
});

// If the snap has been fully installed before, also emit snapUninstalled.
Expand Down

0 comments on commit 85422bc

Please sign in to comment.