From fbd920b65fad8d038f52d2a648a8472bfc30d020 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Fri, 18 Mar 2022 13:39:26 +0100 Subject: [PATCH] fix(api): update validation for data feeds config --- packages/api/src/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 8805f38a..840e5d59 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -87,11 +87,17 @@ export function readDataFeeds (): Array { function validateDataFeeds ( dataFeeds: Array> ) { - const fields = [ + const expectedFields = [ 'feedFullName', + 'id', 'address', + 'contractId', + 'routerAddress', 'network', + 'networkName', + 'chain', 'name', + 'label', 'pollingPeriod', 'color', 'blockExplorer', @@ -101,7 +107,7 @@ function validateDataFeeds ( ] dataFeeds.forEach((feedInfoConfig, index) => { - fields.forEach(field => { + expectedFields.forEach((field) => { // Validate nested keys in a field field.split('.').reduce((acc, val) => { // Throw error if the key is not found or has a falsy value @@ -110,6 +116,12 @@ function validateDataFeeds ( `Missing field ${field} in index ${index} in data feed config file` ) } else { + // Throw error if not validated new fields are added in the config file + if (Object.keys(feedInfoConfig).length !== expectedFields.length) { + throw new Error( + `There are more fields in the feed config than expected` + ) + } return acc[val] } }, feedInfoConfig)