Skip to content

Commit

Permalink
add capped characters validation for description
Browse files Browse the repository at this point in the history
  • Loading branch information
Manh Cao committed Nov 25, 2024
1 parent ffc1884 commit 9acb8c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions const.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// categories need to be lowercase strings
const PROTOCOL_CATEGORIES = ['money market', 'yield strategy', 'liquid locker', 'others'];

const DESCRIPTION_MAXIMUM_CHARACTERS = 120;

module.exports = {
PROTOCOL_CATEGORIES,
DESCRIPTION_MAXIMUM_CHARACTERS,
}
18 changes: 14 additions & 4 deletions validate-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const {PROTOCOL_CATEGORIES} = require("./const");
const {PROTOCOL_CATEGORIES, DESCRIPTION_MAXIMUM_CHARACTERS} = require("./const");

const LIMIT_ICON_KB_SIZE = 20;
const BUFFER_LIMIT_ICON_KB_SIZE = LIMIT_ICON_KB_SIZE + 1;
Expand All @@ -22,6 +22,18 @@ function validateCategory(protocol, category) {
}
}

function validateDescription(info) {
const {protocol, field, index, description} = info;

if (!mustBeNonEmptyString(description)) {
throw new Error(`protocol ${protocol}: metadata ${field} invalid 'description' field at index ${index}`);
}

if (description.length > DESCRIPTION_MAXIMUM_CHARACTERS) {
throw new Error(`protocol ${protocol}: metadata ${field} 'description' too long at index ${index}`);
}
}

async function main() {
const CHANGED_PROTOCOLS = process.env.CHANGED_PROTOCOLS;
const GET_ASSET_LIST_URL = process.env.GET_ASSET_LIST_URL;
Expand Down Expand Up @@ -157,9 +169,7 @@ function checkMetadataField(data, protocol, field, assetMap) {
throw new Error(`protocol ${protocol}: metadata ${field} address not found in pendle ${field} list at index ${index}`);
}

if (!mustBeNonEmptyString(description)) {
throw new Error(`protocol ${protocol}: metadata ${field} invalid 'description' field at index ${index}`);
}
validateDescription({protocol, field, index, description});

if (!mustBeNonEmptyString(integrationUrl)) {
throw new Error(`protocol ${protocol}: metadata ${field} invalid 'integrationUrl' field at index ${index}`);
Expand Down

0 comments on commit 9acb8c7

Please sign in to comment.