-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_.test.js
More file actions
40 lines (34 loc) · 1.09 KB
/
_.test.js
File metadata and controls
40 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const path = require("path");
const fs = require("fs");
const { z } = require("zod");
const { isAddress } = require("ethereum-address");
const files = ["bera-bartio.json", "bera-mainnet.json"];
const directory = path.join(__dirname, "src/tokens");
const TokenInfo = z.array(
z
.object({
name: z.string(),
symbol: z.string(),
address: z.string().refine((arg) => isAddress(arg)),
logoURI: z.union([z.string().url().min(1), z.string().base64().min(1)]),
decimals: z
.number()
.int()
.max(2 ** 8),
chainId: z.number().int(),
})
.strict()
);
const runCheck = () => {
for (const file of files) {
const concatenatedPath = path.join(directory, file);
const fileContent = fs.readFileSync(concatenatedPath);
const parsedContent = JSON.parse(fileContent.toString());
const { error } = TokenInfo.safeParse(parsedContent);
if (error) {
console.error(error);
process.exit(1);
}
}
};
runCheck();