Skip to content

Commit 1b243bb

Browse files
authored
feat: Add limits for voting delay and period (#961)
* feat: Add limits for voting delay and period * fix * Update test/examples/space.json * Update src/schemas/space.json * v0.11.1 * Update src/schemas/space.json * Update test/examples/space.json
1 parent 9bd48e9 commit 1b243bb

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.11.0",
3+
"version": "0.11.1",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",
@@ -18,6 +18,7 @@
1818
"@ethersproject/units": "^5.7.0",
1919
"@ethersproject/wallet": "^5.6.2",
2020
"ajv": "^8.11.0",
21+
"ajv-errors": "^3.0.0",
2122
"ajv-formats": "^2.1.1",
2223
"cross-fetch": "^3.1.6",
2324
"json-to-graphql-query": "^2.2.4",

src/schemas/space.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,19 @@
282282
"properties": {
283283
"delay": {
284284
"type": "integer",
285-
"minimum": 0
285+
"minimum": 0,
286+
"maximum": 2592000,
287+
"errorMessage": {
288+
"maximum": "Delay must be less than 30 days"
289+
}
286290
},
287291
"period": {
288292
"type": "integer",
289-
"minimum": 0
293+
"minimum": 0,
294+
"maximum": 15552000,
295+
"errorMessage": {
296+
"maximum": "Delay must be less than 180 days"
297+
}
290298
},
291299
"type": {
292300
"type": "string",

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { namehash, ensNormalize } from '@ethersproject/hash';
77
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
88
import Ajv from 'ajv';
99
import addFormats from 'ajv-formats';
10+
import addErrors from 'ajv-errors';
1011
import Multicaller from './utils/multicaller';
1112
import { getSnapshots } from './utils/blockfinder';
1213
import getProvider from './utils/provider';
@@ -45,6 +46,7 @@ const ajv = new Ajv({
4546
});
4647
// @ts-ignore
4748
addFormats(ajv);
49+
addErrors(ajv);
4850

4951
ajv.addFormat('address', {
5052
validate: (value: string) => {

test/examples/space.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@
2828
"validation": {
2929
"name": "basic",
3030
"params": {}
31+
},
32+
"voting":{
33+
"delay": 2592000,
34+
"period": 15552000
3135
}
3236
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,11 @@ aggregate-error@^3.0.0:
11471147
clean-stack "^2.0.0"
11481148
indent-string "^4.0.0"
11491149

1150+
ajv-errors@^3.0.0:
1151+
version "3.0.0"
1152+
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-3.0.0.tgz#e54f299f3a3d30fe144161e5f0d8d51196c527bc"
1153+
integrity sha512-V3wD15YHfHz6y0KdhYFjyy9vWtEVALT9UrxfN3zqlI6dMioHnJrqOYfyPKol3oqrnCM9uwkcdCwkJ0WUcbLMTQ==
1154+
11501155
ajv-formats@^2.1.1:
11511156
version "2.1.1"
11521157
resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-2.1.1.tgz#6e669400659eb74973bbf2e33327180a0996b520"

0 commit comments

Comments
 (0)