Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new snap metadata #49

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
union,
optional,
Infer,
enums,
} from 'superstruct';

const VerifiedSnapVersionStruct = object({
Expand All @@ -21,6 +22,15 @@ export const VerifiedSnapStruct = object({
id: string(),
metadata: object({
name: string(),
type: optional(enums(['account'])),
author: optional(string()),
website: optional(string()),
summary: optional(string()),
FrederikBolding marked this conversation as resolved.
Show resolved Hide resolved
description: optional(string()),
audits: optional(array(string())),
tags: optional(array(string())),
danroc marked this conversation as resolved.
Show resolved Hide resolved
support: optional(string()),
sourceCode: optional(string()),
}),
versions: record(VersionStruct, VerifiedSnapVersionStruct),
});
Expand Down
108 changes: 108 additions & 0 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,112 @@ describe('Snaps Registry', () => {
it('has valid format', () => {
expect(() => assert(registry, SnapsRegistryDatabaseStruct)).not.toThrow();
});

it('has a valid account snap', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
type: 'account',
author: 'Example Author',
website: 'https://metamask.io',
summary: 'Example Snap',
description: 'Longer Example Snap description.',
audits: [
'https://metamask.io/example/report-1.pdf',
'https://metamask.io/example/report-2.pdf',
],
support: 'https://metamask.io/example/support',
sourceCode: 'https://metamask.io/example/source-code',
tags: ['accounts', 'example'],
},
versions: {
'0.1.0': {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
},
},
blockedSnaps: [
{
id: 'npm:example-blocked-snap',
versionRange: '^0.1.0',
reason: {
explanation: 'Example explanation',
url: 'https://metamask.io/example/explanation',
},
},
{
checksum: 'B3ar53ZIcKeKw3An3aqBeV4CAofj7jGK5hOAAxQY6A0=',
reason: {
explanation: 'Example explanation',
url: 'https://metamask.io/example/explanation',
},
},
],
};
/* eslint-enable @typescript-eslint/naming-convention */

expect(() => assert(registryDb, SnapsRegistryDatabaseStruct)).not.toThrow();
});

it('has a only mandatory fields', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
},
versions: {
'0.1.0': {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
},
},
blockedSnaps: [
{
id: 'npm:example-blocked-snap',
versionRange: '^0.1.0',
},
{
checksum: 'B3ar53ZIcKeKw3An3aqBeV4CAofj7jGK5hOAAxQY6A0=',
},
],
};
/* eslint-enable @typescript-eslint/naming-convention */

expect(() => assert(registryDb, SnapsRegistryDatabaseStruct)).not.toThrow();
});

it('should throw when the metadata has an unexpected field', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
unexpected: 'field',
},
versions: {
'0.1.0': {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
},
},
blockedSnaps: [],
};
/* eslint-enable @typescript-eslint/naming-convention */

expect(() => assert(registryDb, SnapsRegistryDatabaseStruct)).toThrow(
'At path: verifiedSnaps.npm:example-snap.metadata.unexpected -- Expected a value of type `never`, but received: `"field"`',
);
});
});