Skip to content

Commit

Permalink
Create chain data test
Browse files Browse the repository at this point in the history
Define CI tasks
  • Loading branch information
jmrossy committed Apr 7, 2024
1 parent 3528af4 commit 96c56f2
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: ci

on:
# Triggers the workflow on push or pull request events
push:
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
**/node_modules
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
- name: yarn-install
# Check out the lockfile from main, reinstall, and then
# verify the lockfile matches what was committed.
run: |
yarn install
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
build:
runs-on: ubuntu-latest
needs: [install]
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
**/node_modules
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
- name: build
run: yarn run build

prettier:
runs-on: ubuntu-latest
needs: [install]
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
**/node_modules
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
- name: prettier
run: |
yarn run prettier
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
exit 1
fi
test:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
**/node_modules
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
- name: test
run: yarn run test
3 changes: 3 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"import": ["tsx"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"tsx": "^4.7.1",
"typescript": "5.3.3",
"yaml": "^2.3.1",
"zod": "^3.21.2",
"zod-to-json-schema": "^3.22.5"
},
"type": "module",
Expand Down Expand Up @@ -44,7 +45,7 @@
"clean": "rm -rf ./dist ./tmp",
"build": "tsx ./scripts/build.ts && tsc",
"prettier": "prettier --write ./chains ./deployments",
"test": "echo 'TODO'"
"test": "mocha --config .mocharc.json './test/**/*.test.ts' --exit"
},
"packageManager": "[email protected]"
}
24 changes: 24 additions & 0 deletions test/chains.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ChainMetadataSchema } from '@hyperlane-xyz/sdk';
import { z } from 'zod';
import { readAllChainYamlFiles } from './utils';

describe('Chain metadata', () => {
it('All chains have valid metadata', () => {
const result = readAllChainYamlFiles('metadata.yaml');
for (const [chain, metadata] of Object.entries(result)) {
console.log('Validating metadata for', chain);
ChainMetadataSchema.parse(metadata);
}
});
});

describe('Chain addresses', () => {
const AddressSchema = z.record(z.string());
it('All chain addresses are valid', () => {
const result = readAllChainYamlFiles('addresses.yaml');
for (const [chain, addresses] of Object.entries(result)) {
console.log('Validating addresses for', chain);
AddressSchema.parse(addresses);
}
});
});
17 changes: 17 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { ChainMap } from '@hyperlane-xyz/sdk';
import fs from 'fs';
import { parse } from 'yaml';

export function readAllChainYamlFiles(pattern: string) {
const result: ChainMap<any> = {};
for (const chainName of fs.readdirSync('./chains')) {
const stat = fs.statSync(`./chains/${chainName}`);
if (!stat.isDirectory()) continue;
const chainFiles = fs.readdirSync(`./chains/${chainName}`);
for (const chainFile of chainFiles) {
if (!chainFile.includes(pattern)) continue;
result[chainName] = parse(fs.readFileSync(`./chains/${chainName}/${chainFile}`, 'utf8'));
}
}
return result;
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ __metadata:
tsx: "npm:^4.7.1"
typescript: "npm:5.3.3"
yaml: "npm:^2.3.1"
zod: "npm:^3.21.2"
zod-to-json-schema: "npm:^3.22.5"
languageName: unknown
linkType: soft
Expand Down

0 comments on commit 96c56f2

Please sign in to comment.