Skip to content

Commit

Permalink
chore: validate chains and warp routes, change jobs to run on main (#457
Browse files Browse the repository at this point in the history
)

### Description

<!--
Summary of change.
Example: Add sepolia chain
-->

Fixes #439 and #209 

- Change `combine` and `optimize-svg` jobs to only run when commited to
`main`
- Add script to validate chains and warp routes
- Add `step` in `ci.ym`l test job to run these
- For chains it will check for missing `deployer` field and if its
missing logo file
- For warp routes it will check for missing config file and if chain
names are ordered correctly
- Updated `chain` test to check if `isTestnet` is set properly
- Update `warp-routes` test to check for `logoURI` field

### Backward compatibility

<!--
Are these changes backward compatible? Note that additions are backwards
compatible.

Yes/No
-->

Yes

### Testing

Manual
  • Loading branch information
Xaroz authored and ltyu committed Jan 7, 2025
1 parent 3441d42 commit 79c7309
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 81 deletions.
6 changes: 6 additions & 0 deletions .changeset/afraid-lamps-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/registry': patch
---

Warp Routes: add logoURI for tokens that did not have it and rename chain names that were not sorted alphabetically
Chains: Add missing deployer field
25 changes: 18 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
# 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
yarn install
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -97,6 +97,17 @@ jobs:
- name: test
run: yarn run test:unit

- name: validate-file-path
run: |
node ./scripts/validate-file-path.js
- name: validate-svg
run: |
node ./scripts/validate-svg.js
- name: validate-file-data
run: |
node ./scripts/validate-file-data.js
# health:
# runs-on: ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/combine.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: combine

on:
pull_request:
push:
branches:
- main
# Allows you to run this workflow manually
workflow_dispatch:

Expand Down Expand Up @@ -56,7 +58,7 @@ jobs:
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
git add .
git commit -m "Update chain metadata and address files"
git commit -m "Update chain metadata and address files [skip-ci]"
git push
else
echo "No changes to commit."
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/optimize-svg.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: optimize-svg

on:
pull_request:
push:
branches:
- main
# Allows you to run this workflow manually
workflow_dispatch:

Expand Down Expand Up @@ -50,7 +52,7 @@ jobs:
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
git add .
git commit -m "Optimize SVG files"
git commit -m "Optimize SVG files [skip-ci]"
git push
else
echo "No changes to commit."
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/validate.yaml

This file was deleted.

5 changes: 4 additions & 1 deletion chains/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3422,7 +3422,7 @@ metertestnet:
name: Meter Testnet Explorer
url: https://scan.meter.io/
chainId: 83
deployers:
deployer:
name: JaunePomme
url: https://github.com/JaunePomme
displayName: Meter testnet
Expand Down Expand Up @@ -5511,6 +5511,9 @@ u2utestnet:
name: u2uscan
url: https://testnet.u2uscan.xyz
chainId: 2484
deployer:
name: junayedmh
url: https://github.com/JunayedMh
displayName: U2U Testnet
domainId: 2484
isTestnet: true
Expand Down
2 changes: 1 addition & 1 deletion chains/metertestnet/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ blockExplorers:
name: Meter Testnet Explorer
url: https://scan.meter.io/
chainId: 83
deployers:
deployer:
name: JaunePomme
url: https://github.com/JaunePomme
displayName: Meter testnet
Expand Down
3 changes: 3 additions & 0 deletions chains/u2utestnet/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ blockExplorers:
name: u2uscan
url: https://testnet.u2uscan.xyz
chainId: 2484
deployer:
name: junayedmh
url: https://github.com/JunayedMh
displayName: U2U Testnet
domainId: 2484
isTestnet: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tokens:
- token: ethereum|polygon|0x93b637AEA6a0dF51E8E24E49C62da34f616491c5
- token: ethereum|prom|0xd9c95e2ad330E11D7Dfa58f18504049f625E955e
decimals: 6
logoURI: /deployments/warp_routes/USDC/logo.svg
name: USD Coin
standard: EvmHypCollateral
symbol: USDC
Expand Down
2 changes: 2 additions & 0 deletions deployments/warp_routes/USDC/bsc-polygon-prom-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tokens:
- token: ethereum|polygon|0xFDf46770Da4F907c09aEd92299552DC9c7996d99
- token: ethereum|prom|0x424712Bec7c94a0F804c50F77B641A24F33A138e
decimals: 18
logoURI: /deployments/warp_routes/USDC/logo.svg
name: USD Coin
standard: EvmHypCollateral
symbol: USDC
Expand All @@ -16,6 +17,7 @@ tokens:
- token: ethereum|bsc|0x647eeD57dFDd335f9B6f2a9DbDFe09f166b1AdaC
- token: ethereum|prom|0x424712Bec7c94a0F804c50F77B641A24F33A138e
decimals: 18
logoURI: /deployments/warp_routes/USDC/logo.svg
name: USD Coin
standard: EvmHypSynthetic
symbol: USDC
Expand Down
2 changes: 2 additions & 0 deletions deployments/warp_routes/USDT/bsc-polygon-prom-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tokens:
- token: ethereum|polygon|0xd9765D5fE176493808202e63E6B73b523D6A1C3A
- token: ethereum|prom|0xDf6C58ec668daB037373BC49215722c2b0664484
decimals: 18
logoURI: /deployments/warp_routes/USDT/logo.svg
name: Tether USD
standard: EvmHypCollateral
symbol: USDT
Expand All @@ -16,6 +17,7 @@ tokens:
- token: ethereum|bsc|0x74e19D0c1828be422dDCd367a6ADa8CA7003d1a9
- token: ethereum|prom|0xDf6C58ec668daB037373BC49215722c2b0664484
decimals: 18
logoURI: /deployments/warp_routes/USDT/logo.svg
name: Tether USD
standard: EvmHypSynthetic
symbol: USDT
Expand Down
5 changes: 5 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import { parse as yamlParse } from 'yaml';

function findFiles(directory, fileTypes = [], isRecursive = true) {
const files = fs.readdirSync(directory);
Expand Down Expand Up @@ -32,3 +33,7 @@ export function getFilePaths(directories = [], fileTypes = [], isRecursive = tru
})
.flatMap((directory) => findFiles(directory, fileTypes, isRecursive));
}

export function readYaml(filePath) {
return yamlParse(fs.readFileSync(filePath, 'utf-8'));
}
131 changes: 131 additions & 0 deletions scripts/validate-file-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import fs from 'fs';
import path from 'path';
import { readYaml } from './utils.js';

const chainsDir = './chains';
const warpRoutesDir = './deployments/warp_routes';

// chains errors
const missingDeployerField = [];
const noLogoFileError = [];

// warp routes errors
const noConfigFileError = [];
const unorderedChainNamesError = [];

function validateChains() {
if (!fs.existsSync(chainsDir)) {
console.error(`Directory does not exist: ${chainsDir}`);
return;
}

const entries = fs.readdirSync(chainsDir, { withFileTypes: true });

entries.forEach((entry) => {
if (!entry.isDirectory()) return;

const entryPath = path.join(chainsDir, entry.name);
const addressesPath = path.join(entryPath, 'addresses.yaml');
const metadataPath = path.join(entryPath, 'metadata.yaml');

// check if logo file exists
const logoFile = fs.readdirSync(entryPath).find((file) => file.includes('logo.svg'));
if (!logoFile) noLogoFileError.push(entryPath);

if (!fs.existsSync(metadataPath)) return;

// if addresses.yaml exists, check if deployer field is missing in metadata.yaml
const metadata = readYaml(metadataPath);
if (fs.existsSync(addressesPath)) {
if (!Object.keys(metadata).includes('deployer')) missingDeployerField.push(metadataPath);
}
});
}

// This regex will make sure that we can split the filename when it contains the words
// addresses or config that way we can grab all the chain names and exclude these words
const filenameRegex = /^([\w-]+)-(addresses|config)\.yaml$/;

// check if chain names in warp routes are ordered alphabetically
function validateChainNameOrder(entryPath) {
const yamlFiles = fs.readdirSync(entryPath).filter((file) => file.includes('.yaml'));

yamlFiles.forEach((filename) => {
const match = filename.match(filenameRegex);
const filePath = path.join(entryPath, filename);

if (!match) return;

const chains = match[1];
const sortedChains = [...chains.split('-')].sort().join('-');

if (chains !== sortedChains) unorderedChainNamesError.push(filePath);
});
}

function validateConfigFiles(entryPath) {
//Search for config files
const configFiles = fs.readdirSync(entryPath).filter((file) => file.includes('-config.yaml'));

if (configFiles.length === 0) {
noConfigFileError.push(entryPath);
return;
}
}

function validateWarpRoutes() {
if (!fs.existsSync(warpRoutesDir)) {
console.error(`Directory does not exist: ${warpRoutesDir}`);
return;
}

const entries = fs.readdirSync(warpRoutesDir, { withFileTypes: true });

entries.forEach((entry) => {
if (!entry.isDirectory()) return;

const entryPath = path.join(warpRoutesDir, entry.name);

validateConfigFiles(entryPath);
validateChainNameOrder(entryPath);
});
}

function validateErrors() {
const errorCount =
missingDeployerField.length +
noConfigFileError.length +
noLogoFileError.length +
unorderedChainNamesError.length;

if (errorCount === 0) return;

console.error(`Number of errors found: ${errorCount}`);

if (missingDeployerField.length > 0)
console.error(
'Error: Chain contains addresses.yaml but missing deployer field in metadata.yaml for the following paths:',
missingDeployerField,
);

if (noLogoFileError.length > 0) console.error('Error: logo file missing at:', noLogoFileError);

if (noConfigFileError.length > 0)
console.error('Error: no config file at paths:', noConfigFileError);

if (unorderedChainNamesError.length > 0)
console.error(
'Error: Chain names not ordered alphabetically at paths:',
unorderedChainNamesError,
);

process.exit(1);
}

function main() {
validateChains();
validateWarpRoutes();
validateErrors();
}

main();
Loading

0 comments on commit 79c7309

Please sign in to comment.