Skip to content

Commit 4220cac

Browse files
authored
feat: labels on proposals (#1065)
* feat: labels on proposals * remove unwanted log * add more condtions for labels like max length and pattern * fix update proposal * v0.12.20
1 parent 8bf3023 commit 4220cac

File tree

7 files changed

+70
-2
lines changed

7 files changed

+70
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.12.19",
3+
"version": "0.12.20",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/schemas/proposal.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
"turbo": 1000
3737
}
3838
},
39+
"labels": {
40+
"type": "array",
41+
"title": "labels",
42+
"maxItems": 10,
43+
"uniqueItems": true,
44+
"items": {
45+
"type": "string",
46+
"minLength": 1,
47+
"maxLength": 8,
48+
"pattern": "^[a-zA-Z0-9]+$"
49+
}
50+
},
3951
"type": {
4052
"type": "string",
4153
"enum": [

src/schemas/update-proposal.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
"turbo": 1000
4141
}
4242
},
43+
"labels": {
44+
"type": "array",
45+
"title": "labels",
46+
"maxItems": 10,
47+
"uniqueItems": true,
48+
"items": {
49+
"type": "string",
50+
"minLength": 1,
51+
"maxLength": 8,
52+
"pattern": "^[a-zA-Z0-9]+$"
53+
}
54+
},
4355
"type": {
4456
"enum": [
4557
"single-choice",

src/sign/hashedTypes.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@
6060
"42f8858a21d4aa232721cb97074851e729829ea362b88bb21f3879899663b586": "follow",
6161
"2bb75450e28b06f259ea764cd669de6bde0ba70ce729b0ff05ab9df56e0ff21d": "unfollow",
6262
"2ffbebcbd22ef48fd2f4a1182ff1feda7795b57689bd6f0dd73c89e925e7fefb": "profile",
63-
"4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement"
63+
"4288d50b713081aae77d60d596d75864bff7acf7791a00183401e58658ee9da5": "statement",
64+
"d56782e3b50ac86c25ae292923da8c367e3c9e8e7ea9d8baa435051fe2f430fa": "proposal",
65+
"df10a7eeabe19301d6018be8b6c5d13231320d7ece64d021043fa172b64f3796": "update-proposal"
6466
}

src/sign/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface Proposal {
2222
body: string;
2323
discussion: string;
2424
choices: string[];
25+
labels?: string[];
2526
start: number;
2627
end: number;
2728
snapshot: number;
@@ -39,6 +40,7 @@ export interface UpdateProposal {
3940
body: string;
4041
discussion: string;
4142
choices: string[];
43+
labels?: string[];
4244
plugins: string;
4345
}
4446

@@ -143,6 +145,7 @@ export const proposalTypes = {
143145
{ name: 'body', type: 'string' },
144146
{ name: 'discussion', type: 'string' },
145147
{ name: 'choices', type: 'string[]' },
148+
{ name: 'labels', type: 'string[]' },
146149
{ name: 'start', type: 'uint64' },
147150
{ name: 'end', type: 'uint64' },
148151
{ name: 'snapshot', type: 'uint64' },
@@ -162,6 +165,7 @@ export const updateProposalTypes = {
162165
{ name: 'body', type: 'string' },
163166
{ name: 'discussion', type: 'string' },
164167
{ name: 'choices', type: 'string[]' },
168+
{ name: 'labels', type: 'string[]' },
165169
{ name: 'plugins', type: 'string' }
166170
]
167171
};

test/e2e/sign/index.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, test } from 'vitest';
2+
const { createHash } = require('crypto');
3+
import * as types from '../../../src/sign/types';
4+
import hashedTypes from '../../../src/sign/hashedTypes.json';
5+
import kebabCase from 'lodash/kebabCase';
6+
7+
function sha256(str) {
8+
return createHash('sha256').update(str).digest('hex');
9+
}
10+
describe('sign types', () => {
11+
Object.keys(types).forEach((key) => {
12+
test(`hashed type should contain with type ${key}`, () => {
13+
const hash = sha256(JSON.stringify(types[key]));
14+
expect(hash).toBeTruthy();
15+
const derivedKey = kebabCase(
16+
key
17+
.replace('2Types', '')
18+
.replace('Types', '')
19+
.replace('Type', '')
20+
.replace('space', 'settings')
21+
.replace('cancel', 'delete')
22+
);
23+
try {
24+
expect(hashedTypes[hash]).toBe(derivedKey);
25+
} catch (error) {
26+
throw new Error(
27+
`Hash ${hash} does not match the derived key ${derivedKey}`
28+
);
29+
}
30+
});
31+
});
32+
});

test/examples/proposal.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"Add 20,000 $YAM to Gen Exp Fund",
66
"Do not add $YAM"
77
],
8+
"labels": [
9+
"12345678",
10+
"12a4b678",
11+
"abcdefgh",
12+
"a1b2c3d4"
13+
],
814
"start": 1619884800,
915
"end": 1620316800,
1016
"snapshot": 12345167,

0 commit comments

Comments
 (0)