Skip to content

Commit

Permalink
fix: remove limits depending on space turbo status (#1115)
Browse files Browse the repository at this point in the history
Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
wa0x6e and ChaituVR authored Feb 5, 2025
1 parent d36e85f commit 4b15afc
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 125 deletions.
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);
});
}
);

0 comments on commit 4b15afc

Please sign in to comment.