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

fix: remove limits depending on space turbo status #1115

Merged
merged 3 commits into from
Feb 5, 2025
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
12 changes: 2 additions & 10 deletions src/schemas/proposal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
"body": {
"type": "string",
"title": "body",
"minLength": 0,
"maxLengthWithSpaceType": {
"default": 10000,
"turbo": 40000
}
"minLength": 0
},
"discussion": {
"type": "string",
Expand All @@ -30,11 +26,7 @@
"choices": {
"type": "array",
"title": "choices",
"minItems": 1,
"maxLengthWithSpaceType": {
"default": 500,
"turbo": 1000
}
"minItems": 1
},
"labels": {
"type": "array",
Expand Down
4 changes: 0 additions & 4 deletions src/schemas/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@
"strategies": {
"type": "array",
"minItems": 1,
"maxItemsWithSpaceType": {
"default": 8,
"turbo": 10
},
"uniqueItems": true,
"items": {
"type": "object",
Expand Down
12 changes: 2 additions & 10 deletions src/schemas/update-proposal.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
"body": {
"type": "string",
"title": "body",
"minLength": 0,
"maxLengthWithSpaceType": {
"default": 10000,
"turbo": 20000
}
"minLength": 0
},
"discussion": {
"type": "string",
Expand All @@ -34,11 +30,7 @@
"choices": {
"type": "array",
"title": "choices",
"minItems": 1,
"maxLengthWithSpaceType": {
"default": 500,
"turbo": 1000
}
"minItems": 1
},
"labels": {
"type": "array",
Expand Down
42 changes: 0 additions & 42 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,48 +194,6 @@ ajv.addKeyword({
}
});

ajv.addKeyword({
keyword: 'maxLengthWithSpaceType',
validate: function validate(schema, data) {
// @ts-ignore
const spaceType = this.spaceType || 'default';
const isValid = data.length <= schema[spaceType];
if (!isValid) {
// @ts-ignore
validate.errors = [
{
keyword: 'maxLengthWithSpaceType',
message: `must not have more than ${schema[spaceType]}`,
params: { limit: schema[spaceType] }
}
];
}
return isValid;
},
errors: true
});

ajv.addKeyword({
keyword: 'maxItemsWithSpaceType',
validate: function validate(schema, data) {
// @ts-ignore
const spaceType = this.spaceType || 'default';
const isValid = data.length <= schema[spaceType];
if (!isValid) {
// @ts-ignore
validate.errors = [
{
keyword: 'maxItemsWithSpaceType',
message: `must NOT have more than ${schema[spaceType]} items`,
params: { limit: schema[spaceType] }
}
];
}
return isValid;
},
errors: true
});

// Custom URL format to allow empty string values
// https://github.com/snapshot-labs/snapshot.js/pull/541/files
ajv.addFormat('customUrl', {
Expand Down
20 changes: 0 additions & 20 deletions test/examples/proposal-maxLengthWithSpaceType-error.json

This file was deleted.

11 changes: 0 additions & 11 deletions test/examples/space-maxItemsWithSpaceType-error.json

This file was deleted.

28 changes: 0 additions & 28 deletions test/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import profile from './examples/profile.json';
import statement from './examples/statement.json';
import alias from './examples/alias.json';
import schemas from '../src/schemas';
import proposalMaxLengthWithSpaceTypeError from './examples/proposal-maxLengthWithSpaceType-error.json';
import spaceMaxItemsWithSpaceTypeError from './examples/space-maxItemsWithSpaceType-error.json';

// Tests for default spaces
describe.each([
Expand Down Expand Up @@ -49,29 +47,3 @@ describe.each([
expect(isValid).toBe(true);
});
});

// tests for default schema with turbo example, should fail
describe.each([
{
schemaType: 'space',
schema: schemas.space,
example: spaceTurbo,
error: spaceMaxItemsWithSpaceTypeError
},
{
schemaType: 'proposal',
schema: schemas.proposal,
example: proposalTurbo,
error: proposalMaxLengthWithSpaceTypeError
}
])(
`Run validate for default schema with turbo example`,
({ schemaType, schema, example, error }) => {
test(`validating schema ${schemaType} should fail with error`, () => {
const isValid = validateSchema(schema, example, {
snapshotEnv: 'mainnet'
});
expect(isValid).toMatchObject(error);
});
}
);