Skip to content

Commit

Permalink
fix(api): update validation for data feeds config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 30, 2022
1 parent 4a167f8 commit fbd920b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ export function readDataFeeds (): Array<FeedInfo> {
function validateDataFeeds (
dataFeeds: Array<Omit<FeedInfoConfig, 'abi' | 'routerAbi'>>
) {
const fields = [
const expectedFields = [
'feedFullName',
'id',
'address',
'contractId',
'routerAddress',
'network',
'networkName',
'chain',
'name',
'label',
'pollingPeriod',
'color',
'blockExplorer',
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit fbd920b

Please sign in to comment.