-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add code to validate schema of the tokenlist * Update gh actions to use reusable workflow * Add error code on exit * Move schema validation to pretest script * Keep data when throwing errors * Use hash for js-checks workflow
- Loading branch information
Showing
5 changed files
with
60 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Ajv from "ajv"; | ||
import addFormats from "ajv-formats"; | ||
import fs from "node:fs"; | ||
import { exit } from "node:process"; | ||
|
||
// eslint fails to parse "with { type: "json" }" | ||
// See https://github.com/eslint/eslint/discussions/15305 | ||
const tokenList = JSON.parse(fs.readFileSync("./src/hemi.tokenlist.json")); | ||
|
||
const schemaUrl = | ||
"https://raw.githubusercontent.com/Uniswap/token-lists/main/src/tokenlist.schema.json"; | ||
|
||
// See https://github.com/uniswap/token-lists?tab=readme-ov-file#validating-token-lists | ||
async function validate() { | ||
const ajv = new Ajv({ allErrors: true, verbose: true }); | ||
addFormats(ajv); | ||
const schema = await fetch(schemaUrl).then((r) => r.json()); | ||
const validator = ajv.compile(schema); | ||
const valid = validator(tokenList); | ||
if (valid) { | ||
return; | ||
} | ||
if (validator.errors) { | ||
throw validator.errors; | ||
} | ||
} | ||
|
||
validate() | ||
.then(() => console.info("Schema is valid")) | ||
.catch(function (err) { | ||
console.error(err); | ||
exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters