diff --git a/package.json b/package.json index 298ce46ae..0abc676ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@snapshot-labs/snapshot.js", - "version": "0.12.19", + "version": "0.12.20", "repository": "snapshot-labs/snapshot.js", "license": "MIT", "main": "dist/snapshot.cjs.js", diff --git a/src/schemas/proposal.json b/src/schemas/proposal.json index b4dc7af70..8a0fb9421 100644 --- a/src/schemas/proposal.json +++ b/src/schemas/proposal.json @@ -36,6 +36,18 @@ "turbo": 1000 } }, + "labels": { + "type": "array", + "title": "labels", + "maxItems": 10, + "uniqueItems": true, + "items": { + "type": "string", + "minLength": 1, + "maxLength": 8, + "pattern": "^[a-zA-Z0-9]+$" + } + }, "type": { "type": "string", "enum": [ diff --git a/src/schemas/update-proposal.json b/src/schemas/update-proposal.json index 86a738fab..41becd41e 100644 --- a/src/schemas/update-proposal.json +++ b/src/schemas/update-proposal.json @@ -40,6 +40,18 @@ "turbo": 1000 } }, + "labels": { + "type": "array", + "title": "labels", + "maxItems": 10, + "uniqueItems": true, + "items": { + "type": "string", + "minLength": 1, + "maxLength": 8, + "pattern": "^[a-zA-Z0-9]+$" + } + }, "type": { "enum": [ "single-choice", diff --git a/src/sign/hashedTypes.json b/src/sign/hashedTypes.json index 2db4449bb..039741d3b 100644 --- a/src/sign/hashedTypes.json +++ b/src/sign/hashedTypes.json @@ -60,5 +60,7 @@ "42f8858a21d4aa232721cb97074851e729829ea362b88bb21f3879899663b586": "follow", "2bb75450e28b06f259ea764cd669de6bde0ba70ce729b0ff05ab9df56e0ff21d": "unfollow", "2ffbebcbd22ef48fd2f4a1182ff1feda7795b57689bd6f0dd73c89e925e7fefb": "profile", - "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement" + "4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement", + "d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal", + "df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal" } diff --git a/src/sign/types.ts b/src/sign/types.ts index bb0986919..6979d8e6c 100644 --- a/src/sign/types.ts +++ b/src/sign/types.ts @@ -22,6 +22,7 @@ export interface Proposal { body: string; discussion: string; choices: string[]; + labels?: string[]; start: number; end: number; snapshot: number; @@ -39,6 +40,7 @@ export interface UpdateProposal { body: string; discussion: string; choices: string[]; + labels?: string[]; plugins: string; } @@ -143,6 +145,7 @@ export const proposalTypes = { { name: 'body', type: 'string' }, { name: 'discussion', type: 'string' }, { name: 'choices', type: 'string[]' }, + { name: 'labels', type: 'string[]' }, { name: 'start', type: 'uint64' }, { name: 'end', type: 'uint64' }, { name: 'snapshot', type: 'uint64' }, @@ -162,6 +165,7 @@ export const updateProposalTypes = { { name: 'body', type: 'string' }, { name: 'discussion', type: 'string' }, { name: 'choices', type: 'string[]' }, + { name: 'labels', type: 'string[]' }, { name: 'plugins', type: 'string' } ] }; diff --git a/test/e2e/sign/index.spec.ts b/test/e2e/sign/index.spec.ts new file mode 100644 index 000000000..2d3989d08 --- /dev/null +++ b/test/e2e/sign/index.spec.ts @@ -0,0 +1,32 @@ +import { describe, expect, test } from 'vitest'; +const { createHash } = require('crypto'); +import * as types from '../../../src/sign/types'; +import hashedTypes from '../../../src/sign/hashedTypes.json'; +import kebabCase from 'lodash/kebabCase'; + +function sha256(str) { + return createHash('sha256').update(str).digest('hex'); +} +describe('sign types', () => { + Object.keys(types).forEach((key) => { + test(`hashed type should contain with type ${key}`, () => { + const hash = sha256(JSON.stringify(types[key])); + expect(hash).toBeTruthy(); + const derivedKey = kebabCase( + key + .replace('2Types', '') + .replace('Types', '') + .replace('Type', '') + .replace('space', 'settings') + .replace('cancel', 'delete') + ); + try { + expect(hashedTypes[hash]).toBe(derivedKey); + } catch (error) { + throw new Error( + `Hash ${hash} does not match the derived key ${derivedKey}` + ); + } + }); + }); +}); diff --git a/test/examples/proposal.json b/test/examples/proposal.json index fdc059de6..a28ad8794 100644 --- a/test/examples/proposal.json +++ b/test/examples/proposal.json @@ -5,6 +5,12 @@ "Add 20,000 $YAM to Gen Exp Fund", "Do not add $YAM" ], + "labels": [ + "12345678", + "12a4b678", + "abcdefgh", + "a1b2c3d4" + ], "start": 1619884800, "end": 1620316800, "snapshot": 12345167,