Skip to content

Commit

Permalink
feat: add script to validate chain-support.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dcroote committed Sep 22, 2024
1 parent 5b2ebb7 commit 275e6b8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/validate-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Validate deployment config
run: pnpm validate-deployment-config

- name: Validate chain support
run: pnpm validate-chain-support

- name: Validate deployments
run: pnpm validate-deployments
if: always()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"test:coverage": "hardhat coverage",
"test:extended": "EXTENDED_TEST=TRUE hardhat test --parallel",
"test:gas": "REPORT_GAS=TRUE hardhat test",
"validate-chain-support": "ts-node scripts/validate-chain-support.ts",
"validate-deployment-config": "hardhat run scripts/validate-deployment-config.ts",
"validate-deployments": "hardhat run scripts/validate-deployments.ts",
"verify-deployments": "hardhat run scripts/verify-deployments.ts",
Expand Down
51 changes: 51 additions & 0 deletions scripts/validate-chain-support.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import chainSupport from '../data/chain-support.json';

async function checkSortedList(list: string[]): Promise<void> {
const sortedList = [...list].sort();
if (JSON.stringify(list) !== JSON.stringify(sortedList)) {
throw new Error(`List unsorted`);
}
}

async function checkDuplicates(list: string[]): Promise<void> {
const hasDuplicates = new Set(list).size !== list.length;
if (hasDuplicates) {
throw new Error(`Duplicates found`);
}
}

async function main(fieldLists: Record<string, string[]>): Promise<void> {
const errors: Error[] = [];
for (const field in fieldLists) {
const list = fieldLists[field];
if (!list || list.length === 0) {
errors.push(new Error(`Empty list found for field: ${field}`));
continue;
}

const validations = [checkDuplicates, checkSortedList];
await Promise.all(
validations.map(async (validation) => {
try {
await validation(list);
} catch (error) {
errors.push(new Error(String((error as Error).message) + ` in field: ${field}`));
}
})
);
}
if (errors.length > 0) {
// eslint-disable-next-line no-console
console.error('Validation failed with the following error(s):\n' + errors.join('\n'));
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
}

/* eslint-disable */
main(chainSupport)
.then(() => process.exit(0))
.catch((error) => {
console.log(error);
process.exit(1);
});

0 comments on commit 275e6b8

Please sign in to comment.