2022-08-28 10:25:46 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const Ajv = require("ajv")
|
|
|
|
const ajv = new Ajv()
|
|
|
|
const schema = require('./schema/chainSchema.json')
|
|
|
|
const chainFiles = fs.readdirSync('../_data/chains/');
|
|
|
|
|
|
|
|
const filesWithErrors = []
|
|
|
|
for(const chainFile of chainFiles){
|
|
|
|
const fileLocation = `../_data/chains/${chainFile}`
|
|
|
|
const fileData = fs.readFileSync(fileLocation,'utf8')
|
|
|
|
const fileDataJson = JSON.parse(fileData)
|
|
|
|
const chainIdFromFileName = chainFile.match(/eip155-(\d+)\.json/)[1]
|
2022-10-01 12:10:05 +00:00
|
|
|
const parsedChainId = parseInt(chainIdFromFileName, 10);
|
|
|
|
if(chainIdFromFileName != parsedChainId.toString()){
|
|
|
|
throw new Error(`File name does not match parsed ChainID ${parsedChainId} in ${chainFile}`)
|
|
|
|
}
|
|
|
|
if(parsedChainId !== fileDataJson.chainId){
|
2022-08-28 10:25:46 +00:00
|
|
|
throw new Error(`File Name does not match with ChainID in ${chainFile}`)
|
|
|
|
}
|
|
|
|
const valid = ajv.validate(schema, fileDataJson)
|
|
|
|
if(!valid) {
|
|
|
|
console.error(ajv.errors)
|
|
|
|
filesWithErrors.push(chainFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(filesWithErrors.length > 0){
|
|
|
|
throw new Error(`Invalid JSON Schema in ${filesWithErrors.length} files at ${filesWithErrors.join(",")}`)
|
|
|
|
}
|