Skip to content

Commit 751d49c

Browse files
Add test
1 parent ec7bdda commit 751d49c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/snaps-controllers/src/snaps/registry/json.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,27 @@ describe('JsonSnapsRegistry', () => {
617617
expect(fetchMock).toHaveBeenCalledTimes(2);
618618
});
619619

620+
it('skips update if the signature matches the existing one', async () => {
621+
const spy = jest.spyOn(globalThis.crypto.subtle, 'digest');
622+
623+
fetchMock
624+
.mockResponseOnce(JSON.stringify(MOCK_DATABASE))
625+
.mockResponseOnce(JSON.stringify(MOCK_SIGNATURE_FILE));
626+
627+
const { messenger } = getRegistry({
628+
state: {
629+
database: MOCK_DATABASE,
630+
signature: MOCK_SIGNATURE,
631+
lastUpdated: 0,
632+
databaseUnavailable: false,
633+
},
634+
});
635+
await messenger.call('SnapsRegistry:update');
636+
637+
expect(fetchMock).toHaveBeenCalledTimes(2);
638+
expect(spy).not.toHaveBeenCalled();
639+
});
640+
620641
it('does not fetch if a second call is made under the threshold', async () => {
621642
fetchMock
622643
.mockResponseOnce(JSON.stringify(MOCK_DATABASE))

packages/snaps-controllers/src/snaps/registry/json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export class JsonSnapsRegistry extends BaseController<
273273
state.database = JSON.parse(database);
274274
state.lastUpdated = Date.now();
275275
state.databaseUnavailable = false;
276+
state.signature = signatureJson.signature;
276277
});
277278
} catch {
278279
// Ignore

0 commit comments

Comments
 (0)